Fix up catalog list services to build help string in constructor

This commit is contained in:
Preetha Appan 2017-10-11 16:15:53 -05:00 committed by Frank Schröder
parent 8761232b2a
commit 3bd4b738c0
1 changed files with 6 additions and 4 deletions

View File

@ -23,6 +23,7 @@ type cmd struct {
UI cli.Ui UI cli.Ui
flags *flag.FlagSet flags *flag.FlagSet
http *flags.HTTPFlags http *flags.HTTPFlags
usage string
// flags // flags
node string node string
@ -45,10 +46,10 @@ func (c *cmd) initFlags() {
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 {
c.initFlags()
if err := c.flags.Parse(args); err != nil { if err := c.flags.Parse(args); err != nil {
return 1 return 1
} }
@ -129,7 +130,10 @@ func (c *cmd) Synopsis() string {
} }
func (c *cmd) Help() string { func (c *cmd) Help() string {
s := `Usage: consul catalog services [options] return c.usage
}
const usage = `Usage: consul catalog services [options]
Retrieves the list services registered in a given datacenter. By default, the Retrieves the list services registered in a given datacenter. By default, the
datacenter of the local agent is queried. datacenter of the local agent is queried.
@ -151,5 +155,3 @@ func (c *cmd) Help() string {
$ consul catalog services -node-meta="foo=bar" $ consul catalog services -node-meta="foo=bar"
For a full list of options and examples, please see the Consul documentation.` For a full list of options and examples, please see the Consul documentation.`
return flags.Usage(s, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
}