From e1935590b1efab8b2384ba32c9c511e979da9643 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Wed, 11 Oct 2017 17:32:35 -0500 Subject: [PATCH] Fix leave and validate commands to build help string in constructor --- command/leave/leave.go | 14 ++++++++------ command/validate/validate.go | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/command/leave/leave.go b/command/leave/leave.go index 3d53abd4b..3868d68e3 100644 --- a/command/leave/leave.go +++ b/command/leave/leave.go @@ -10,7 +10,7 @@ import ( func New(ui cli.Ui) *cmd { c := &cmd{UI: ui} - c.initFlags() + c.init() return c } @@ -18,13 +18,15 @@ type cmd struct { UI cli.Ui flags *flag.FlagSet http *flags.HTTPFlags + usage string } -func (c *cmd) initFlags() { +func (c *cmd) init() { c.flags = flag.NewFlagSet("", flag.ContinueOnError) 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 { @@ -58,9 +60,9 @@ func (c *cmd) Synopsis() string { } func (c *cmd) Help() string { - s := `Usage: consul leave [options] + return c.usage +} + +const usage = `Usage: consul leave [options] Causes the agent to gracefully leave the Consul cluster and shutdown.` - - return flags.Usage(s, c.flags, c.http.ClientFlags(), c.http.ServerFlags()) -} diff --git a/command/validate/validate.go b/command/validate/validate.go index c94d0500f..e489be015 100644 --- a/command/validate/validate.go +++ b/command/validate/validate.go @@ -11,7 +11,7 @@ import ( func New(ui cli.Ui) *cmd { c := &cmd{UI: ui} - c.initFlags() + c.init() return c } @@ -19,12 +19,14 @@ type cmd struct { UI cli.Ui flags *flag.FlagSet quiet bool + usage string } -func (c *cmd) initFlags() { +func (c *cmd) init() { c.flags = flag.NewFlagSet("", flag.ContinueOnError) c.flags.BoolVar(&c.quiet, "quiet", false, "When given, a successful run will produce no output.") + c.usage = flags.Usage(usage, c.flags, nil, nil) } func (c *cmd) Run(args []string) int { @@ -58,7 +60,10 @@ func (c *cmd) Synopsis() string { } func (c *cmd) Help() string { - s := `Usage: consul validate [options] FILE_OR_DIRECTORY... + return c.usage +} + +const usage = `Usage: consul validate [options] FILE_OR_DIRECTORY... Performs a basic sanity test on Consul configuration files. For each file or directory given, the validate command will attempt to parse the @@ -67,6 +72,3 @@ func (c *cmd) Help() string { starting the agent. Returns 0 if the configuration is valid, or 1 if there are problems.` - - return flags.Usage(s, c.flags, nil, nil) -}