Skip to content

Commit c21493a

Browse files
authored
add -show-url option for ui command (#11213)
1 parent 25b2e54 commit c21493a

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

.changelog/11213.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
cli: Add `-show-url` option for the `nomad ui` command.
3+
```

command/ui.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ UI Options
3535
3636
-authenticate: Exchange your Nomad ACL token for a one-time token in the
3737
web UI, if ACLs are enabled.
38+
39+
-show-url: Show the Nomad UI URL instead of opening with the default browser.
3840
`
3941

4042
return strings.TrimSpace(helpText)
@@ -82,10 +84,12 @@ func (c *UiCommand) Name() string { return "ui" }
8284

8385
func (c *UiCommand) Run(args []string) int {
8486
var authenticate bool
87+
var showUrl bool
8588

8689
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
8790
flags.Usage = func() { c.Ui.Output(c.Help()) }
8891
flags.BoolVar(&authenticate, "authenticate", false, "")
92+
flags.BoolVar(&showUrl, "show-url", false, "")
8993

9094
if err := flags.Parse(args); err != nil {
9195
return 1
@@ -178,17 +182,24 @@ func (c *UiCommand) Run(args []string) int {
178182
}
179183
}
180184

185+
var output string
181186
if authenticate && ottSecret != "" {
182-
c.Ui.Output(fmt.Sprintf("Opening URL %q with one-time token", url.String()))
187+
output = fmt.Sprintf("Opening URL %q with one-time token", url.String())
183188
url.RawQuery = fmt.Sprintf("ott=%s", ottSecret)
184189
} else {
185-
c.Ui.Output(fmt.Sprintf("Opening URL %q", url.String()))
190+
output = fmt.Sprintf("Opening URL %q", url.String())
191+
}
192+
193+
if showUrl {
194+
c.Ui.Output(fmt.Sprintf("URL for web UI: %s", url.String()))
195+
return 0
186196
}
197+
198+
c.Ui.Output(output)
187199
if err := open.Start(url.String()); err != nil {
188200
c.Ui.Error(fmt.Sprintf("Error opening URL: %s", err))
189201
return 1
190202
}
191-
192203
return 0
193204
}
194205

website/content/docs/commands/ui.mdx

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ storage for authentication.
3636
- `-authenticate`: Exchange your Nomad ACL token for a one-time token in the
3737
web UI.
3838

39+
- `-show-url`: Show the Nomad UI URL instead of opening with the default browser.
40+
3941
## Examples
4042

4143
Open the UI homepage:
@@ -65,3 +67,10 @@ Open the UI and authenticate using your ACL token:
6567
$ NOMAD_ACL_TOKEN=e9674b26-763b-4637-a28f-0df95c53cdda nomad ui -authenticate
6668
Opening URL "http://127.0.0.1:4646" with token
6769
```
70+
71+
Show the UI URL without opening the browser:
72+
73+
```shell-session
74+
$ nomad ui -show-url
75+
URL for web UI: http://127.0.0.1:4646
76+
```

0 commit comments

Comments
 (0)