From fe84af448b940610523c3a85af6c121b8c3c2463 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Tue, 17 Oct 2017 07:58:03 +0200 Subject: [PATCH] commands: move operator command to separate pkg --- command/commands.go | 8 ++------ command/{ => oper}/operator.go | 36 +++++++++++++++------------------- command/oper/operator_test.go | 13 ++++++++++++ command/operator_test.go | 12 ------------ 4 files changed, 31 insertions(+), 38 deletions(-) rename command/{ => oper}/operator.go (59%) create mode 100644 command/oper/operator_test.go delete mode 100644 command/operator_test.go diff --git a/command/commands.go b/command/commands.go index e18ab9787..cd2787ae1 100644 --- a/command/commands.go +++ b/command/commands.go @@ -27,6 +27,7 @@ import ( "github.com/hashicorp/consul/command/maint" "github.com/hashicorp/consul/command/members" "github.com/hashicorp/consul/command/monitor" + "github.com/hashicorp/consul/command/oper" "github.com/hashicorp/consul/command/validate" "github.com/hashicorp/consul/version" "github.com/mitchellh/cli" @@ -142,12 +143,7 @@ func init() { }, "operator": func() (cli.Command, error) { - return &OperatorCommand{ - BaseCommand: BaseCommand{ - Flags: FlagSetNone, - UI: ui, - }, - }, nil + return oper.New(), nil }, "operator autopilot": func() (cli.Command, error) { diff --git a/command/operator.go b/command/oper/operator.go similarity index 59% rename from command/operator.go rename to command/oper/operator.go index 1272d7898..4c1fbb584 100644 --- a/command/operator.go +++ b/command/oper/operator.go @@ -1,20 +1,25 @@ -package command +package oper import ( - "strings" - "github.com/mitchellh/cli" ) -// OperatorCommand is used to provide various low-level tools for Consul -// operators. -type OperatorCommand struct { - BaseCommand +func New() *cmd { + return &cmd{} } -func (c *OperatorCommand) Help() string { - helpText := ` -Usage: consul operator [options] +type cmd struct{} + +func (c *cmd) Run(args []string) int { + return cli.RunResultHelp +} + +func (c *cmd) Synopsis() string { + return "Provides cluster-level tools for Consul operators" +} + +func (c *cmd) Help() string { + s := `Usage: consul operator [options] Provides cluster-level tools for Consul operators, such as interacting with the Raft subsystem. NOTE: Use this command with extreme caution, as improper @@ -27,14 +32,5 @@ Usage: consul operator [options] Run consul operator with no arguments for help on that subcommand. ` - return strings.TrimSpace(helpText) -} - -func (c *OperatorCommand) Run(args []string) int { - return cli.RunResultHelp -} - -// Synopsis returns a one-line description of this command. -func (c *OperatorCommand) Synopsis() string { - return "Provides cluster-level tools for Consul operators" + return s } diff --git a/command/oper/operator_test.go b/command/oper/operator_test.go new file mode 100644 index 000000000..f540fe377 --- /dev/null +++ b/command/oper/operator_test.go @@ -0,0 +1,13 @@ +package oper + +import ( + "strings" + "testing" +) + +func TestOperatorCommand_noTabs(t *testing.T) { + t.Parallel() + if strings.ContainsRune(New().Help(), '\t') { + t.Fatal("usage has tabs") + } +} diff --git a/command/operator_test.go b/command/operator_test.go deleted file mode 100644 index 7364a7cfa..000000000 --- a/command/operator_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package command - -import ( - "testing" - - "github.com/mitchellh/cli" -) - -func TestOperator_Implements(t *testing.T) { - t.Parallel() - var _ cli.Command = &OperatorCommand{} -}