Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add -show-url option for ui command #11213

Merged
merged 3 commits into from Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11213.txt
@@ -0,0 +1,3 @@
```release-note:improvement
cli: Add `-show-url` option for the `nomad ui` command.
```
17 changes: 14 additions & 3 deletions command/ui.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()))
yaroot marked this conversation as resolved.
Show resolved Hide resolved
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
}

Expand Down
9 changes: 9 additions & 0 deletions website/content/docs/commands/ui.mdx
Expand Up @@ -36,6 +36,8 @@ 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

Open the UI homepage:
Expand Down Expand Up @@ -65,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
```