diff --git a/command/commands.go b/command/commands.go index 2c72c981df..3f5cb8f4a2 100644 --- a/command/commands.go +++ b/command/commands.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/consul/command/info" "github.com/hashicorp/consul/command/join" "github.com/hashicorp/consul/command/keygen" + "github.com/hashicorp/consul/command/kv" "github.com/hashicorp/consul/command/validate" "github.com/hashicorp/consul/version" "github.com/mitchellh/cli" @@ -114,12 +115,7 @@ func init() { }, "kv": func() (cli.Command, error) { - return &KVCommand{ - BaseCommand: BaseCommand{ - Flags: FlagSetNone, - UI: ui, - }, - }, nil + return kv.New(), nil }, "kv delete": func() (cli.Command, error) { diff --git a/command/kv_command.go b/command/kv/kv.go similarity index 66% rename from command/kv_command.go rename to command/kv/kv.go index 82bc2676da..a1a9afa998 100644 --- a/command/kv_command.go +++ b/command/kv/kv.go @@ -1,23 +1,26 @@ -package command +package kv import ( + "github.com/hashicorp/consul/command/flags" "github.com/mitchellh/cli" ) -// KVCommand is a Command implementation that just shows help for -// the subcommands nested below it. -type KVCommand struct { - BaseCommand +func New() *cmd { + return &cmd{} } -func (c *KVCommand) Run(args []string) int { +type cmd struct{} + +func (c *cmd) Run(args []string) int { return cli.RunResultHelp } -func (c *KVCommand) Help() string { - c.InitFlagSet() - return c.HelpCommand(` -Usage: consul kv [options] [args] +func (c *cmd) Synopsis() string { + return "Interact with the key-value store" +} + +func (c *cmd) Help() string { + s := `Usage: consul kv [options] [args] This command has subcommands for interacting with Consul's key-value store. Here are some simple examples, and more detailed examples are @@ -39,11 +42,6 @@ Usage: consul kv [options] [args] $ consul kv delete redis/config/connections - For more examples, ask for subcommand help or view the documentation. - -`) -} - -func (c *KVCommand) Synopsis() string { - return "Interact with the key-value store" + For more examples, ask for subcommand help or view the documentation.` + return flags.Usage(s, nil, nil, nil) } diff --git a/command/kv/kv_test.go b/command/kv/kv_test.go new file mode 100644 index 0000000000..1d833a6784 --- /dev/null +++ b/command/kv/kv_test.go @@ -0,0 +1,12 @@ +package kv + +import ( + "strings" + "testing" +) + +func TestKVCommand_noTabs(t *testing.T) { + if strings.ContainsRune(New().Help(), '\t') { + t.Fatal("usage has tabs") + } +} diff --git a/command/kv_command_test.go b/command/kv_command_test.go deleted file mode 100644 index 8162eb85ce..0000000000 --- a/command/kv_command_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package command - -import ( - "testing" - - "github.com/mitchellh/cli" -) - -func TestKVCommand_implements(t *testing.T) { - t.Parallel() - var _ cli.Command = &KVCommand{} -} - -func TestKVCommand_noTabs(t *testing.T) { - t.Parallel() - assertNoTabs(t, new(KVCommand)) -}