Fix leave and validate commands to build help string in constructor
This commit is contained in:
parent
3c4363389e
commit
e1935590b1
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue