command/keys: fail fast if no actionable args were passed

This commit is contained in:
Ryan Uber 2014-09-08 21:45:15 -07:00
parent e4251a3372
commit 0f611572cc
1 changed files with 15 additions and 9 deletions

View File

@ -33,13 +33,6 @@ func (c *KeysCommand) Run(args []string) int {
return 1
}
client, err := RPCClient(*rpcAddr)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
return 1
}
defer client.Close()
// Only accept a single argument
found := listKeys
for _, arg := range []string{installKey, useKey, removeKey} {
@ -50,6 +43,19 @@ func (c *KeysCommand) Run(args []string) int {
found = found || len(arg) > 0
}
// Fail fast if no actionable args were passed
if !found {
c.Ui.Error(c.Help())
return 1
}
client, err := RPCClient(*rpcAddr)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
return 1
}
defer client.Close()
if listKeys {
var keys map[string]int
var numNodes int
@ -96,8 +102,8 @@ func (c *KeysCommand) Run(args []string) int {
return 0
}
c.Ui.Output(c.Help())
return 1
// Should never make it here
return 0
}
func (c *KeysCommand) Help() string {