commands: move kv command to separate pkg

This commit is contained in:
Frank Schroeder 2017-10-11 14:51:25 +02:00 committed by Frank Schröder
parent aca803ca8d
commit 200199a875
4 changed files with 29 additions and 40 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/hashicorp/consul/command/info" "github.com/hashicorp/consul/command/info"
"github.com/hashicorp/consul/command/join" "github.com/hashicorp/consul/command/join"
"github.com/hashicorp/consul/command/keygen" "github.com/hashicorp/consul/command/keygen"
"github.com/hashicorp/consul/command/kv"
"github.com/hashicorp/consul/command/validate" "github.com/hashicorp/consul/command/validate"
"github.com/hashicorp/consul/version" "github.com/hashicorp/consul/version"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
@ -114,12 +115,7 @@ func init() {
}, },
"kv": func() (cli.Command, error) { "kv": func() (cli.Command, error) {
return &KVCommand{ return kv.New(), nil
BaseCommand: BaseCommand{
Flags: FlagSetNone,
UI: ui,
},
}, nil
}, },
"kv delete": func() (cli.Command, error) { "kv delete": func() (cli.Command, error) {

View File

@ -1,23 +1,26 @@
package command package kv
import ( import (
"github.com/hashicorp/consul/command/flags"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
) )
// KVCommand is a Command implementation that just shows help for func New() *cmd {
// the subcommands nested below it. return &cmd{}
type KVCommand struct {
BaseCommand
} }
func (c *KVCommand) Run(args []string) int { type cmd struct{}
func (c *cmd) Run(args []string) int {
return cli.RunResultHelp return cli.RunResultHelp
} }
func (c *KVCommand) Help() string { func (c *cmd) Synopsis() string {
c.InitFlagSet() return "Interact with the key-value store"
return c.HelpCommand(` }
Usage: consul kv <subcommand> [options] [args]
func (c *cmd) Help() string {
s := `Usage: consul kv <subcommand> [options] [args]
This command has subcommands for interacting with Consul's key-value This command has subcommands for interacting with Consul's key-value
store. Here are some simple examples, and more detailed examples are store. Here are some simple examples, and more detailed examples are
@ -39,11 +42,6 @@ Usage: consul kv <subcommand> [options] [args]
$ consul kv delete redis/config/connections $ consul kv delete redis/config/connections
For more examples, ask for subcommand help or view the documentation. For more examples, ask for subcommand help or view the documentation.`
return flags.Usage(s, nil, nil, nil)
`)
}
func (c *KVCommand) Synopsis() string {
return "Interact with the key-value store"
} }

12
command/kv/kv_test.go Normal file
View File

@ -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")
}
}

View File

@ -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))
}