From f10f07b448f07c23000f5df15d05710278f17279 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Tue, 17 Oct 2017 08:03:03 +0200 Subject: [PATCH] commands: move operator raft command to separate pkg --- command/commands.go | 8 ++------ command/operator_raft_test.go | 22 -------------------- command/{ => operraft}/operator_raft.go | 27 ++++++++++++------------- command/operraft/operator_raft_test.go | 13 ++++++++++++ 4 files changed, 28 insertions(+), 42 deletions(-) delete mode 100644 command/operator_raft_test.go rename command/{ => operraft}/operator_raft.go (57%) create mode 100644 command/operraft/operator_raft_test.go diff --git a/command/commands.go b/command/commands.go index cd2787ae1d..8e7f79a808 100644 --- a/command/commands.go +++ b/command/commands.go @@ -28,6 +28,7 @@ import ( "github.com/hashicorp/consul/command/members" "github.com/hashicorp/consul/command/monitor" "github.com/hashicorp/consul/command/oper" + "github.com/hashicorp/consul/command/operraft" "github.com/hashicorp/consul/command/validate" "github.com/hashicorp/consul/version" "github.com/mitchellh/cli" @@ -174,12 +175,7 @@ func init() { }, "operator raft": func() (cli.Command, error) { - return &OperatorRaftCommand{ - BaseCommand: BaseCommand{ - Flags: FlagSetHTTP, - UI: ui, - }, - }, nil + return operraft.New(), nil }, "operator raft list-peers": func() (cli.Command, error) { diff --git a/command/operator_raft_test.go b/command/operator_raft_test.go deleted file mode 100644 index 99eb7312b7..0000000000 --- a/command/operator_raft_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package command - -import ( - "testing" - - "github.com/mitchellh/cli" -) - -func testOperatorRaftCommand(t *testing.T) (*cli.MockUi, *OperatorRaftCommand) { - ui := cli.NewMockUi() - return ui, &OperatorRaftCommand{ - BaseCommand: BaseCommand{ - UI: ui, - Flags: FlagSetHTTP, - }, - } -} - -func TestOperator_Raft_Implements(t *testing.T) { - t.Parallel() - var _ cli.Command = &OperatorRaftCommand{} -} diff --git a/command/operator_raft.go b/command/operraft/operator_raft.go similarity index 57% rename from command/operator_raft.go rename to command/operraft/operator_raft.go index 5460a694c1..c516ad5d51 100644 --- a/command/operator_raft.go +++ b/command/operraft/operator_raft.go @@ -1,21 +1,25 @@ -package command +package operraft import ( - "strings" - "github.com/mitchellh/cli" ) -type OperatorRaftCommand struct { - BaseCommand +func New() *cmd { + return &cmd{} } -func (c *OperatorRaftCommand) Run(args []string) int { +type cmd struct{} + +func (c *cmd) Run(args []string) int { return cli.RunResultHelp } -func (c *OperatorRaftCommand) Help() string { - helpText := ` +func (c *cmd) Synopsis() string { + return "Provides cluster-level tools for Consul operators" +} + +func (c *cmd) Help() string { + s := ` Usage: consul operator raft [options] The Raft operator command is used to interact with Consul's Raft subsystem. The @@ -23,10 +27,5 @@ command can be used to verify Raft peers or in rare cases to recover quorum by removing invalid peers. ` - - return strings.TrimSpace(helpText) -} - -func (c *OperatorRaftCommand) Synopsis() string { - return "Provides cluster-level tools for Consul operators" + return s } diff --git a/command/operraft/operator_raft_test.go b/command/operraft/operator_raft_test.go new file mode 100644 index 0000000000..3ba5e23a78 --- /dev/null +++ b/command/operraft/operator_raft_test.go @@ -0,0 +1,13 @@ +package operraft + +import ( + "strings" + "testing" +) + +func TestOperatorRaftCommand_noTabs(t *testing.T) { + t.Parallel() + if strings.ContainsRune(New().Help(), '\t') { + t.Fatal("usage has tabs") + } +}