From a1750f375d13df7ce353cfdb66c822c62ec29a8e Mon Sep 17 00:00:00 2001 From: Yan Su Date: Tue, 21 Sep 2021 19:33:43 +0900 Subject: [PATCH 1/3] add `-show-url` option for `ui` command --- command/ui.go | 17 ++++++++++++++--- website/content/docs/commands/ui.mdx | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/command/ui.go b/command/ui.go index d4d275dbb52..c74f9b0fbf0 100644 --- a/command/ui.go +++ b/command/ui.go @@ -35,6 +35,8 @@ UI Options -authenticate: Exchange your Nomad ACL token for a one-time token in the web UI, if ACLs are enabled. + + -show-url: Show the Nomad UI URL instead of opening with the default browser. ` return strings.TrimSpace(helpText) @@ -82,10 +84,12 @@ func (c *UiCommand) Name() string { return "ui" } func (c *UiCommand) Run(args []string) int { var authenticate bool + var showUrl bool flags := c.Meta.FlagSet(c.Name(), FlagSetClient) flags.Usage = func() { c.Ui.Output(c.Help()) } flags.BoolVar(&authenticate, "authenticate", false, "") + flags.BoolVar(&showUrl, "show-url", false, "") if err := flags.Parse(args); err != nil { return 1 @@ -178,17 +182,24 @@ func (c *UiCommand) Run(args []string) int { } } + var output string if authenticate && ottSecret != "" { - c.Ui.Output(fmt.Sprintf("Opening URL %q with one-time token", url.String())) + output = fmt.Sprintf("Opening URL %q with one-time token", url.String()) url.RawQuery = fmt.Sprintf("ott=%s", ottSecret) } else { - c.Ui.Output(fmt.Sprintf("Opening URL %q", url.String())) + output = fmt.Sprintf("Opening URL %q", url.String()) + } + + if showUrl { + c.Ui.Output(fmt.Sprintf("URL for web UI: %s", url.String())) + return 0 } + + c.Ui.Output(output) if err := open.Start(url.String()); err != nil { c.Ui.Error(fmt.Sprintf("Error opening URL: %s", err)) return 1 } - return 0 } diff --git a/website/content/docs/commands/ui.mdx b/website/content/docs/commands/ui.mdx index 21bc2decc62..f4f5a355114 100644 --- a/website/content/docs/commands/ui.mdx +++ b/website/content/docs/commands/ui.mdx @@ -35,6 +35,7 @@ storage for authentication. - `-authenticate`: Exchange your Nomad ACL token for a one-time token in the web UI. +- `-show-url`: Show the Nomad UI URL instead of opening with the default browser. ## Examples From d2bf340db5f39043d6bccdeee43edfc581cde98c Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Tue, 5 Oct 2021 18:24:02 -0400 Subject: [PATCH 2/3] docs: add example for `nomad ui -show-url` --- website/content/docs/commands/ui.mdx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/website/content/docs/commands/ui.mdx b/website/content/docs/commands/ui.mdx index f4f5a355114..1ad5370ed22 100644 --- a/website/content/docs/commands/ui.mdx +++ b/website/content/docs/commands/ui.mdx @@ -35,6 +35,7 @@ storage for authentication. - `-authenticate`: Exchange your Nomad ACL token for a one-time token in the web UI. + - `-show-url`: Show the Nomad UI URL instead of opening with the default browser. ## Examples @@ -66,3 +67,10 @@ Open the UI and authenticate using your ACL token: $ NOMAD_ACL_TOKEN=e9674b26-763b-4637-a28f-0df95c53cdda nomad ui -authenticate Opening URL "http://127.0.0.1:4646" with token ``` + +Show the UI URL without opening the browser: + +```shell-session +$ nomad ui -show-url +URL for web UI: http://127.0.0.1:4646 +``` From c220c83b102cbf73373d6137244914c7db89806e Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Tue, 5 Oct 2021 18:25:26 -0400 Subject: [PATCH 3/3] changelog: add entry for #11213 --- .changelog/11213.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/11213.txt diff --git a/.changelog/11213.txt b/.changelog/11213.txt new file mode 100644 index 00000000000..3718e8bf5cb --- /dev/null +++ b/.changelog/11213.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: Add `-show-url` option for the `nomad ui` command. +```