From 0cb1c92977ccc58d99102358cdb0fea2f9d965d5 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Wed, 11 Oct 2017 16:31:53 -0500 Subject: [PATCH] Fix exec and event commands to build help string in constructor --- command/event/event.go | 10 ++++++---- command/exec/exec.go | 17 ++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/command/event/event.go b/command/event/event.go index b368b4d21..e4efadbdf 100644 --- a/command/event/event.go +++ b/command/event/event.go @@ -24,6 +24,7 @@ type cmd struct { node string service string tag string + usage string } func (c *cmd) initFlags() { @@ -39,6 +40,7 @@ func (c *cmd) initFlags() { c.http = &flags.HTTPFlags{} flags.Merge(c.flags, c.http.ClientFlags()) + c.usage = flags.Usage(usage, c.flags, c.http.ClientFlags(), nil) } func (c *cmd) Run(args []string) int { @@ -131,11 +133,11 @@ func (c *cmd) Synopsis() string { } func (c *cmd) Help() string { - s := `Usage: consul event [options] [payload] + return c.usage +} + +const usage = `Usage: consul event [options] [payload] Dispatches a custom user event across a datacenter. An event must provide a name, but a payload is optional. Events support filtering using regular expressions on node name, service, and tag definitions.` - - return flags.Usage(s, c.flags, c.http.ClientFlags(), nil) -} diff --git a/command/exec/exec.go b/command/exec/exec.go index dd54a2a1f..5b5315f9c 100644 --- a/command/exec/exec.go +++ b/command/exec/exec.go @@ -29,6 +29,7 @@ type cmd struct { UI cli.Ui flags *flag.FlagSet http *flags.HTTPFlags + usage string shutdownCh <-chan struct{} conf rExecConf @@ -59,6 +60,7 @@ func (c *cmd) initFlags() { c.http = &flags.HTTPFlags{} flags.Merge(c.flags, c.http.ClientFlags()) flags.Merge(c.flags, c.http.ServerFlags()) + c.usage = flags.Usage(usage, c.flags, c.http.ClientFlags(), c.http.ServerFlags()) } func (c *cmd) Run(args []string) int { @@ -185,13 +187,7 @@ func (c *cmd) Synopsis() string { } func (c *cmd) Help() string { - s := `Usage: consul exec [options] [-|command...] - - Evaluates a command on remote Consul nodes. The nodes responding can - be filtered using regular expressions on node name, service, and tag - definitions. If a command is '-', stdin will be read until EOF - and used as a script input. ` - return flags.Usage(s, c.flags, c.http.ClientFlags(), c.http.ServerFlags()) + return c.usage } // waitForJob is used to poll for results and wait until the job is terminated @@ -689,3 +685,10 @@ func (u *TargetedUI) prefixLines(arrow bool, message string) string { return strings.TrimRightFunc(result.String(), unicode.IsSpace) } + +const usage = `Usage: consul exec [options] [-|command...] + + Evaluates a command on remote Consul nodes. The nodes responding can + be filtered using regular expressions on node name, service, and tag + definitions. If a command is '-', stdin will be read until EOF + and used as a script input. `