diff --git a/command/kv_command.go b/command/kv_command.go new file mode 100644 index 000000000..28bd71a94 --- /dev/null +++ b/command/kv_command.go @@ -0,0 +1,76 @@ +package command + +import ( + "strings" + + "github.com/mitchellh/cli" +) + +// KVCommand is a Command implementation that just shows help for +// the subcommands nested below it. +type KVCommand struct { + Ui cli.Ui +} + +func (c *KVCommand) Run(args []string) int { + return cli.RunResultHelp +} + +func (c *KVCommand) Help() string { + helpText := ` +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 + available in the subcommands or the documentation. + + Create or update the key named "redis/config/connections" with the value "5": + + $ consul kv put redis/config/connections 5 + + Read this value back: + + $ consul kv get redis/config/connections + + Or get detailed key information: + + $ consul kv get -detailed redis/config/connections + + Finally, delete the key: + + $ consul kv delete redis/config/connections + + For more examples, ask for subcommand help or view the documentation. + +` + return strings.TrimSpace(helpText) +} + +func (c *KVCommand) Synopsis() string { + return "Interact with the key-value store" +} + +var apiOptsText = strings.TrimSpace(` +API Options: + + -http-addr= Address of the Consul agent with the port. This can + be an IP address or DNS address, but it must include + the port. This can also be specified via the + CONSUL_HTTP_ADDR environment variable. The default + value is 127.0.0.1:8500. + + -datacenter= Name of the datacenter to query. If unspecified, the + query will default to the datacenter of the Consul + agent at the HTTP address. + + -token= ACL token to use in the request. This can also be + specified via the CONSUL_HTTP_TOKEN environment + variable. If unspecified, the query will default to + the token of the Consul agent at the HTTP address. + + -stale Permit any Consul server (non-leader) to respond to + this request. This allows for lower latency and higher + throughput, but can result in stale data. This option + has no effect on non-read operations. The default + value is false. +`) diff --git a/command/kv_command_test.go b/command/kv_command_test.go new file mode 100644 index 000000000..950938108 --- /dev/null +++ b/command/kv_command_test.go @@ -0,0 +1,15 @@ +package command + +import ( + "testing" + + "github.com/mitchellh/cli" +) + +func TestKVCommand_implements(t *testing.T) { + var _ cli.Command = &KVCommand{} +} + +func TestKVCommand_noTabs(t *testing.T) { + assertNoTabs(t, new(KVCommand)) +} diff --git a/command/util_test.go b/command/util_test.go index e06492aa0..faf0377bc 100644 --- a/command/util_test.go +++ b/command/util_test.go @@ -7,6 +7,7 @@ import ( "math/rand" "net" "os" + "strings" "sync/atomic" "testing" "time" @@ -14,6 +15,7 @@ import ( "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/command/agent" "github.com/hashicorp/consul/consul" + "github.com/mitchellh/cli" ) var offset uint64 @@ -137,3 +139,9 @@ func nextConfig() *agent.Config { return conf } + +func assertNoTabs(t *testing.T, c cli.Command) { + if strings.ContainsRune(c.Help(), '\t') { + t.Errorf("%#v help output contains tabs", c) + } +} diff --git a/commands.go b/commands.go index 2a25c77f8..691ac8de6 100644 --- a/commands.go +++ b/commands.go @@ -53,6 +53,12 @@ func init() { }, nil }, + "kv": func() (cli.Command, error) { + return &command.KVCommand{ + Ui: ui, + }, nil + }, + "join": func() (cli.Command, error) { return &command.JoinCommand{ Ui: ui,