Fix leave and validate commands to build help string in constructor

This commit is contained in:
Preetha Appan 2017-10-11 17:32:35 -05:00 committed by Frank Schröder
parent 3c4363389e
commit e1935590b1
2 changed files with 16 additions and 12 deletions

View File

@ -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())
}

View File

@ -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)
}