From 0f611572cc558da87e377e5af29d5f6ff6ac065a Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Mon, 8 Sep 2014 21:45:15 -0700 Subject: [PATCH] command/keys: fail fast if no actionable args were passed --- command/keys.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/command/keys.go b/command/keys.go index 069af85661..0373804cf7 100644 --- a/command/keys.go +++ b/command/keys.go @@ -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 {