command: improve help text when invalid arguments are given

This commit is contained in:
Nick Ethier 2018-04-18 12:02:11 -04:00
parent 43c964ad63
commit 182e3bec1b
No known key found for this signature in database
GPG Key ID: 07C1A3ECED90D24A
81 changed files with 383 additions and 147 deletions

View File

@ -31,6 +31,8 @@ func (f *ACLCommand) Synopsis() string {
return "Interact with ACL policies and tokens"
}
func (f *ACLCommand) Name() string { return "acl" }
func (f *ACLCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -39,8 +39,10 @@ func (c *ACLBootstrapCommand) Synopsis() string {
return "Bootstrap the ACL system for initial token"
}
func (c *ACLBootstrapCommand) Name() string { return "acl bootstrap" }
func (c *ACLBootstrapCommand) Run(args []string) int {
flags := c.Meta.FlagSet("acl bootstrap", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
@ -49,7 +51,8 @@ func (c *ACLBootstrapCommand) Run(args []string) int {
// Check that we got no arguments
args = flags.Args()
if l := len(args); l != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -40,6 +40,8 @@ func (f *ACLPolicyCommand) Synopsis() string {
return "Interact with ACL policies"
}
func (f *ACLPolicyCommand) Name() string { return "acl policy" }
func (f *ACLPolicyCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -47,9 +47,11 @@ func (c *ACLPolicyApplyCommand) Synopsis() string {
return "Create or update an ACL policy"
}
func (c *ACLPolicyApplyCommand) Name() string { return "acl policy apply" }
func (c *ACLPolicyApplyCommand) Run(args []string) int {
var description string
flags := c.Meta.FlagSet("acl policy apply", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.StringVar(&description, "description", "", "")
if err := flags.Parse(args); err != nil {
@ -59,7 +61,8 @@ func (c *ACLPolicyApplyCommand) Run(args []string) int {
// Check that we got two arguments
args = flags.Args()
if l := len(args); l != 2 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes two arguments, <name> and <path>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -37,8 +37,10 @@ func (c *ACLPolicyDeleteCommand) Synopsis() string {
return "Delete an existing ACL policy"
}
func (c *ACLPolicyDeleteCommand) Name() string { return "acl policy delete" }
func (c *ACLPolicyDeleteCommand) Run(args []string) int {
flags := c.Meta.FlagSet("acl policy delete", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
@ -47,7 +49,8 @@ func (c *ACLPolicyDeleteCommand) Run(args []string) int {
// Check that we got exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <name>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -37,8 +37,10 @@ func (c *ACLPolicyInfoCommand) Synopsis() string {
return "Fetch info on an existing ACL policy"
}
func (c *ACLPolicyInfoCommand) Name() string { return "acl policy info" }
func (c *ACLPolicyInfoCommand) Run(args []string) int {
flags := c.Meta.FlagSet("acl policy info", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
@ -47,7 +49,8 @@ func (c *ACLPolicyInfoCommand) Run(args []string) int {
// Check that we got exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <name>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -50,11 +50,13 @@ func (c *ACLPolicyListCommand) Synopsis() string {
return "List ACL policies"
}
func (c *ACLPolicyListCommand) Name() string { return "acl policy list" }
func (c *ACLPolicyListCommand) Run(args []string) int {
var json bool
var tmpl string
flags := c.Meta.FlagSet("acl policy list", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")
@ -66,7 +68,8 @@ func (c *ACLPolicyListCommand) Run(args []string) int {
// Check that we got no arguments
args = flags.Args()
if l := len(args); l != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -40,6 +40,8 @@ func (f *ACLTokenCommand) Synopsis() string {
return "Interact with ACL tokens"
}
func (f *ACLTokenCommand) Name() string { return "acl token" }
func (f *ACLTokenCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -58,11 +58,13 @@ func (c *ACLTokenCreateCommand) Synopsis() string {
return "Create a new ACL token"
}
func (c *ACLTokenCreateCommand) Name() string { return "acl token create" }
func (c *ACLTokenCreateCommand) Run(args []string) int {
var name, tokenType string
var global bool
var policies []string
flags := c.Meta.FlagSet("acl token create", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.StringVar(&name, "name", "", "")
flags.StringVar(&tokenType, "type", "client", "")
@ -78,7 +80,8 @@ func (c *ACLTokenCreateCommand) Run(args []string) int {
// Check that we got no arguments
args = flags.Args()
if l := len(args); l != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -37,8 +37,10 @@ func (c *ACLTokenDeleteCommand) Synopsis() string {
return "Delete an existing ACL token"
}
func (c *ACLTokenDeleteCommand) Name() string { return "acl token delete" }
func (c *ACLTokenDeleteCommand) Run(args []string) int {
flags := c.Meta.FlagSet("acl token delete", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
@ -49,7 +51,8 @@ func (c *ACLTokenDeleteCommand) Run(args []string) int {
// such token was provided.
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <token_accessor_id>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -37,8 +37,10 @@ func (c *ACLTokenInfoCommand) Synopsis() string {
return "Fetch information on an existing ACL token"
}
func (c *ACLTokenInfoCommand) Name() string { return "acl token info" }
func (c *ACLTokenInfoCommand) Run(args []string) int {
flags := c.Meta.FlagSet("acl token info", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
@ -47,7 +49,8 @@ func (c *ACLTokenInfoCommand) Run(args []string) int {
// Check that we have exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <token_accessor_id>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -36,17 +36,20 @@ func (c *ACLTokenSelfCommand) Synopsis() string {
return "Lookup self ACL token"
}
func (c *ACLTokenSelfCommand) Name() string { return "acl token self" }
func (c *ACLTokenSelfCommand) Run(args []string) int {
flags := c.Meta.FlagSet("acl token self", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
}
// Check that we have exactly one argument
// Check that we have no arguments
args = flags.Args()
if l := len(args); l != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -58,11 +58,13 @@ func (c *ACLTokenUpdateCommand) Synopsis() string {
return "Update an existing ACL token"
}
func (*ACLTokenUpdateCommand) Name() string { return "acl token update" }
func (c *ACLTokenUpdateCommand) Run(args []string) int {
var name, tokenType string
var global bool
var policies []string
flags := c.Meta.FlagSet("acl token update", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.StringVar(&name, "name", "", "")
flags.StringVar(&tokenType, "type", "client", "")
@ -78,7 +80,8 @@ func (c *ACLTokenUpdateCommand) Run(args []string) int {
// Check that we got exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <token_accessor_id>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -26,17 +26,20 @@ func (c *AgentInfoCommand) Synopsis() string {
return "Display status information about the local agent"
}
func (c *AgentInfoCommand) Name() string { return "agent-info" }
func (c *AgentInfoCommand) Run(args []string) int {
flags := c.Meta.FlagSet("agent-info", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
}
// Check that we either got no jobs or exactly one.
// Check that we got no arguments
args = flags.Args()
if len(args) > 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -35,6 +35,8 @@ func (f *AllocCommand) Synopsis() string {
return "Interact with allocations"
}
func (f *AllocCommand) Name() string { return "alloc" }
func (f *AllocCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -109,11 +109,13 @@ func (f *AllocFSCommand) AutocompleteArgs() complete.Predictor {
})
}
func (f *AllocFSCommand) Name() string { return "alloc fs" }
func (f *AllocFSCommand) Run(args []string) int {
var verbose, machine, job, stat, tail, follow bool
var numLines, numBytes int64
flags := f.Meta.FlagSet("alloc fs", FlagSetClient)
flags := f.Meta.FlagSet(f.Name(), FlagSetClient)
flags.Usage = func() { f.Ui.Output(f.Help()) }
flags.BoolVar(&verbose, "verbose", false, "")
flags.BoolVar(&machine, "H", false, "")
@ -131,15 +133,17 @@ func (f *AllocFSCommand) Run(args []string) int {
if len(args) < 1 {
if job {
f.Ui.Error("job ID is required")
f.Ui.Error("A job ID is required")
} else {
f.Ui.Error("allocation ID is required")
f.Ui.Error("An allocation ID is required")
}
f.Ui.Error(commandErrorText(f))
return 1
}
if len(args) > 2 {
f.Ui.Error(f.Help())
f.Ui.Error("This command takes one or two arguments, <allocation> [<path>]")
f.Ui.Error(commandErrorText(f))
return 1
}

View File

@ -90,11 +90,13 @@ func (l *AllocLogsCommand) AutocompleteArgs() complete.Predictor {
})
}
func (l *AllocLogsCommand) Name() string { return "alloc logs" }
func (l *AllocLogsCommand) Run(args []string) int {
var verbose, job, tail, stderr, follow bool
var numLines, numBytes int64
flags := l.Meta.FlagSet("alloc logs", FlagSetClient)
flags := l.Meta.FlagSet(l.Name(), FlagSetClient)
flags.Usage = func() { l.Ui.Output(l.Help()) }
flags.BoolVar(&verbose, "verbose", false, "")
flags.BoolVar(&job, "job", false, "")
@ -111,15 +113,16 @@ func (l *AllocLogsCommand) Run(args []string) int {
if numArgs := len(args); numArgs < 1 {
if job {
l.Ui.Error("Job ID required. See help:\n")
l.Ui.Error("A job ID is required")
} else {
l.Ui.Error("Allocation ID required. See help:\n")
l.Ui.Error("An allocation ID is required")
}
l.Ui.Error(l.Help())
l.Ui.Error(commandErrorText(l))
return 1
} else if numArgs > 2 {
l.Ui.Error(l.Help())
l.Ui.Error("This command takes one or two arguments")
l.Ui.Error(commandErrorText(l))
return 1
}

View File

@ -83,11 +83,13 @@ 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 tmpl string
flags := c.Meta.FlagSet("alloc status", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&short, "short", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -128,7 +130,10 @@ func (c *AllocStatusCommand) Run(args []string) int {
}
if len(args) != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one of the following argument conditions:")
c.Ui.Error(" * A single <allocation>")
c.Ui.Error(" * No arguments, with output format specified")
c.Ui.Error(commandErrorText(c))
return 1
}
allocID := args[0]

View File

@ -47,6 +47,8 @@ func (c *AgentCheckCommand) Synopsis() string {
return "Displays health of the local Nomad agent"
}
func (c *AgentCheckCommand) Name() string { return "check" }
func (c *AgentCheckCommand) Run(args []string) int {
var minPeers, minServers int
@ -59,6 +61,13 @@ func (c *AgentCheckCommand) Run(args []string) int {
return 1
}
args = flags.Args()
if len(args) > 0 {
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}
client, err := c.Meta.Client()
if err != nil {
c.Ui.Error(fmt.Sprintf("error initializing client: %s", err))

View File

@ -46,6 +46,11 @@ func (c *DeprecatedCommand) warn() {
c.Ui.Warn("")
}
// NamedCommand is a interface to denote a commmand's name.
type NamedCommand interface {
Name() string
}
// Commands returns the mapping of CLI commands for Nomad. The meta
// parameter lets you set meta options for all commands.
func Commands(metaPtr *Meta, agentUi cli.Ui) map[string]cli.CommandFactory {

View File

@ -44,6 +44,8 @@ func (f *DeploymentCommand) Synopsis() string {
return "Interact with deployments"
}
func (f *DeploymentCommand) Name() string { return "deployment" }
func (f *DeploymentCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -65,10 +65,12 @@ func (c *DeploymentFailCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *DeploymentFailCommand) Name() string { return "deployment fail" }
func (c *DeploymentFailCommand) Run(args []string) int {
var detach, verbose bool
flags := c.Meta.FlagSet("deployment fail", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -80,7 +82,8 @@ func (c *DeploymentFailCommand) Run(args []string) int {
// Check that we got no arguments
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -53,11 +53,13 @@ func (c *DeploymentListCommand) Synopsis() string {
return "List all deployments"
}
func (c *DeploymentListCommand) Name() string { return "deployment list" }
func (c *DeploymentListCommand) Run(args []string) int {
var json, verbose bool
var tmpl string
flags := c.Meta.FlagSet("deployment list", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&verbose, "verbose", false, "")
flags.BoolVar(&json, "json", false, "")
@ -70,7 +72,8 @@ func (c *DeploymentListCommand) Run(args []string) int {
// Check that we got no arguments
args = flags.Args()
if l := len(args); l != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -57,10 +57,12 @@ func (c *DeploymentPauseCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *DeploymentPauseCommand) Name() string { return "deployment pause" }
func (c *DeploymentPauseCommand) Run(args []string) int {
var verbose bool
flags := c.Meta.FlagSet("deployment pause", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&verbose, "verbose", false, "")
@ -68,10 +70,11 @@ func (c *DeploymentPauseCommand) Run(args []string) int {
return 1
}
// Check that we got no arguments
// Check that we got exactly 1 argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <deployment id>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -75,11 +75,13 @@ func (c *DeploymentPromoteCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *DeploymentPromoteCommand) Name() string { return "deployment promote" }
func (c *DeploymentPromoteCommand) Run(args []string) int {
var detach, verbose bool
var groups []string
flags := c.Meta.FlagSet("deployment promote", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -89,10 +91,11 @@ func (c *DeploymentPromoteCommand) Run(args []string) int {
return 1
}
// Check that we got no arguments
// Check that we got exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <deployment id>")
c.Ui.Error(commandErrorText(c))
return 1
}
dID := args[0]

View File

@ -63,10 +63,11 @@ func (c *DeploymentResumeCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *DeploymentResumeCommand) Name() string { return "deployment resume" }
func (c *DeploymentResumeCommand) Run(args []string) int {
var detach, verbose bool
flags := c.Meta.FlagSet("deployment resume", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -75,10 +76,11 @@ func (c *DeploymentResumeCommand) Run(args []string) int {
return 1
}
// Check that we got no arguments
// Check that we got exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <deployment id>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -67,11 +67,13 @@ func (c *DeploymentStatusCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *DeploymentStatusCommand) Name() string { return "deployment status" }
func (c *DeploymentStatusCommand) Run(args []string) int {
var json, verbose bool
var tmpl string
flags := c.Meta.FlagSet("deployment status", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&verbose, "verbose", false, "")
flags.BoolVar(&json, "json", false, "")
@ -81,10 +83,11 @@ func (c *DeploymentStatusCommand) Run(args []string) int {
return 1
}
// Check that we got no arguments
// Check that we got exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <deployment id>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -33,6 +33,8 @@ func (f *EvalCommand) Synopsis() string {
return "Interact with evaluations"
}
func (f *EvalCommand) Name() string { return "eval" }
func (f *EvalCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -77,11 +77,13 @@ 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 tmpl string
flags := c.Meta.FlagSet("eval status", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&monitor, "monitor", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -121,7 +123,8 @@ func (c *EvalStatusCommand) Run(args []string) int {
}
if len(args) != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -484,3 +484,9 @@ func sanitizeUUIDPrefix(prefix string) string {
remainder := length % 2
return prefix[:len(prefix)-remainder]
}
// commandErrorText is used to easily render the same messaging accross commads
// when an error is printed.
func commandErrorText(cmd NamedCommand) string {
return fmt.Sprintf("For additional help try 'nomad %s -help'", cmd.Name())
}

View File

@ -42,6 +42,8 @@ func (f *JobCommand) Synopsis() string {
return "Interact with jobs"
}
func (f *JobCommand) Name() string { return "job" }
func (f *JobCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -68,11 +68,13 @@ func (c *JobDeploymentsCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *JobDeploymentsCommand) Name() string { return "job deployments" }
func (c *JobDeploymentsCommand) Run(args []string) int {
var json, latest, verbose bool
var tmpl string
flags := c.Meta.FlagSet("job deployments", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&latest, "latest", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -86,7 +88,8 @@ func (c *JobDeploymentsCommand) Run(args []string) int {
// Check that we got exactly one node
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <job>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -22,7 +22,7 @@ Usage: nomad job dispatch [options] <parameterized job> [input source]
Dispatch creates an instance of a parameterized job. A data payload to the
dispatched instance can be provided via stdin by using "-" or by specifying a
path to a file. Metadata can be supplied by using the meta flag one or more
times.
times.
Upon successful creation, the dispatched job ID will be printed and the
triggered evaluation will be monitored. This can be disabled by supplying the
@ -40,7 +40,7 @@ Dispatch Options:
key which is overridden when dispatching. The flag can be provided more than
once to inject multiple metadata key/value pairs. Arbitrary keys are not
allowed. The parameterized job must allow the key to be merged.
-detach
Return immediately instead of entering monitor mode. After job dispatch,
the evaluation ID will be printed to the screen, which can be used to
@ -80,11 +80,13 @@ 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 meta []string
flags := c.Meta.FlagSet("job dispatch", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -102,8 +104,9 @@ func (c *JobDispatchCommand) Run(args []string) int {
// Check that we got exactly one node
args = flags.Args()
if l := len(args); l < 1 || l > 2 {
c.Ui.Error(c.Help())
if l := len(args); l != 1 {
c.Ui.Error("This command takes one argument, <parameterized job>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -80,11 +80,13 @@ func (c *JobHistoryCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *JobHistoryCommand) Name() string { return "job history" }
func (c *JobHistoryCommand) Run(args []string) int {
var json, diff, full bool
var tmpl, versionStr string
flags := c.Meta.FlagSet("job history", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&diff, "p", false, "")
flags.BoolVar(&full, "full", false, "")
@ -99,7 +101,8 @@ func (c *JobHistoryCommand) Run(args []string) int {
// Check that we got exactly one node
args = flags.Args()
if l := len(args); l < 1 || l > 2 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <job>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -34,10 +34,13 @@ func (c *JobInitCommand) Synopsis() string {
return "Create an example job file"
}
func (c *JobInitCommand) Name() string { return "job init" }
func (c *JobInitCommand) Run(args []string) int {
// Check for misuse
if len(args) != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}
@ -129,24 +132,24 @@ job "example" {
# perform in parallel. In this case, this specifies to update a single task
# at a time.
max_parallel = 1
# The "min_healthy_time" parameter specifies the minimum time the allocation
# must be in the healthy state before it is marked as healthy and unblocks
# further allocations from being updated.
min_healthy_time = "10s"
# The "healthy_deadline" parameter specifies the deadline in which the
# allocation must be marked as healthy after which the allocation is
# automatically transitioned to unhealthy. Transitioning to unhealthy will
# fail the deployment and potentially roll back the job if "auto_revert" is
# set to true.
healthy_deadline = "3m"
# The "auto_revert" parameter specifies if the job should auto-revert to the
# last stable job on deployment failure. A job is marked as stable if all the
# allocations as part of its deployment were marked healthy.
auto_revert = false
# The "canary" parameter specifies that changes to the job that would result
# in destructive updates should create the specified number of canaries
# without stopping any previous allocations. Once the operator determines the
@ -162,7 +165,7 @@ job "example" {
# The migrate stanza specifies the group's strategy for migrating off of
# draining nodes. If omitted, a default migration strategy is applied.
#
# For more information on the "migrate" stanza, please see
# For more information on the "migrate" stanza, please see
# the online documentation at:
#
# https://www.nomadproject.io/docs/job-specification/migrate.html
@ -243,7 +246,7 @@ job "example" {
# will migrate the data. This is useful for tasks that store data
# that should persist across allocation updates.
# sticky = true
#
#
# Setting migrate to true results in the allocation directory of a
# sticky allocation directory to be migrated.
# migrate = true

View File

@ -66,11 +66,13 @@ func (c *JobInspectCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *JobInspectCommand) Name() string { return "job inspect" }
func (c *JobInspectCommand) Run(args []string) int {
var json bool
var tmpl, versionStr string
flags := c.Meta.FlagSet("job inspect", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")
@ -108,7 +110,8 @@ func (c *JobInspectCommand) Run(args []string) int {
// Check that we got exactly one job
if len(args) != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <job>")
c.Ui.Error(commandErrorText(c))
return 1
}
jobID := args[0]

View File

@ -93,10 +93,11 @@ func (c *JobPlanCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictOr(complete.PredictFiles("*.nomad"), complete.PredictFiles("*.hcl"))
}
func (c *JobPlanCommand) Name() string { return "job plan" }
func (c *JobPlanCommand) Run(args []string) int {
var diff, policyOverride, verbose bool
flags := c.Meta.FlagSet("job plan", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&diff, "diff", true, "")
flags.BoolVar(&policyOverride, "policy-override", false, "")
@ -109,7 +110,8 @@ func (c *JobPlanCommand) Run(args []string) int {
// Check that we got exactly one job
args = flags.Args()
if len(args) != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <path>")
c.Ui.Error(commandErrorText(c))
return 255
}

View File

@ -76,11 +76,13 @@ func (c *JobPromoteCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *JobPromoteCommand) Name() string { return "job promote" }
func (c *JobPromoteCommand) Run(args []string) int {
var detach, verbose bool
var groups []string
flags := c.Meta.FlagSet("job promote", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -90,10 +92,11 @@ func (c *JobPromoteCommand) Run(args []string) int {
return 1
}
// Check that we got no arguments
// Check that we got exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <job id>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -63,10 +63,12 @@ func (c *JobRevertCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *JobRevertCommand) Name() string { return "job revert" }
func (c *JobRevertCommand) Run(args []string) int {
var detach, verbose bool
flags := c.Meta.FlagSet("job revert", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -84,7 +86,8 @@ func (c *JobRevertCommand) Run(args []string) int {
// Check that we got two args
args = flags.Args()
if l := len(args); l != 2 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes two arguments, <job> <version>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -114,11 +114,13 @@ func (c *JobRunCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictOr(complete.PredictFiles("*.nomad"), complete.PredictFiles("*.hcl"))
}
func (c *JobRunCommand) Name() string { return "job run" }
func (c *JobRunCommand) Run(args []string) int {
var detach, verbose, output, override bool
var checkIndexStr, vaultToken string
flags := c.Meta.FlagSet("job run", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -140,14 +142,8 @@ func (c *JobRunCommand) Run(args []string) int {
// Check that we got exactly one argument
args = flags.Args()
if len(args) != 1 {
c.Ui.Error(c.Help())
return 1
}
// Check that we got exactly one node
args = flags.Args()
if len(args) != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <path>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -85,10 +85,12 @@ func (c *JobStatusCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *JobStatusCommand) Name() string { return "status" }
func (c *JobStatusCommand) Run(args []string) int {
var short bool
flags := c.Meta.FlagSet("status", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&short, "short", false, "")
flags.BoolVar(&c.evals, "evals", false, "")
@ -102,7 +104,8 @@ func (c *JobStatusCommand) Run(args []string) int {
// Check that we either got no jobs or exactly one.
args = flags.Args()
if len(args) > 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes either no arguments or one, <job>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -77,10 +77,12 @@ func (c *JobStopCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *JobStopCommand) Name() string { return "job stop" }
func (c *JobStopCommand) Run(args []string) int {
var detach, purge, verbose, autoYes bool
flags := c.Meta.FlagSet("job stop", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
@ -100,7 +102,8 @@ func (c *JobStopCommand) Run(args []string) int {
// Check that we got exactly one job
args = flags.Args()
if len(args) != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <job>")
c.Ui.Error(commandErrorText(c))
return 1
}
jobID := args[0]

View File

@ -43,8 +43,10 @@ func (c *JobValidateCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictOr(complete.PredictFiles("*.nomad"), complete.PredictFiles("*.hcl"))
}
func (c *JobValidateCommand) Name() string { return "job validate" }
func (c *JobValidateCommand) Run(args []string) int {
flags := c.Meta.FlagSet("job validate", FlagSetNone)
flags := c.Meta.FlagSet(c.Name(), FlagSetNone)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
@ -53,7 +55,8 @@ func (c *JobValidateCommand) Run(args []string) int {
// Check that we got exactly one node
args = flags.Args()
if len(args) != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <path>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -43,6 +43,8 @@ func (f *NamespaceCommand) Synopsis() string {
return "Interact with namespaces"
}
func (f *NamespaceCommand) Name() string { return "namespace" }
func (f *NamespaceCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -51,10 +51,12 @@ func (c *NamespaceApplyCommand) Synopsis() string {
return "Create or update a namespace"
}
func (c *NamespaceApplyCommand) Name() string { return "namespace apply" }
func (c *NamespaceApplyCommand) Run(args []string) int {
var description, quota *string
flags := c.Meta.FlagSet("namespace apply", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.Var((flaghelper.FuncVar)(func(s string) error {
description = &s
@ -72,7 +74,8 @@ func (c *NamespaceApplyCommand) Run(args []string) int {
// Check that we get exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <namespace>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -37,8 +37,10 @@ func (c *NamespaceDeleteCommand) Synopsis() string {
return "Delete a namespace"
}
func (c *NamespaceDeleteCommand) Name() string { return "namespace delete" }
func (c *NamespaceDeleteCommand) Run(args []string) int {
flags := c.Meta.FlagSet("namespace delete", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
@ -48,7 +50,8 @@ func (c *NamespaceDeleteCommand) Run(args []string) int {
// Check that we got one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <namespace>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -45,9 +45,11 @@ func (c *NamespaceInspectCommand) Synopsis() string {
return "Inspect a namespace"
}
func (c *NamespaceInspectCommand) Name() string { return "namespace inspect" }
func (c *NamespaceInspectCommand) Run(args []string) int {
var tmpl string
flags := c.Meta.FlagSet("namespace inspect", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.StringVar(&tmpl, "t", "", "")
@ -58,7 +60,8 @@ func (c *NamespaceInspectCommand) Run(args []string) int {
// Check that we got one arguments
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <namespace>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -50,11 +50,13 @@ func (c *NamespaceListCommand) Synopsis() string {
return "List namespaces"
}
func (c *NamespaceListCommand) Name() string { return "namespace list" }
func (c *NamespaceListCommand) Run(args []string) int {
var json bool
var tmpl string
flags := c.Meta.FlagSet("namespace list", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")
@ -66,7 +68,8 @@ func (c *NamespaceListCommand) Run(args []string) int {
// Check that we got no arguments
args = flags.Args()
if l := len(args); l != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -37,8 +37,10 @@ func (c *NamespaceStatusCommand) Synopsis() string {
return "Display a namespace's status"
}
func (c *NamespaceStatusCommand) Name() string { return "namespace status" }
func (c *NamespaceStatusCommand) Run(args []string) int {
flags := c.Meta.FlagSet("namespace status", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
@ -48,7 +50,8 @@ func (c *NamespaceStatusCommand) Run(args []string) int {
// Check that we got one arguments
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <namespace>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -12,7 +12,7 @@ type NodeCommand struct {
func (f *NodeCommand) Help() string {
helpText := `
Usage: nomad nomad <subcommand> [options] [args]
Usage: nomad node <subcommand> [options] [args]
This command groups subcommands for interacting with nodes. Nodes in Nomad are
agent's that can run submitted workloads. This command can be used to examine
@ -42,6 +42,8 @@ func (f *NodeCommand) Synopsis() string {
return "Interact with nodes"
}
func (f *NodeCommand) Name() string { return "node" }
func (f *NodeCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -50,10 +50,12 @@ func (c *NodeConfigCommand) Synopsis() string {
return "View or modify client configuration details"
}
func (c *NodeConfigCommand) Name() string { return "node config" }
func (c *NodeConfigCommand) Run(args []string) int {
var listServers, updateServers bool
flags := c.Meta.FlagSet("node config", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&listServers, "servers", false, "")
flags.BoolVar(&updateServers, "update-servers", false, "")
@ -65,7 +67,8 @@ func (c *NodeConfigCommand) Run(args []string) int {
// Check the flags for misuse
if !listServers && !updateServers {
c.Ui.Error(c.Help())
c.Ui.Error("The '-servers' or '-update-servers' flag(s) must be set")
c.Ui.Error(commandErrorText(c))
return 1
}
@ -79,7 +82,8 @@ func (c *NodeConfigCommand) Run(args []string) int {
if updateServers {
// Get the server addresses
if len(args) == 0 {
c.Ui.Error(c.Help())
c.Ui.Error("If the '-update-servers' flag is set, atleast one server argument must be provided")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -109,12 +109,14 @@ func (c *NodeDrainCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *NodeDrainCommand) Name() string { return "node-drain" }
func (c *NodeDrainCommand) Run(args []string) int {
var enable, disable, detach, force,
noDeadline, ignoreSystem, keepIneligible, self, autoYes bool
var deadline string
flags := c.Meta.FlagSet("node-drain", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&enable, "enable", false, "Enable drain mode")
flags.BoolVar(&disable, "disable", false, "Disable drain mode")
@ -133,7 +135,8 @@ func (c *NodeDrainCommand) Run(args []string) int {
// Check that we got either enable or disable, but not both.
if (enable && disable) || (!enable && !disable) {
c.Ui.Error(c.Help())
c.Ui.Error("Ethier the '-enable' or '-disable' flag must be set")
c.Ui.Error(commandErrorText(c))
return 1
}
@ -141,20 +144,24 @@ func (c *NodeDrainCommand) Run(args []string) int {
args = flags.Args()
if l := len(args); self && l != 0 || !self && l != 1 {
c.Ui.Error("Node ID must be specified if -self isn't being used")
c.Ui.Error(commandErrorText(c))
return 1
}
// Validate a compatible set of flags were set
if disable && (deadline != "" || force || noDeadline || ignoreSystem) {
c.Ui.Error("-disable can't be combined with flags configuring drain strategy")
c.Ui.Error(commandErrorText(c))
return 1
}
if deadline != "" && (force || noDeadline) {
c.Ui.Error("-deadline can't be combined with -force or -no-deadline")
c.Ui.Error(commandErrorText(c))
return 1
}
if force && noDeadline {
c.Ui.Error("-force and -no-deadline are mutually exclusive")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -69,10 +69,12 @@ func (c *NodeEligibilityCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *NodeEligibilityCommand) Name() string { return "node-eligibility" }
func (c *NodeEligibilityCommand) Run(args []string) int {
var enable, disable, self bool
flags := c.Meta.FlagSet("node-eligibility", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&enable, "enable", false, "Mark node as eligibile for scheduling")
flags.BoolVar(&disable, "disable", false, "Mark node as ineligibile for scheduling")
@ -84,7 +86,8 @@ func (c *NodeEligibilityCommand) Run(args []string) int {
// Check that we got either enable or disable, but not both.
if (enable && disable) || (!enable && !disable) {
c.Ui.Error(c.Help())
c.Ui.Error("Ethier the '-enable' or '-disable' flag must be set")
c.Ui.Error(commandErrorText(c))
return 1
}
@ -92,6 +95,7 @@ func (c *NodeEligibilityCommand) Run(args []string) int {
args = flags.Args()
if l := len(args); self && l != 0 || !self && l != 1 {
c.Ui.Error("Node ID must be specified if -self isn't being used")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -111,9 +111,11 @@ func (c *NodeStatusCommand) AutocompleteArgs() complete.Predictor {
})
}
func (c *NodeStatusCommand) Name() string { return "node-status" }
func (c *NodeStatusCommand) Run(args []string) int {
flags := c.Meta.FlagSet("node-status", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&c.short, "short", false, "")
flags.BoolVar(&c.verbose, "verbose", false, "")
@ -130,7 +132,8 @@ func (c *NodeStatusCommand) Run(args []string) int {
// Check that we got either a single node or none
args = flags.Args()
if len(args) > 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes either one or no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -27,6 +27,8 @@ func (f *OperatorCommand) Synopsis() string {
return "Provides cluster-level tools for Nomad operators"
}
func (f *OperatorCommand) Name() string { return "operator" }
func (f *OperatorCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -10,6 +10,8 @@ type OperatorAutopilotCommand struct {
Meta
}
func (c *OperatorAutopilotCommand) Name() string { return "operator autopilot" }
func (c *OperatorAutopilotCommand) Run(args []string) int {
return cli.RunResultHelp
}
@ -30,11 +32,11 @@ Usage: nomad operator autopilot <subcommand> [options]
Get the current Autopilot configuration:
$ nomad operator autopilot get-config
Set a new Autopilot configuration, enabling automatic dead server cleanup:
$ nomad operator autopilot set-config -cleanup-dead-servers=true
Please see the individual subcommand help for detailed usage information.
`
return strings.TrimSpace(helpText)

View File

@ -19,6 +19,7 @@ func (c *OperatorAutopilotGetCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *OperatorAutopilotGetCommand) Name() string { return "operator autopilot get-config" }
func (c *OperatorAutopilotGetCommand) Run(args []string) int {
flags := c.Meta.FlagSet("autopilot", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }

View File

@ -29,6 +29,8 @@ func (c *OperatorAutopilotSetCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *OperatorAutopilotSetCommand) Name() string { return "operator autopilot set-config" }
func (c *OperatorAutopilotSetCommand) Run(args []string) int {
var cleanupDeadServers flags.BoolValue
var maxTrailingLogs flags.UintValue

View File

@ -28,6 +28,8 @@ Usage: nomad operator keygen
return strings.TrimSpace(helpText)
}
func (c *OperatorKeygenCommand) Name() string { return "operator keygen" }
func (c *OperatorKeygenCommand) Run(_ []string) int {
key := make([]byte, 16)
n, err := rand.Reader.Read(key)

View File

@ -67,6 +67,8 @@ func (c *OperatorKeyringCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *OperatorKeyringCommand) Name() string { return "operator keyring" }
func (c *OperatorKeyringCommand) Run(args []string) int {
var installKey, useKey, removeKey string
var listKeys bool
@ -95,6 +97,7 @@ func (c *OperatorKeyringCommand) Run(args []string) int {
for _, arg := range []string{installKey, useKey, removeKey} {
if found && len(arg) > 0 {
c.Ui.Error("Only a single action is allowed")
c.Ui.Error(commandErrorText(c))
return 1
}
found = found || len(arg) > 0
@ -102,7 +105,9 @@ func (c *OperatorKeyringCommand) Run(args []string) int {
// Fail fast if no actionable args were passed
if !found {
c.Ui.Error(c.Help())
c.Ui.Error("No actionable argument was passed")
c.Ui.Error("Either the '-install', '-use', '-remove' or '-list' flag must be set")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -35,6 +35,8 @@ func (c *OperatorRaftCommand) Synopsis() string {
return "Provides access to the Raft subsystem"
}
func (c *OperatorRaftCommand) Name() string { return "operator raft" }
func (c *OperatorRaftCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -48,6 +48,8 @@ func (c *OperatorRaftListCommand) Synopsis() string {
return "Display the current Raft peer configuration"
}
func (c *OperatorRaftListCommand) Name() string { return "operator raft list-peers" }
func (c *OperatorRaftListCommand) Run(args []string) int {
var stale bool

View File

@ -33,7 +33,7 @@ Remove Peer Options:
-peer-address="IP:port"
Remove a Nomad server with given address from the Raft configuration.
-peer-id="id"
Remove a Nomad server with the given ID from the Raft configuration.
`
@ -56,6 +56,8 @@ func (c *OperatorRaftRemoveCommand) Synopsis() string {
return "Remove a Nomad server from the Raft configuration"
}
func (c *OperatorRaftRemoveCommand) Name() string { return "operator raft remove-peer" }
func (c *OperatorRaftRemoveCommand) Run(args []string) int {
var peerAddress string
var peerID string

View File

@ -20,7 +20,7 @@ Usage: nomad quota <subcommand> [options] [args]
quotas allow operators to restrict the aggregate resource usage of namespaces.
Users can inspect existing quota specifications, create new quotas, delete and
list existing quotas, and more. For a full guide on resource quotas see:
https://www.nomadproject.io/guides/quotas.html
https://www.nomadproject.io/guides/quotas.html
Examine a quota's status:
@ -44,6 +44,8 @@ func (f *QuotaCommand) Synopsis() string {
return "Interact with quotas"
}
func (f *QuotaCommand) Name() string { return "quota" }
func (f *QuotaCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -36,7 +36,7 @@ General Options:
Apply Options:
-json
Parse the input as a JSON quota specification.
Parse the input as a JSON quota specification.
`
return strings.TrimSpace(helpText)
@ -57,9 +57,11 @@ func (c *QuotaApplyCommand) Synopsis() string {
return "Create or update a quota specification"
}
func (c *QuotaApplyCommand) Name() string { return "quota apply" }
func (c *QuotaApplyCommand) Run(args []string) int {
var jsonInput bool
flags := c.Meta.FlagSet("quota apply", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&jsonInput, "json", false, "")
@ -70,7 +72,8 @@ func (c *QuotaApplyCommand) Run(args []string) int {
// Check that we get exactly one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <input>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -36,8 +36,10 @@ func (c *QuotaDeleteCommand) Synopsis() string {
return "Delete a quota specification"
}
func (c *QuotaDeleteCommand) Name() string { return "quota delete" }
func (c *QuotaDeleteCommand) Run(args []string) int {
flags := c.Meta.FlagSet("quota delete", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
@ -47,7 +49,8 @@ func (c *QuotaDeleteCommand) Run(args []string) int {
// Check that we got one argument
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <quota>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -35,7 +35,7 @@ Usage: nomad quota init
Init Options:
-json
Create an example JSON quota specification.
Create an example JSON quota specification.
`
return strings.TrimSpace(helpText)
}
@ -54,9 +54,11 @@ func (c *QuotaInitCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *QuotaInitCommand) Name() string { return "quota init" }
func (c *QuotaInitCommand) Run(args []string) int {
var jsonOutput bool
flags := c.Meta.FlagSet("quota init", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&jsonOutput, "json", false, "")
@ -67,7 +69,8 @@ func (c *QuotaInitCommand) Run(args []string) int {
// Check that we get no arguments
args = flags.Args()
if l := len(args); l != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -52,9 +52,11 @@ func (c *QuotaInspectCommand) Synopsis() string {
return "Inspect a quota specification"
}
func (c *QuotaInspectCommand) Name() string { return "quota inspect" }
func (c *QuotaInspectCommand) Run(args []string) int {
var tmpl string
flags := c.Meta.FlagSet("quota inspect", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.StringVar(&tmpl, "t", "", "")
@ -65,7 +67,8 @@ func (c *QuotaInspectCommand) Run(args []string) int {
// Check that we got one arguments
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <quota>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -50,11 +50,12 @@ func (c *QuotaListCommand) Synopsis() string {
return "List quota specifications"
}
func (c *QuotaListCommand) Name() string { return "quota list" }
func (c *QuotaListCommand) Run(args []string) int {
var json bool
var tmpl string
flags := c.Meta.FlagSet("quota list", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")
@ -66,7 +67,8 @@ func (c *QuotaListCommand) Run(args []string) int {
// Check that we got no arguments
args = flags.Args()
if l := len(args); l != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -40,8 +40,10 @@ func (c *QuotaStatusCommand) Synopsis() string {
return "Display a quota's status and current usage"
}
func (c *QuotaStatusCommand) Name() string { return "quota status" }
func (c *QuotaStatusCommand) Run(args []string) int {
flags := c.Meta.FlagSet("quota status", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
@ -51,7 +53,8 @@ func (c *QuotaStatusCommand) Run(args []string) int {
// Check that we got one arguments
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <quota>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -45,6 +45,8 @@ func (f *SentinelCommand) Synopsis() string {
return "Interact with Sentinel policies"
}
func (f *SentinelCommand) Name() string { return "sentinel" }
func (f *SentinelCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -59,10 +59,12 @@ func (c *SentinelApplyCommand) Synopsis() string {
return "Create a new or update existing Sentinel policies"
}
func (c *SentinelApplyCommand) Name() string { return "sentinel apply" }
func (c *SentinelApplyCommand) Run(args []string) int {
var description, scope, enfLevel string
var err error
flags := c.Meta.FlagSet("sentinel apply", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.StringVar(&description, "description", "", "")
flags.StringVar(&scope, "scope", "submit-job", "")
@ -74,7 +76,8 @@ func (c *SentinelApplyCommand) Run(args []string) int {
// Check that we got exactly two arguments
args = flags.Args()
if l := len(args); l != 2 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes exactly two arguments, <name> <file>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -38,8 +38,10 @@ func (c *SentinelDeleteCommand) Synopsis() string {
return "Delete an existing Sentinel policies"
}
func (c *SentinelDeleteCommand) Name() string { return "sentinel delete" }
func (c *SentinelDeleteCommand) Run(args []string) int {
flags := c.Meta.FlagSet("sentinel delete", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
@ -48,7 +50,8 @@ func (c *SentinelDeleteCommand) Run(args []string) int {
// Check that we got exactly one arguments
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <name>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -38,13 +38,19 @@ func (c *SentinelListCommand) Synopsis() string {
return "Display all Sentinel policies"
}
func (c *SentinelListCommand) Name() string { return "sentinel list" }
func (c *SentinelListCommand) Run(args []string) int {
flags := c.Meta.FlagSet("sentinel list", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
}
if args = flags.Args(); len(args) > 0 {
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
}
// Get the HTTP client
client, err := c.Meta.Client()
if err != nil {

View File

@ -45,9 +45,11 @@ func (c *SentinelReadCommand) Synopsis() string {
return "Inspects an existing Sentinel policies"
}
func (c *SentinelReadCommand) Name() string { return "sentinel read" }
func (c *SentinelReadCommand) Run(args []string) int {
var raw bool
flags := c.Meta.FlagSet("sentinel read", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&raw, "raw", false, "")
if err := flags.Parse(args); err != nil {
@ -57,7 +59,8 @@ func (c *SentinelReadCommand) Run(args []string) int {
// Check that we got exactly one arguments
args = flags.Args()
if l := len(args); l != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <name>")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -39,6 +39,8 @@ func (f *ServerCommand) Synopsis() string {
return "Interact with servers"
}
func (f *ServerCommand) Name() string { return "server" }
func (f *ServerCommand) Run(args []string) int {
return cli.RunResultHelp
}

View File

@ -28,8 +28,10 @@ func (c *ServerForceLeaveCommand) Synopsis() string {
return "Force a server into the 'left' state"
}
func (c *ServerForceLeaveCommand) Name() string { return "server force-leave" }
func (c *ServerForceLeaveCommand) Run(args []string) int {
flags := c.Meta.FlagSet("server-force-leave", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
@ -38,7 +40,8 @@ func (c *ServerForceLeaveCommand) Run(args []string) int {
// Check that we got exactly one node
args = flags.Args()
if len(args) != 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes one argument, <node>")
c.Ui.Error(commandErrorText(c))
return 1
}
node := args[0]

View File

@ -29,8 +29,10 @@ func (c *ServerJoinCommand) Synopsis() string {
return "Join server nodes together"
}
func (c *ServerJoinCommand) Name() string { return "server join" }
func (c *ServerJoinCommand) Run(args []string) int {
flags := c.Meta.FlagSet("server-join", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
@ -39,7 +41,8 @@ func (c *ServerJoinCommand) Run(args []string) int {
// Check that we got at least one node
args = flags.Args()
if len(args) < 1 {
c.Ui.Error(c.Help())
c.Ui.Error("One or more node addresses must be given as arguments")
c.Ui.Error(commandErrorText(c))
return 1
}
nodes := args

View File

@ -52,10 +52,12 @@ func (c *ServerMembersCommand) Synopsis() string {
return "Display a list of known servers and their status"
}
func (c *ServerMembersCommand) Name() string { return "server members" }
func (c *ServerMembersCommand) Run(args []string) int {
var detailed bool
flags := c.Meta.FlagSet("server-members", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detailed, "detailed", false, "Show detailed output")
@ -66,7 +68,8 @@ func (c *ServerMembersCommand) Run(args []string) int {
// Check for extra arguments
args = flags.Args()
if len(args) != 0 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -72,8 +72,10 @@ func (c *UiCommand) Synopsis() string {
return "Open the Nomad Web UI"
}
func (c *UiCommand) Name() string { return "ui" }
func (c *UiCommand) Run(args []string) int {
flags := c.Meta.FlagSet("deployment list", FlagSetClient)
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
if err := flags.Parse(args); err != nil {
@ -83,7 +85,8 @@ func (c *UiCommand) Run(args []string) int {
// Check that we got no more than one argument
args = flags.Args()
if l := len(args); l > 1 {
c.Ui.Error(c.Help())
c.Ui.Error("This command takes no or one optional argument, [<identifier>]")
c.Ui.Error(commandErrorText(c))
return 1
}

View File

@ -15,6 +15,8 @@ func (c *VersionCommand) Help() string {
return ""
}
func (c *VersionCommand) Name() string { return "version" }
func (c *VersionCommand) Run(_ []string) int {
c.Ui.Output(c.Version.FullVersionNumber(true))
return 0