Fix Keyring and keygen commands to build help string in constructor

This commit is contained in:
Preetha Appan 2017-10-11 17:02:31 -05:00 committed by Frank Schröder
parent b8dd539037
commit 75ec8a29a3
2 changed files with 16 additions and 11 deletions

View File

@ -12,17 +12,19 @@ import (
func New(ui cli.Ui) *cmd {
c := &cmd{UI: ui}
c.initFlags()
c.init()
return c
}
type cmd struct {
UI cli.Ui
flags *flag.FlagSet
usage string
}
func (c *cmd) initFlags() {
func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.usage = flags.Usage(usage, c.flags, nil, nil)
}
func (c *cmd) Run(args []string) int {
@ -50,11 +52,11 @@ func (c *cmd) Synopsis() string {
}
func (c *cmd) Help() string {
s := `Usage: consul keygen
return c.usage
}
const usage = `Usage: consul keygen
Generates a new encryption key that can be used to configure the
agent to encrypt traffic. The output of this command is already
in the proper format that the agent expects.`
return flags.Usage(s, c.flags, nil, nil)
}

View File

@ -12,7 +12,7 @@ import (
func New(ui cli.Ui) *cmd {
c := &cmd{UI: ui}
c.initFlags()
c.init()
return c
}
@ -20,6 +20,7 @@ type cmd struct {
UI cli.Ui
flags *flag.FlagSet
http *flags.HTTPFlags
usage string
// flags
installKey string
@ -29,7 +30,7 @@ type cmd struct {
relay int
}
func (c *cmd) initFlags() {
func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.flags.StringVar(&c.installKey, "install", "",
"Install a new encryption key. This will broadcast the new key to "+
@ -51,6 +52,7 @@ func (c *cmd) initFlags() {
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 {
@ -164,7 +166,10 @@ func (c *cmd) Synopsis() string {
}
func (c *cmd) Help() string {
s := `Usage: consul keyring [options]
return c.usage
}
const usage = `Usage: consul keyring [options]
Manages encryption keys used for gossip messages. Gossip encryption is
optional. When enabled, this command may be used to examine active encryption
@ -178,5 +183,3 @@ func (c *cmd) Help() string {
All variations of the keyring command return 0 if all nodes reply and there
are no errors. If any node fails to reply or reports failure, the exit code
will be 1.`
return flags.Usage(s, c.flags, c.http.ClientFlags(), c.http.ServerFlags())
}