Fix up info and forceleave to build help string in constructor

This commit is contained in:
Preetha Appan 2017-10-11 16:44:01 -05:00 committed by Frank Schröder
parent 95053297a9
commit 0e1ee70a5e
2 changed files with 16 additions and 12 deletions

View File

@ -10,7 +10,7 @@ import (
func New(ui cli.Ui) *cmd { func New(ui cli.Ui) *cmd {
c := &cmd{UI: ui} c := &cmd{UI: ui}
c.initFlags() c.init()
return c return c
} }
@ -18,13 +18,15 @@ type cmd struct {
UI cli.Ui UI cli.Ui
flags *flag.FlagSet flags *flag.FlagSet
http *flags.HTTPFlags http *flags.HTTPFlags
usage string
} }
func (c *cmd) initFlags() { func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError) c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.http = &flags.HTTPFlags{} c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags()) flags.Merge(c.flags, c.http.ClientFlags())
flags.Merge(c.flags, c.http.ServerFlags()) 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 { func (c *cmd) Run(args []string) int {
@ -60,7 +62,10 @@ func (c *cmd) Synopsis() string {
} }
func (c *cmd) Help() string { func (c *cmd) Help() string {
s := `Usage: consul force-leave [options] name return c.usage
}
const usage = `Usage: consul force-leave [options] name
Forces a member of a Consul cluster to enter the "left" state. Note Forces a member of a Consul cluster to enter the "left" state. Note
that if the member is still actually alive, it will eventually rejoin that if the member is still actually alive, it will eventually rejoin
@ -68,6 +73,3 @@ func (c *cmd) Help() string {
that are never coming back. If you do not force leave a failed node, that are never coming back. If you do not force leave a failed node,
Consul will attempt to reconnect to those failed nodes for some period of Consul will attempt to reconnect to those failed nodes for some period of
time before eventually reaping them.` time before eventually reaping them.`
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 { func New(ui cli.Ui) *cmd {
c := &cmd{UI: ui} c := &cmd{UI: ui}
c.initFlags() c.init()
return c return c
} }
@ -19,12 +19,14 @@ type cmd struct {
UI cli.Ui UI cli.Ui
flags *flag.FlagSet flags *flag.FlagSet
http *flags.HTTPFlags http *flags.HTTPFlags
usage string
} }
func (c *cmd) initFlags() { func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError) c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.http = &flags.HTTPFlags{} c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags()) 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 { func (c *cmd) Run(args []string) int {
@ -86,9 +88,9 @@ func (c *cmd) Synopsis() string {
} }
func (c *cmd) Help() string { func (c *cmd) Help() string {
s := `Usage: consul info [options] return c.usage
}
const usage = `Usage: consul info [options]
Provides debugging information for operators` Provides debugging information for operators`
return flags.Usage(s, c.flags, c.http.ClientFlags(), nil)
}