From 45b0ce9177be3976317d736b0d33da822ac46278 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Wed, 18 Apr 2018 12:02:11 -0400 Subject: [PATCH 1/5] command: improve help text when invalid arguments are given --- command/acl.go | 2 ++ command/acl_bootstrap.go | 7 +++++-- command/acl_policy.go | 2 ++ command/acl_policy_apply.go | 7 +++++-- command/acl_policy_delete.go | 7 +++++-- command/acl_policy_info.go | 7 +++++-- command/acl_policy_list.go | 7 +++++-- command/acl_token.go | 2 ++ command/acl_token_create.go | 7 +++++-- command/acl_token_delete.go | 7 +++++-- command/acl_token_info.go | 7 +++++-- command/acl_token_self.go | 9 ++++++--- command/acl_token_update.go | 7 +++++-- command/agent_info.go | 9 ++++++--- command/alloc.go | 2 ++ command/alloc_fs.go | 12 ++++++++---- command/alloc_logs.go | 13 ++++++++----- command/alloc_status.go | 9 +++++++-- command/check.go | 9 +++++++++ command/commands.go | 5 +++++ command/deployment.go | 2 ++ command/deployment_fail.go | 7 +++++-- command/deployment_list.go | 7 +++++-- command/deployment_pause.go | 9 ++++++--- command/deployment_promote.go | 9 ++++++--- command/deployment_resume.go | 8 +++++--- command/deployment_status.go | 9 ++++++--- command/eval.go | 2 ++ command/eval_status.go | 7 +++++-- command/helpers.go | 6 ++++++ command/job.go | 2 ++ command/job_deployments.go | 7 +++++-- command/job_dispatch.go | 13 ++++++++----- command/job_history.go | 7 +++++-- command/job_init.go | 17 ++++++++++------- command/job_inspect.go | 7 +++++-- command/job_plan.go | 6 ++++-- command/job_promote.go | 9 ++++++--- command/job_revert.go | 7 +++++-- command/job_run.go | 14 +++++--------- command/job_status.go | 7 +++++-- command/job_stop.go | 7 +++++-- command/job_validate.go | 7 +++++-- command/namespace.go | 2 ++ command/namespace_apply.go | 7 +++++-- command/namespace_delete.go | 7 +++++-- command/namespace_inspect.go | 7 +++++-- command/namespace_list.go | 7 +++++-- command/namespace_status.go | 7 +++++-- command/node.go | 4 +++- command/node_config.go | 10 +++++++--- command/node_drain.go | 11 +++++++++-- command/node_eligibility.go | 8 ++++++-- command/node_status.go | 7 +++++-- command/operator.go | 2 ++ command/operator_autopilot.go | 6 ++++-- command/operator_autopilot_get.go | 1 + command/operator_autopilot_set.go | 2 ++ command/operator_keygen.go | 2 ++ command/operator_keyring.go | 7 ++++++- command/operator_raft.go | 2 ++ command/operator_raft_list.go | 2 ++ command/operator_raft_remove.go | 4 +++- command/quota.go | 4 +++- command/quota_apply.go | 9 ++++++--- command/quota_delete.go | 7 +++++-- command/quota_init.go | 9 ++++++--- command/quota_inspect.go | 7 +++++-- command/quota_list.go | 6 ++++-- command/quota_status.go | 7 +++++-- command/sentinel.go | 2 ++ command/sentinel_apply.go | 7 +++++-- command/sentinel_delete.go | 7 +++++-- command/sentinel_list.go | 8 +++++++- command/sentinel_read.go | 7 +++++-- command/server.go | 2 ++ command/server_force_leave.go | 7 +++++-- command/server_join.go | 7 +++++-- command/server_members.go | 7 +++++-- command/ui.go | 7 +++++-- command/version.go | 2 ++ 81 files changed, 383 insertions(+), 147 deletions(-) diff --git a/command/acl.go b/command/acl.go index 4cc45a18c3e..4667fbf9feb 100644 --- a/command/acl.go +++ b/command/acl.go @@ -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 } diff --git a/command/acl_bootstrap.go b/command/acl_bootstrap.go index 22718b2c2cd..634eea7e896 100644 --- a/command/acl_bootstrap.go +++ b/command/acl_bootstrap.go @@ -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 } diff --git a/command/acl_policy.go b/command/acl_policy.go index 28e9e1be054..f10718149f8 100644 --- a/command/acl_policy.go +++ b/command/acl_policy.go @@ -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 } diff --git a/command/acl_policy_apply.go b/command/acl_policy_apply.go index ab438e6f302..6133ae046bd 100644 --- a/command/acl_policy_apply.go +++ b/command/acl_policy_apply.go @@ -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, and ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_policy_delete.go b/command/acl_policy_delete.go index a928f279908..e09d27e0a4b 100644 --- a/command/acl_policy_delete.go +++ b/command/acl_policy_delete.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_policy_info.go b/command/acl_policy_info.go index b58c6fce133..0d0fcf38680 100644 --- a/command/acl_policy_info.go +++ b/command/acl_policy_info.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_policy_list.go b/command/acl_policy_list.go index 65e2a42ae6e..aa04dd8b323 100644 --- a/command/acl_policy_list.go +++ b/command/acl_policy_list.go @@ -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 } diff --git a/command/acl_token.go b/command/acl_token.go index 8f1faa50327..395fdb84db0 100644 --- a/command/acl_token.go +++ b/command/acl_token.go @@ -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 } diff --git a/command/acl_token_create.go b/command/acl_token_create.go index a513d948370..d7a80e10f41 100644 --- a/command/acl_token_create.go +++ b/command/acl_token_create.go @@ -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 } diff --git a/command/acl_token_delete.go b/command/acl_token_delete.go index 7724b319791..ed56236d137 100644 --- a/command/acl_token_delete.go +++ b/command/acl_token_delete.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_token_info.go b/command/acl_token_info.go index bb03b1165a6..87c76a18d2c 100644 --- a/command/acl_token_info.go +++ b/command/acl_token_info.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_token_self.go b/command/acl_token_self.go index 0a547ddffab..19441a486e5 100644 --- a/command/acl_token_self.go +++ b/command/acl_token_self.go @@ -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 } diff --git a/command/acl_token_update.go b/command/acl_token_update.go index e1632b93cbb..47eb158ba14 100644 --- a/command/acl_token_update.go +++ b/command/acl_token_update.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/agent_info.go b/command/agent_info.go index e482157a8d1..65d24842f1e 100644 --- a/command/agent_info.go +++ b/command/agent_info.go @@ -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 } diff --git a/command/alloc.go b/command/alloc.go index 04f232b3f28..f3d8663bc39 100644 --- a/command/alloc.go +++ b/command/alloc.go @@ -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 } diff --git a/command/alloc_fs.go b/command/alloc_fs.go index 1a59df7743b..69ed15c20b8 100644 --- a/command/alloc_fs.go +++ b/command/alloc_fs.go @@ -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, []") + f.Ui.Error(commandErrorText(f)) return 1 } diff --git a/command/alloc_logs.go b/command/alloc_logs.go index 20ad8356121..3691c52bf7e 100644 --- a/command/alloc_logs.go +++ b/command/alloc_logs.go @@ -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 } diff --git a/command/alloc_status.go b/command/alloc_status.go index ccd90a35f33..b3e41fa6ae1 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -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 ") + c.Ui.Error(" * No arguments, with output format specified") + c.Ui.Error(commandErrorText(c)) return 1 } allocID := args[0] diff --git a/command/check.go b/command/check.go index 922d7bccc64..0c2c3f07501 100644 --- a/command/check.go +++ b/command/check.go @@ -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)) diff --git a/command/commands.go b/command/commands.go index 6eeba401aac..c4104ca4548 100644 --- a/command/commands.go +++ b/command/commands.go @@ -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 { diff --git a/command/deployment.go b/command/deployment.go index f0d13bb2183..6f87558fe32 100644 --- a/command/deployment.go +++ b/command/deployment.go @@ -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 } diff --git a/command/deployment_fail.go b/command/deployment_fail.go index 8dbc0224988..25ad154b7e4 100644 --- a/command/deployment_fail.go +++ b/command/deployment_fail.go @@ -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 } diff --git a/command/deployment_list.go b/command/deployment_list.go index 05e256c792a..94f1773512a 100644 --- a/command/deployment_list.go +++ b/command/deployment_list.go @@ -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 } diff --git a/command/deployment_pause.go b/command/deployment_pause.go index 31c8bbab89e..62600e12b73 100644 --- a/command/deployment_pause.go +++ b/command/deployment_pause.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/deployment_promote.go b/command/deployment_promote.go index 337fe5c2315..05389360a39 100644 --- a/command/deployment_promote.go +++ b/command/deployment_promote.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } dID := args[0] diff --git a/command/deployment_resume.go b/command/deployment_resume.go index 15f40a81c0f..316ac3475ed 100644 --- a/command/deployment_resume.go +++ b/command/deployment_resume.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/deployment_status.go b/command/deployment_status.go index e7d697cc4d6..053445ab19f 100644 --- a/command/deployment_status.go +++ b/command/deployment_status.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/eval.go b/command/eval.go index a1031634f20..af0ddaa5925 100644 --- a/command/eval.go +++ b/command/eval.go @@ -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 } diff --git a/command/eval_status.go b/command/eval_status.go index 75a6cc0d7cc..99312fdcbb1 100644 --- a/command/eval_status.go +++ b/command/eval_status.go @@ -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 } diff --git a/command/helpers.go b/command/helpers.go index 025dc6555e0..30af6f24073 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -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()) +} diff --git a/command/job.go b/command/job.go index 36d0e1ce276..79d6a00e851 100644 --- a/command/job.go +++ b/command/job.go @@ -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 } diff --git a/command/job_deployments.go b/command/job_deployments.go index be0b021504a..6d52ed0dbd3 100644 --- a/command/job_deployments.go +++ b/command/job_deployments.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_dispatch.go b/command/job_dispatch.go index c782facf378..7dcf2a7f633 100644 --- a/command/job_dispatch.go +++ b/command/job_dispatch.go @@ -22,7 +22,7 @@ Usage: nomad job dispatch [options] [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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_history.go b/command/job_history.go index a602d35466e..0e2600bf661 100644 --- a/command/job_history.go +++ b/command/job_history.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_init.go b/command/job_init.go index 7b1059aad9a..b77c3e58149 100644 --- a/command/job_init.go +++ b/command/job_init.go @@ -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 diff --git a/command/job_inspect.go b/command/job_inspect.go index cf7a0491fcf..a5ec0d5b0b4 100644 --- a/command/job_inspect.go +++ b/command/job_inspect.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } jobID := args[0] diff --git a/command/job_plan.go b/command/job_plan.go index a87acec8029..6ae7079d07f 100644 --- a/command/job_plan.go +++ b/command/job_plan.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 255 } diff --git a/command/job_promote.go b/command/job_promote.go index 01f63cb3a43..ff51fd96afb 100644 --- a/command/job_promote.go +++ b/command/job_promote.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_revert.go b/command/job_revert.go index ac070c7567f..283028237b5 100644 --- a/command/job_revert.go +++ b/command/job_revert.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_run.go b/command/job_run.go index 6fb19b2bce2..1cffead115f 100644 --- a/command/job_run.go +++ b/command/job_run.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_status.go b/command/job_status.go index aa2e12a04e2..ae2d3a981cf 100644 --- a/command/job_status.go +++ b/command/job_status.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_stop.go b/command/job_stop.go index b0da67d8b4e..a1d9fe7da7f 100644 --- a/command/job_stop.go +++ b/command/job_stop.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } jobID := args[0] diff --git a/command/job_validate.go b/command/job_validate.go index 950b1e3bba4..0b6f4bdac91 100644 --- a/command/job_validate.go +++ b/command/job_validate.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/namespace.go b/command/namespace.go index d43deec8435..813829d7c2f 100644 --- a/command/namespace.go +++ b/command/namespace.go @@ -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 } diff --git a/command/namespace_apply.go b/command/namespace_apply.go index eccd8ace526..be22951e689 100644 --- a/command/namespace_apply.go +++ b/command/namespace_apply.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/namespace_delete.go b/command/namespace_delete.go index 3b3717512a3..78088924379 100644 --- a/command/namespace_delete.go +++ b/command/namespace_delete.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/namespace_inspect.go b/command/namespace_inspect.go index 78f83e81010..444e287e7bf 100644 --- a/command/namespace_inspect.go +++ b/command/namespace_inspect.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/namespace_list.go b/command/namespace_list.go index 1d916b3717a..c44d9280018 100644 --- a/command/namespace_list.go +++ b/command/namespace_list.go @@ -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 } diff --git a/command/namespace_status.go b/command/namespace_status.go index f3780d9fde6..6e45f344e20 100644 --- a/command/namespace_status.go +++ b/command/namespace_status.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/node.go b/command/node.go index 0479d0b20ea..7654030b70e 100644 --- a/command/node.go +++ b/command/node.go @@ -12,7 +12,7 @@ type NodeCommand struct { func (f *NodeCommand) Help() string { helpText := ` -Usage: nomad nomad [options] [args] +Usage: nomad node [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 } diff --git a/command/node_config.go b/command/node_config.go index cf88db8bbeb..e77c14a3ba3 100644 --- a/command/node_config.go +++ b/command/node_config.go @@ -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 } diff --git a/command/node_drain.go b/command/node_drain.go index 0c0063f3b18..198feb233ca 100644 --- a/command/node_drain.go +++ b/command/node_drain.go @@ -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 } diff --git a/command/node_eligibility.go b/command/node_eligibility.go index 64a5d9533ff..27bf2404f13 100644 --- a/command/node_eligibility.go +++ b/command/node_eligibility.go @@ -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 } diff --git a/command/node_status.go b/command/node_status.go index 26e201dccc3..1ea62ff7b8a 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -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 } diff --git a/command/operator.go b/command/operator.go index 850154ba626..3937bc2e34e 100644 --- a/command/operator.go +++ b/command/operator.go @@ -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 } diff --git a/command/operator_autopilot.go b/command/operator_autopilot.go index c98e0b70424..aa73296c56a 100644 --- a/command/operator_autopilot.go +++ b/command/operator_autopilot.go @@ -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 [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) diff --git a/command/operator_autopilot_get.go b/command/operator_autopilot_get.go index 4e9012bcef3..b6e00b53a4b 100644 --- a/command/operator_autopilot_get.go +++ b/command/operator_autopilot_get.go @@ -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()) } diff --git a/command/operator_autopilot_set.go b/command/operator_autopilot_set.go index e60862f05b5..efc6010d7f5 100644 --- a/command/operator_autopilot_set.go +++ b/command/operator_autopilot_set.go @@ -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 diff --git a/command/operator_keygen.go b/command/operator_keygen.go index 621e915d87e..62dab3bae1d 100644 --- a/command/operator_keygen.go +++ b/command/operator_keygen.go @@ -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) diff --git a/command/operator_keyring.go b/command/operator_keyring.go index 5ef828178ba..ac0f3b2225b 100644 --- a/command/operator_keyring.go +++ b/command/operator_keyring.go @@ -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 } diff --git a/command/operator_raft.go b/command/operator_raft.go index 5d6df4eade8..79e0cb6482c 100644 --- a/command/operator_raft.go +++ b/command/operator_raft.go @@ -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 } diff --git a/command/operator_raft_list.go b/command/operator_raft_list.go index 6295dae4839..c3da3a6fe10 100644 --- a/command/operator_raft_list.go +++ b/command/operator_raft_list.go @@ -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 diff --git a/command/operator_raft_remove.go b/command/operator_raft_remove.go index 8a3a2bcbef8..d4cdfcadc8d 100644 --- a/command/operator_raft_remove.go +++ b/command/operator_raft_remove.go @@ -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 diff --git a/command/quota.go b/command/quota.go index 62d3570818e..fbbc9858c1b 100644 --- a/command/quota.go +++ b/command/quota.go @@ -20,7 +20,7 @@ Usage: nomad quota [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 } diff --git a/command/quota_apply.go b/command/quota_apply.go index 7d1dffe489d..4e0ab33040f 100644 --- a/command/quota_apply.go +++ b/command/quota_apply.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/quota_delete.go b/command/quota_delete.go index 7c6e1fd9755..b87e3c73933 100644 --- a/command/quota_delete.go +++ b/command/quota_delete.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/quota_init.go b/command/quota_init.go index a5a42d20df8..a78a356c773 100644 --- a/command/quota_init.go +++ b/command/quota_init.go @@ -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 } diff --git a/command/quota_inspect.go b/command/quota_inspect.go index 51253d85517..442890671dd 100644 --- a/command/quota_inspect.go +++ b/command/quota_inspect.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/quota_list.go b/command/quota_list.go index 7aa3d7cc148..d414a9de9dc 100644 --- a/command/quota_list.go +++ b/command/quota_list.go @@ -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 } diff --git a/command/quota_status.go b/command/quota_status.go index a19ba35f95c..ab812cb1fe1 100644 --- a/command/quota_status.go +++ b/command/quota_status.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/sentinel.go b/command/sentinel.go index 4e30f98bfad..3f26eea8272 100644 --- a/command/sentinel.go +++ b/command/sentinel.go @@ -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 } diff --git a/command/sentinel_apply.go b/command/sentinel_apply.go index 3070979e2e2..cd0c409f4b2 100644 --- a/command/sentinel_apply.go +++ b/command/sentinel_apply.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/sentinel_delete.go b/command/sentinel_delete.go index c1053b69125..55620795592 100644 --- a/command/sentinel_delete.go +++ b/command/sentinel_delete.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/sentinel_list.go b/command/sentinel_list.go index 84994b19fe2..ae86d5c7a12 100644 --- a/command/sentinel_list.go +++ b/command/sentinel_list.go @@ -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 { diff --git a/command/sentinel_read.go b/command/sentinel_read.go index ae3c7c7648e..8ee07205733 100644 --- a/command/sentinel_read.go +++ b/command/sentinel_read.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/server.go b/command/server.go index f675869cbf0..c729884a201 100644 --- a/command/server.go +++ b/command/server.go @@ -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 } diff --git a/command/server_force_leave.go b/command/server_force_leave.go index dde9e949bf3..0b56a0f79ef 100644 --- a/command/server_force_leave.go +++ b/command/server_force_leave.go @@ -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, ") + c.Ui.Error(commandErrorText(c)) return 1 } node := args[0] diff --git a/command/server_join.go b/command/server_join.go index 86208eaa5c0..c9244f11a8d 100644 --- a/command/server_join.go +++ b/command/server_join.go @@ -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 diff --git a/command/server_members.go b/command/server_members.go index f9e611b8782..63fcfbf7dc6 100644 --- a/command/server_members.go +++ b/command/server_members.go @@ -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 } diff --git a/command/ui.go b/command/ui.go index d11e75d71f1..8a6c42615f9 100644 --- a/command/ui.go +++ b/command/ui.go @@ -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, []") + c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/version.go b/command/version.go index c7527862a84..46751039531 100644 --- a/command/version.go +++ b/command/version.go @@ -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 From 5d39f68f89959bb9b6525e5a65973a557a9279c9 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Wed, 18 Apr 2018 12:19:53 -0400 Subject: [PATCH 2/5] command: fix misspelling in comment --- command/helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/helpers.go b/command/helpers.go index 30af6f24073..3d6eab7ff00 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -485,7 +485,7 @@ func sanitizeUUIDPrefix(prefix string) string { return prefix[:len(prefix)-remainder] } -// commandErrorText is used to easily render the same messaging accross commads +// commandErrorText is used to easily render the same messaging across commads // when an error is printed. func commandErrorText(cmd NamedCommand) string { return fmt.Sprintf("For additional help try 'nomad %s -help'", cmd.Name()) From 4a4ed06db1e9b6ab1812e3c93c8c59d7acc65e33 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Wed, 18 Apr 2018 13:51:17 -0400 Subject: [PATCH 3/5] command: update tests to check for new error message --- command/agent_info_test.go | 2 +- command/alloc_fs_test.go | 2 +- command/alloc_logs_test.go | 2 +- command/alloc_status_test.go | 2 +- command/deployment_fail_test.go | 2 +- command/deployment_list_test.go | 2 +- command/deployment_pause_test.go | 2 +- command/deployment_promote_test.go | 2 +- command/deployment_resume_test.go | 2 +- command/deployment_status_test.go | 2 +- command/eval_status_test.go | 2 +- command/job_deployments_test.go | 2 +- command/job_dispatch_test.go | 2 +- command/job_history_test.go | 2 +- command/job_init_test.go | 2 +- command/job_inspect_test.go | 2 +- command/job_plan_test.go | 2 +- command/job_promote_test.go | 2 +- command/job_revert_test.go | 2 +- command/job_run_test.go | 2 +- command/job_status_test.go | 2 +- command/job_stop_test.go | 2 +- command/job_validate_test.go | 2 +- command/namespace_apply_test.go | 4 ++-- command/namespace_delete_test.go | 2 +- command/namespace_inspect_test.go | 2 +- command/namespace_list_test.go | 2 +- command/namespace_status_test.go | 2 +- command/node_config_test.go | 6 +++--- command/node_drain_test.go | 6 +++--- command/node_eligibility_test.go | 6 +++--- command/node_status_test.go | 2 +- command/quota_apply_test.go | 4 ++-- command/quota_delete_test.go | 2 +- command/quota_init_test.go | 4 ++-- command/quota_inspect_test.go | 2 +- command/quota_list_test.go | 2 +- command/quota_status_test.go | 2 +- command/server_members_test.go | 2 +- 39 files changed, 48 insertions(+), 48 deletions(-) diff --git a/command/agent_info_test.go b/command/agent_info_test.go index 99361afc335..9099729aa7b 100644 --- a/command/agent_info_test.go +++ b/command/agent_info_test.go @@ -35,7 +35,7 @@ func TestAgentInfoCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/alloc_fs_test.go b/command/alloc_fs_test.go index 0e15b503471..d713a74b920 100644 --- a/command/alloc_fs_test.go +++ b/command/alloc_fs_test.go @@ -46,7 +46,7 @@ func TestFSCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/alloc_logs_test.go b/command/alloc_logs_test.go index 868a9cb9163..f567ae7bb0f 100644 --- a/command/alloc_logs_test.go +++ b/command/alloc_logs_test.go @@ -28,7 +28,7 @@ func TestLogsCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/alloc_status_test.go b/command/alloc_status_test.go index e30a3ff7cc5..65f3ee54cd2 100644 --- a/command/alloc_status_test.go +++ b/command/alloc_status_test.go @@ -34,7 +34,7 @@ func TestAllocStatusCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/deployment_fail_test.go b/command/deployment_fail_test.go index 2f5723d6fd8..e5d5047fc21 100644 --- a/command/deployment_fail_test.go +++ b/command/deployment_fail_test.go @@ -24,7 +24,7 @@ func TestDeploymentFailCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/deployment_list_test.go b/command/deployment_list_test.go index 291d837a534..66262579a6d 100644 --- a/command/deployment_list_test.go +++ b/command/deployment_list_test.go @@ -21,7 +21,7 @@ func TestDeploymentListCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/deployment_pause_test.go b/command/deployment_pause_test.go index 2917f65a2e7..7d89c7adf57 100644 --- a/command/deployment_pause_test.go +++ b/command/deployment_pause_test.go @@ -24,7 +24,7 @@ func TestDeploymentPauseCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/deployment_promote_test.go b/command/deployment_promote_test.go index 9d332d2a7be..aa7976c240b 100644 --- a/command/deployment_promote_test.go +++ b/command/deployment_promote_test.go @@ -24,7 +24,7 @@ func TestDeploymentPromoteCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/deployment_resume_test.go b/command/deployment_resume_test.go index b1e70bad6c7..1cac0518e1c 100644 --- a/command/deployment_resume_test.go +++ b/command/deployment_resume_test.go @@ -24,7 +24,7 @@ func TestDeploymentResumeCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/deployment_status_test.go b/command/deployment_status_test.go index 4023cfe1bf4..c2a1a0bd8d4 100644 --- a/command/deployment_status_test.go +++ b/command/deployment_status_test.go @@ -24,7 +24,7 @@ func TestDeploymentStatusCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/eval_status_test.go b/command/eval_status_test.go index 56e0eda51c1..c6f96579755 100644 --- a/command/eval_status_test.go +++ b/command/eval_status_test.go @@ -28,7 +28,7 @@ func TestEvalStatusCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_deployments_test.go b/command/job_deployments_test.go index c90565c73be..9cb40f056ee 100644 --- a/command/job_deployments_test.go +++ b/command/job_deployments_test.go @@ -24,7 +24,7 @@ func TestJobDeploymentsCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_dispatch_test.go b/command/job_dispatch_test.go index 3b59667c889..8034e6e7875 100644 --- a/command/job_dispatch_test.go +++ b/command/job_dispatch_test.go @@ -24,7 +24,7 @@ func TestJobDispatchCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_history_test.go b/command/job_history_test.go index 723cf31c39e..05088d519c6 100644 --- a/command/job_history_test.go +++ b/command/job_history_test.go @@ -24,7 +24,7 @@ func TestJobHistoryCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_init_test.go b/command/job_init_test.go index dba6618067c..d2f7617fced 100644 --- a/command/job_init_test.go +++ b/command/job_init_test.go @@ -23,7 +23,7 @@ func TestInitCommand_Run(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expect exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expect help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_inspect_test.go b/command/job_inspect_test.go index 43e6bb0a461..d369c7cfb7c 100644 --- a/command/job_inspect_test.go +++ b/command/job_inspect_test.go @@ -27,7 +27,7 @@ func TestInspectCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_plan_test.go b/command/job_plan_test.go index c9360de6d95..8efefcba627 100644 --- a/command/job_plan_test.go +++ b/command/job_plan_test.go @@ -30,7 +30,7 @@ func TestPlanCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 255 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_promote_test.go b/command/job_promote_test.go index d4160d41b7b..50ead0d0279 100644 --- a/command/job_promote_test.go +++ b/command/job_promote_test.go @@ -24,7 +24,7 @@ func TestJobPromoteCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_revert_test.go b/command/job_revert_test.go index 1e4d061f171..450df93f1ab 100644 --- a/command/job_revert_test.go +++ b/command/job_revert_test.go @@ -24,7 +24,7 @@ func TestJobRevertCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_run_test.go b/command/job_run_test.go index 1db113ddf3a..a1b1ed93d11 100644 --- a/command/job_run_test.go +++ b/command/job_run_test.go @@ -66,7 +66,7 @@ func TestRunCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_status_test.go b/command/job_status_test.go index 9f1d71adb48..84aa86c541d 100644 --- a/command/job_status_test.go +++ b/command/job_status_test.go @@ -194,7 +194,7 @@ func TestJobStatusCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_stop_test.go b/command/job_stop_test.go index 1389f537c75..528faf0ce99 100644 --- a/command/job_stop_test.go +++ b/command/job_stop_test.go @@ -27,7 +27,7 @@ func TestStopCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/job_validate_test.go b/command/job_validate_test.go index 516d317503a..25ef93efead 100644 --- a/command/job_validate_test.go +++ b/command/job_validate_test.go @@ -66,7 +66,7 @@ func TestValidateCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/namespace_apply_test.go b/command/namespace_apply_test.go index fe149f5cd81..a8d683065bc 100644 --- a/command/namespace_apply_test.go +++ b/command/namespace_apply_test.go @@ -24,7 +24,7 @@ func TestNamespaceApplyCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -32,7 +32,7 @@ func TestNamespaceApplyCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"-address=nope"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("name required error, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/namespace_delete_test.go b/command/namespace_delete_test.go index b22f9b5bbb6..6205904ddb4 100644 --- a/command/namespace_delete_test.go +++ b/command/namespace_delete_test.go @@ -26,7 +26,7 @@ func TestNamespaceDeleteCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/namespace_inspect_test.go b/command/namespace_inspect_test.go index 0e8b624fd68..6516dbb71b7 100644 --- a/command/namespace_inspect_test.go +++ b/command/namespace_inspect_test.go @@ -26,7 +26,7 @@ func TestNamespaceInspectCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/namespace_list_test.go b/command/namespace_list_test.go index 49b232a07e7..f2a11701fc8 100644 --- a/command/namespace_list_test.go +++ b/command/namespace_list_test.go @@ -23,7 +23,7 @@ func TestNamespaceListCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/namespace_status_test.go b/command/namespace_status_test.go index 1d188337d6d..229272893ae 100644 --- a/command/namespace_status_test.go +++ b/command/namespace_status_test.go @@ -26,7 +26,7 @@ func TestNamespaceStatusCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/node_config_test.go b/command/node_config_test.go index 8ddf3f44f42..31a845a569f 100644 --- a/command/node_config_test.go +++ b/command/node_config_test.go @@ -28,7 +28,7 @@ func TestClientConfigCommand_UpdateServers(t *testing.T) { if code != 1 { t.Fatalf("expected exit 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -55,7 +55,7 @@ func TestClientConfigCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -64,7 +64,7 @@ func TestClientConfigCommand_Fails(t *testing.T) { if code := cmd.Run([]string{}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/node_drain_test.go b/command/node_drain_test.go index 41cb69acff4..570c4368d95 100644 --- a/command/node_drain_test.go +++ b/command/node_drain_test.go @@ -251,7 +251,7 @@ func TestNodeDrainCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -278,7 +278,7 @@ func TestNodeDrainCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"-enable", "-disable", "12345678-abcd-efab-cdef-123456789abc"}); code != 1 { t.Fatalf("expected exit 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -287,7 +287,7 @@ func TestNodeDrainCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"12345678-abcd-efab-cdef-123456789abc"}); code != 1 { t.Fatalf("expected exit 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/node_eligibility_test.go b/command/node_eligibility_test.go index 6fbb3c91d8f..92d0b06a0a1 100644 --- a/command/node_eligibility_test.go +++ b/command/node_eligibility_test.go @@ -28,7 +28,7 @@ func TestNodeEligibilityCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -56,7 +56,7 @@ func TestNodeEligibilityCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"-enable", "-disable", "12345678-abcd-efab-cdef-123456789abc"}); code != 1 { t.Fatalf("expected exit 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -65,7 +65,7 @@ func TestNodeEligibilityCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"12345678-abcd-efab-cdef-123456789abc"}); code != 1 { t.Fatalf("expected exit 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/node_status_test.go b/command/node_status_test.go index 6f5ba357cec..0740317dc54 100644 --- a/command/node_status_test.go +++ b/command/node_status_test.go @@ -175,7 +175,7 @@ func TestNodeStatusCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/quota_apply_test.go b/command/quota_apply_test.go index a610723261e..d2211f0bf57 100644 --- a/command/quota_apply_test.go +++ b/command/quota_apply_test.go @@ -26,7 +26,7 @@ func TestQuotaApplyCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -34,7 +34,7 @@ func TestQuotaApplyCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"-address=nope"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("name required error, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/quota_delete_test.go b/command/quota_delete_test.go index c06e63a7d3a..254abc64c77 100644 --- a/command/quota_delete_test.go +++ b/command/quota_delete_test.go @@ -27,7 +27,7 @@ func TestQuotaDeleteCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/quota_init_test.go b/command/quota_init_test.go index 5001e711488..16e9c66567a 100644 --- a/command/quota_init_test.go +++ b/command/quota_init_test.go @@ -23,7 +23,7 @@ func TestQuotaInitCommand_Run_HCL(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expect exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expect help output, got: %s", out) } ui.ErrorWriter.Reset() @@ -75,7 +75,7 @@ func TestQuotaInitCommand_Run_JSON(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expect exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expect help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/quota_inspect_test.go b/command/quota_inspect_test.go index 39864fe65c0..79efc6bfc02 100644 --- a/command/quota_inspect_test.go +++ b/command/quota_inspect_test.go @@ -25,7 +25,7 @@ func TestQuotaInspectCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/quota_list_test.go b/command/quota_list_test.go index 4d1de2bdac4..6909dcbe598 100644 --- a/command/quota_list_test.go +++ b/command/quota_list_test.go @@ -24,7 +24,7 @@ func TestQuotaListCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/quota_status_test.go b/command/quota_status_test.go index 3b5c6a42e8b..5e71ab42125 100644 --- a/command/quota_status_test.go +++ b/command/quota_status_test.go @@ -25,7 +25,7 @@ func TestQuotaStatusCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() diff --git a/command/server_members_test.go b/command/server_members_test.go index e6ac296e682..f334ed121d1 100644 --- a/command/server_members_test.go +++ b/command/server_members_test.go @@ -55,7 +55,7 @@ func TestMembersCommand_Fails(t *testing.T) { if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 { t.Fatalf("expected exit code 1, got: %d", code) } - if out := ui.ErrorWriter.String(); !strings.Contains(out, cmd.Help()) { + if out := ui.ErrorWriter.String(); !strings.Contains(out, commandErrorText(cmd)) { t.Fatalf("expected help output, got: %s", out) } ui.ErrorWriter.Reset() From 0216a8e37748ac54c0af1ae05a0556012a5e3c6c Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Wed, 18 Apr 2018 13:55:51 -0400 Subject: [PATCH 4/5] command: use ':' instead of ',' in error msg --- command/acl_policy_apply.go | 2 +- command/acl_policy_delete.go | 2 +- command/acl_policy_info.go | 2 +- command/acl_token_delete.go | 2 +- command/acl_token_info.go | 2 +- command/acl_token_update.go | 2 +- command/alloc_fs.go | 2 +- command/deployment_pause.go | 2 +- command/deployment_promote.go | 2 +- command/deployment_resume.go | 2 +- command/deployment_status.go | 2 +- command/job_deployments.go | 2 +- command/job_dispatch.go | 2 +- command/job_history.go | 2 +- command/job_inspect.go | 2 +- command/job_plan.go | 2 +- command/job_promote.go | 2 +- command/job_revert.go | 2 +- command/job_run.go | 2 +- command/job_status.go | 2 +- command/job_stop.go | 2 +- command/job_validate.go | 2 +- command/namespace_apply.go | 2 +- command/namespace_delete.go | 2 +- command/namespace_inspect.go | 2 +- command/namespace_status.go | 2 +- command/quota_apply.go | 2 +- command/quota_delete.go | 2 +- command/quota_inspect.go | 2 +- command/quota_status.go | 2 +- command/sentinel_apply.go | 2 +- command/sentinel_delete.go | 2 +- command/sentinel_read.go | 2 +- command/server_force_leave.go | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) diff --git a/command/acl_policy_apply.go b/command/acl_policy_apply.go index 6133ae046bd..6b9e4718697 100644 --- a/command/acl_policy_apply.go +++ b/command/acl_policy_apply.go @@ -61,7 +61,7 @@ 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("This command takes two arguments, and ") + c.Ui.Error("This command takes two arguments: and ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_policy_delete.go b/command/acl_policy_delete.go index e09d27e0a4b..49b7c47e993 100644 --- a/command/acl_policy_delete.go +++ b/command/acl_policy_delete.go @@ -49,7 +49,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_policy_info.go b/command/acl_policy_info.go index 0d0fcf38680..a4e7403bab8 100644 --- a/command/acl_policy_info.go +++ b/command/acl_policy_info.go @@ -49,7 +49,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_token_delete.go b/command/acl_token_delete.go index ed56236d137..2184a4e3dd3 100644 --- a/command/acl_token_delete.go +++ b/command/acl_token_delete.go @@ -51,7 +51,7 @@ func (c *ACLTokenDeleteCommand) Run(args []string) int { // such token was provided. args = flags.Args() if l := len(args); l != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_token_info.go b/command/acl_token_info.go index 87c76a18d2c..4525d41732d 100644 --- a/command/acl_token_info.go +++ b/command/acl_token_info.go @@ -49,7 +49,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/acl_token_update.go b/command/acl_token_update.go index 47eb158ba14..45db1a0b771 100644 --- a/command/acl_token_update.go +++ b/command/acl_token_update.go @@ -80,7 +80,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/alloc_fs.go b/command/alloc_fs.go index 69ed15c20b8..3802952246b 100644 --- a/command/alloc_fs.go +++ b/command/alloc_fs.go @@ -142,7 +142,7 @@ func (f *AllocFSCommand) Run(args []string) int { } if len(args) > 2 { - f.Ui.Error("This command takes one or two arguments, []") + f.Ui.Error("This command takes one or two arguments: []") f.Ui.Error(commandErrorText(f)) return 1 } diff --git a/command/deployment_pause.go b/command/deployment_pause.go index 62600e12b73..9dee40d2070 100644 --- a/command/deployment_pause.go +++ b/command/deployment_pause.go @@ -73,7 +73,7 @@ func (c *DeploymentPauseCommand) Run(args []string) int { // Check that we got exactly 1 argument args = flags.Args() if l := len(args); l != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/deployment_promote.go b/command/deployment_promote.go index 05389360a39..2b8bdb64433 100644 --- a/command/deployment_promote.go +++ b/command/deployment_promote.go @@ -94,7 +94,7 @@ func (c *DeploymentPromoteCommand) Run(args []string) int { // Check that we got exactly one argument args = flags.Args() if l := len(args); l != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/deployment_resume.go b/command/deployment_resume.go index 316ac3475ed..79c2e1a1629 100644 --- a/command/deployment_resume.go +++ b/command/deployment_resume.go @@ -79,7 +79,7 @@ func (c *DeploymentResumeCommand) Run(args []string) int { // Check that we got exactly one argument args = flags.Args() if l := len(args); l != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/deployment_status.go b/command/deployment_status.go index 053445ab19f..5380ea3107f 100644 --- a/command/deployment_status.go +++ b/command/deployment_status.go @@ -86,7 +86,7 @@ func (c *DeploymentStatusCommand) Run(args []string) int { // Check that we got exactly one argument args = flags.Args() if l := len(args); l != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_deployments.go b/command/job_deployments.go index 6d52ed0dbd3..b099a305cee 100644 --- a/command/job_deployments.go +++ b/command/job_deployments.go @@ -88,7 +88,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_dispatch.go b/command/job_dispatch.go index 7dcf2a7f633..4a768592833 100644 --- a/command/job_dispatch.go +++ b/command/job_dispatch.go @@ -105,7 +105,7 @@ func (c *JobDispatchCommand) Run(args []string) int { // Check that we got exactly one node args = flags.Args() if l := len(args); l != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_history.go b/command/job_history.go index 0e2600bf661..0d759f6a7c2 100644 --- a/command/job_history.go +++ b/command/job_history.go @@ -101,7 +101,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_inspect.go b/command/job_inspect.go index a5ec0d5b0b4..c95a9e247ea 100644 --- a/command/job_inspect.go +++ b/command/job_inspect.go @@ -110,7 +110,7 @@ func (c *JobInspectCommand) Run(args []string) int { // Check that we got exactly one job if len(args) != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_plan.go b/command/job_plan.go index 6ae7079d07f..5625f9fe4da 100644 --- a/command/job_plan.go +++ b/command/job_plan.go @@ -110,7 +110,7 @@ func (c *JobPlanCommand) Run(args []string) int { // Check that we got exactly one job args = flags.Args() if len(args) != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 255 } diff --git a/command/job_promote.go b/command/job_promote.go index ff51fd96afb..fe5426733be 100644 --- a/command/job_promote.go +++ b/command/job_promote.go @@ -95,7 +95,7 @@ func (c *JobPromoteCommand) Run(args []string) int { // Check that we got exactly one argument args = flags.Args() if l := len(args); l != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_revert.go b/command/job_revert.go index 283028237b5..9893333bfd0 100644 --- a/command/job_revert.go +++ b/command/job_revert.go @@ -86,7 +86,7 @@ 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("This command takes two arguments, ") + c.Ui.Error("This command takes two arguments: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_run.go b/command/job_run.go index 1cffead115f..7f17decd518 100644 --- a/command/job_run.go +++ b/command/job_run.go @@ -142,7 +142,7 @@ func (c *JobRunCommand) Run(args []string) int { // Check that we got exactly one argument args = flags.Args() if len(args) != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_status.go b/command/job_status.go index ae2d3a981cf..af7d18af9ca 100644 --- a/command/job_status.go +++ b/command/job_status.go @@ -104,7 +104,7 @@ 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("This command takes either no arguments or one, ") + c.Ui.Error("This command takes either no arguments or one: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_stop.go b/command/job_stop.go index a1d9fe7da7f..9f05e0d9055 100644 --- a/command/job_stop.go +++ b/command/job_stop.go @@ -102,7 +102,7 @@ func (c *JobStopCommand) Run(args []string) int { // Check that we got exactly one job args = flags.Args() if len(args) != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/job_validate.go b/command/job_validate.go index 0b6f4bdac91..49c4c11089e 100644 --- a/command/job_validate.go +++ b/command/job_validate.go @@ -55,7 +55,7 @@ func (c *JobValidateCommand) Run(args []string) int { // Check that we got exactly one node args = flags.Args() if len(args) != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/namespace_apply.go b/command/namespace_apply.go index be22951e689..e22cd28c3d4 100644 --- a/command/namespace_apply.go +++ b/command/namespace_apply.go @@ -74,7 +74,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/namespace_delete.go b/command/namespace_delete.go index 78088924379..0c1f7d4b1d4 100644 --- a/command/namespace_delete.go +++ b/command/namespace_delete.go @@ -50,7 +50,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/namespace_inspect.go b/command/namespace_inspect.go index 444e287e7bf..994e3e971b2 100644 --- a/command/namespace_inspect.go +++ b/command/namespace_inspect.go @@ -60,7 +60,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/namespace_status.go b/command/namespace_status.go index 6e45f344e20..ef47260eda8 100644 --- a/command/namespace_status.go +++ b/command/namespace_status.go @@ -50,7 +50,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/quota_apply.go b/command/quota_apply.go index 4e0ab33040f..0dee1519dd6 100644 --- a/command/quota_apply.go +++ b/command/quota_apply.go @@ -72,7 +72,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/quota_delete.go b/command/quota_delete.go index b87e3c73933..439c9a0d540 100644 --- a/command/quota_delete.go +++ b/command/quota_delete.go @@ -49,7 +49,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/quota_inspect.go b/command/quota_inspect.go index 442890671dd..f07f0a6396b 100644 --- a/command/quota_inspect.go +++ b/command/quota_inspect.go @@ -67,7 +67,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/quota_status.go b/command/quota_status.go index ab812cb1fe1..6c7805e3fdb 100644 --- a/command/quota_status.go +++ b/command/quota_status.go @@ -53,7 +53,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/sentinel_apply.go b/command/sentinel_apply.go index cd0c409f4b2..b810247070c 100644 --- a/command/sentinel_apply.go +++ b/command/sentinel_apply.go @@ -76,7 +76,7 @@ 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("This command takes exactly two arguments, ") + c.Ui.Error("This command takes exactly two arguments: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/sentinel_delete.go b/command/sentinel_delete.go index 55620795592..643054564d3 100644 --- a/command/sentinel_delete.go +++ b/command/sentinel_delete.go @@ -50,7 +50,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/sentinel_read.go b/command/sentinel_read.go index 8ee07205733..32d5f741eb7 100644 --- a/command/sentinel_read.go +++ b/command/sentinel_read.go @@ -59,7 +59,7 @@ 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("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } diff --git a/command/server_force_leave.go b/command/server_force_leave.go index 0b56a0f79ef..3976dd4e459 100644 --- a/command/server_force_leave.go +++ b/command/server_force_leave.go @@ -40,7 +40,7 @@ func (c *ServerForceLeaveCommand) Run(args []string) int { // Check that we got exactly one node args = flags.Args() if len(args) != 1 { - c.Ui.Error("This command takes one argument, ") + c.Ui.Error("This command takes one argument: ") c.Ui.Error(commandErrorText(c)) return 1 } From f1364fbbad0aaa05fd5d684d6474593d6cfdc5f7 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Wed, 18 Apr 2018 21:21:43 -0400 Subject: [PATCH 5/5] command: fix job dispatch arg check --- command/job_dispatch.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command/job_dispatch.go b/command/job_dispatch.go index 4a768592833..ed338868597 100644 --- a/command/job_dispatch.go +++ b/command/job_dispatch.go @@ -102,10 +102,10 @@ func (c *JobDispatchCommand) Run(args []string) int { length = fullId } - // Check that we got exactly one node + // Check that we got one or two arguments args = flags.Args() - if l := len(args); l != 1 { - c.Ui.Error("This command takes one argument: ") + if l := len(args); l < 1 || l > 2 { + c.Ui.Error("This command takes one or two argument: [input source]") c.Ui.Error(commandErrorText(c)) return 1 }