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

[cli] UI URL hints for common CLI commands #24454

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion command/alloc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Alloc Status Options:
-verbose
Show full information.

-ui
Open the allocation status page in the browser.

-json
Output the allocation in its JSON format.

Expand All @@ -70,6 +73,7 @@ func (c *AllocStatusCommand) AutocompleteFlags() complete.Flags {
"-verbose": complete.PredictNothing,
"-json": complete.PredictNothing,
"-t": complete.PredictAnything,
"-ui": complete.PredictNothing,
})
}

Expand All @@ -91,7 +95,7 @@ func (c *AllocStatusCommand) AutocompleteArgs() complete.Predictor {
func (c *AllocStatusCommand) Name() string { return "alloc status" }

func (c *AllocStatusCommand) Run(args []string) int {
var short, displayStats, verbose, json bool
var short, displayStats, verbose, json, openURL bool
var tmpl string

flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
Expand All @@ -101,6 +105,7 @@ func (c *AllocStatusCommand) Run(args []string) int {
flags.BoolVar(&displayStats, "stats", false, "")
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")
flags.BoolVar(&openURL, "ui", false, "")

if err := flags.Parse(args); err != nil {
return 1
Expand Down Expand Up @@ -237,6 +242,16 @@ func (c *AllocStatusCommand) Run(args []string) int {
c.Ui.Output(formatAllocMetrics(alloc.Metrics, true, " "))
}

hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "alloc status",
PathParams: map[string]string{
"allocID": alloc.ID,
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
}
return 0
}

Expand Down
32 changes: 30 additions & 2 deletions command/deployment_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Status Options:
How long to wait before polling an update, used in conjunction with monitor
mode. Defaults to 2s.

-ui
Open the deployment in the browser.

-t
Format and display deployment using a Go template.
`
Expand All @@ -72,6 +75,7 @@ func (c *DeploymentStatusCommand) AutocompleteFlags() complete.Flags {
"-json": complete.PredictNothing,
"-monitor": complete.PredictNothing,
"-t": complete.PredictAnything,
"-ui": complete.PredictNothing,
})
}

Expand All @@ -93,7 +97,7 @@ func (c *DeploymentStatusCommand) AutocompleteArgs() complete.Predictor {
func (c *DeploymentStatusCommand) Name() string { return "deployment status" }

func (c *DeploymentStatusCommand) Run(args []string) int {
var json, verbose, monitor bool
var json, verbose, monitor, openURL bool
var wait time.Duration
var tmpl string

Expand All @@ -104,7 +108,7 @@ func (c *DeploymentStatusCommand) Run(args []string) int {
flags.BoolVar(&monitor, "monitor", false, "")
flags.StringVar(&tmpl, "t", "", "")
flags.DurationVar(&wait, "wait", 2*time.Second, "")

flags.BoolVar(&openURL, "ui", false, "")
if err := flags.Parse(args); err != nil {
return 1
}
Expand Down Expand Up @@ -183,9 +187,33 @@ func (c *DeploymentStatusCommand) Run(args []string) int {
formatTime(time.Now()), limit(deploy.ID, length)))
c.monitor(client, deploy.ID, meta.LastIndex, wait, verbose)

hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "deployment status",
PathParams: map[string]string{
"jobID": deploy.JobID,
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
// Because this is before monitor, newline so we don't scrunch
c.Ui.Output("\n")
}

return 0
}
c.Ui.Output(c.Colorize().Color(formatDeployment(client, deploy, length)))

hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "deployment status",
PathParams: map[string]string{
"jobID": deploy.JobID,
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
}
return 0
}

Expand Down
15 changes: 14 additions & 1 deletion command/eval_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Eval List Options:

-t
Format and display evaluation using a Go template.

-ui
Open the evaluation in the browser.
`

return strings.TrimSpace(helpText)
Expand All @@ -72,6 +75,7 @@ func (c *EvalListCommand) AutocompleteFlags() complete.Flags {
"-status": complete.PredictAnything,
"-per-page": complete.PredictAnything,
"-page-token": complete.PredictAnything,
"-ui": complete.PredictNothing,
})
}

Expand All @@ -93,7 +97,7 @@ func (c *EvalListCommand) AutocompleteArgs() complete.Predictor {
func (c *EvalListCommand) Name() string { return "eval list" }

func (c *EvalListCommand) Run(args []string) int {
var monitor, verbose, json bool
var monitor, verbose, json, openURL bool
var perPage int
var tmpl, pageToken, filter, filterJobID, filterStatus string

Expand All @@ -103,6 +107,7 @@ func (c *EvalListCommand) Run(args []string) int {
flags.BoolVar(&verbose, "verbose", false, "")
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")
flags.BoolVar(&openURL, "ui", false, "")
flags.IntVar(&perPage, "per-page", 0, "")
flags.StringVar(&pageToken, "page-token", "", "")
flags.StringVar(&filter, "filter", "", "")
Expand Down Expand Up @@ -173,6 +178,14 @@ Results have been paginated. To get the next page run:
%s -page-token %s`, argsWithoutPageToken(os.Args), qm.NextToken))
}

hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "eval list",
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
}

return 0
}

Expand Down
19 changes: 17 additions & 2 deletions command/eval_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Eval Status Options:

-t
Format and display evaluation using a Go template.

-ui
Open the evaluation in the browser.
`

return strings.TrimSpace(helpText)
Expand All @@ -59,6 +62,7 @@ func (c *EvalStatusCommand) AutocompleteFlags() complete.Flags {
"-monitor": complete.PredictNothing,
"-t": complete.PredictAnything,
"-verbose": complete.PredictNothing,
"-ui": complete.PredictNothing,
})
}

Expand All @@ -84,7 +88,7 @@ func (c *EvalStatusCommand) AutocompleteArgs() complete.Predictor {
func (c *EvalStatusCommand) Name() string { return "eval status" }

func (c *EvalStatusCommand) Run(args []string) int {
var monitor, verbose, json bool
var monitor, verbose, json, openURL bool
var tmpl string

flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
Expand All @@ -93,7 +97,7 @@ func (c *EvalStatusCommand) Run(args []string) int {
flags.BoolVar(&verbose, "verbose", false, "")
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")

flags.BoolVar(&openURL, "ui", false, "")
if err := flags.Parse(args); err != nil {
return 1
}
Expand Down Expand Up @@ -247,6 +251,17 @@ func (c *EvalStatusCommand) Run(args []string) int {
}
}

hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "eval status",
PathParams: map[string]string{
"evalID": eval.ID,
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
}

return 0
}

Expand Down
24 changes: 23 additions & 1 deletion command/job_dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package command
import (
"fmt"
"io"
"net/url"
"os"
"strings"

Expand Down Expand Up @@ -68,6 +69,9 @@ Dispatch Options:

-verbose
Display full information.

-ui
Open the dispatched job in the browser.
`
return strings.TrimSpace(helpText)
}
Expand All @@ -83,6 +87,7 @@ func (c *JobDispatchCommand) AutocompleteFlags() complete.Flags {
"-detach": complete.PredictNothing,
"-idempotency-token": complete.PredictAnything,
"-verbose": complete.PredictNothing,
"-ui": complete.PredictNothing,
})
}

Expand Down Expand Up @@ -113,7 +118,7 @@ func (c *JobDispatchCommand) AutocompleteArgs() complete.Predictor {
func (c *JobDispatchCommand) Name() string { return "job dispatch" }

func (c *JobDispatchCommand) Run(args []string) int {
var detach, verbose bool
var detach, verbose, openURL bool
var idempotencyToken string
var meta []string
var idPrefixTemplate string
Expand All @@ -125,6 +130,7 @@ func (c *JobDispatchCommand) Run(args []string) int {
flags.StringVar(&idempotencyToken, "idempotency-token", "", "")
flags.Var((*flaghelper.StringFlag)(&meta), "meta", "")
flags.StringVar(&idPrefixTemplate, "id-prefix-template", "", "")
flags.BoolVar(&openURL, "ui", false, "")

if err := flags.Parse(args); err != nil {
return 1
Expand Down Expand Up @@ -220,5 +226,21 @@ func (c *JobDispatchCommand) Run(args []string) int {

c.Ui.Output("")
mon := newMonitor(c.Ui, client, length)

// for hint purposes, need the dispatchedJobID to be escaped ("/" becomes "%2F")
dispatchID := url.PathEscape(resp.DispatchedJobID)

hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "job dispatch",
PathParams: map[string]string{
"dispatchID": dispatchID,
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
// Because this is before monitor, newline so we don't scrunch
c.Ui.Output("\n")
}
return mon.monitor(resp.EvalID)
}
43 changes: 42 additions & 1 deletion command/job_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ Run Options:
Output the JSON that would be submitted to the HTTP API without submitting
the job.

-ui
Open the job run page in the browser.

-policy-override
Sets the flag to force override any soft mandatory Sentinel policies.

Expand Down Expand Up @@ -176,6 +179,7 @@ func (c *JobRunCommand) AutocompleteFlags() complete.Flags {
"-var": complete.PredictAnything,
"-var-file": complete.PredictFiles("*.var"),
"-eval-priority": complete.PredictNothing,
"-ui": complete.PredictNothing,
})
}

Expand All @@ -190,7 +194,7 @@ func (c *JobRunCommand) AutocompleteArgs() complete.Predictor {
func (c *JobRunCommand) Name() string { return "job run" }

func (c *JobRunCommand) Run(args []string) int {
var detach, verbose, output, override, preserveCounts bool
var detach, verbose, output, override, preserveCounts, openURL bool
var checkIndexStr, consulToken, consulNamespace, vaultToken, vaultNamespace string
var evalPriority int

Expand All @@ -211,6 +215,7 @@ func (c *JobRunCommand) Run(args []string) int {
flagSet.Var(&c.JobGetter.Vars, "var", "")
flagSet.Var(&c.JobGetter.VarFiles, "var-file", "")
flagSet.IntVar(&evalPriority, "eval-priority", 0, "")
flagSet.BoolVar(&openURL, "ui", false, "")

if err := flagSet.Parse(args); err != nil {
return 1
Expand Down Expand Up @@ -305,6 +310,18 @@ func (c *JobRunCommand) Run(args []string) int {
}

c.Ui.Output(string(buf))

hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "job run",
PathParams: map[string]string{
"jobID": *job.ID,
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
}

return 0
}

Expand Down Expand Up @@ -372,10 +389,34 @@ func (c *JobRunCommand) Run(args []string) int {
c.Ui.Output("Evaluation ID: " + evalID)
}

hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "job run",
PathParams: map[string]string{
"jobID": *job.ID,
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
}

return 0
}

// Detach was not specified, so start monitoring
hint, _ := c.Meta.showUIPath(UIHintContext{
Command: "job run",
PathParams: map[string]string{
"jobID": *job.ID,
},
OpenURL: openURL,
})
if hint != "" {
c.Ui.Output(hint)
// Because this is before monitor, newline so we don't scrunch
c.Ui.Output("\n")
}

mon := newMonitor(c.Ui, client, length)
return mon.monitor(evalID)

Expand Down
Loading
Loading