From c8992cbe28b16e302dee0738f9f985e3d10b9021 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Tue, 17 Oct 2017 08:56:35 +0200 Subject: [PATCH] commands: move snapshot command to separate pkg --- command/commands.go | 5 ++--- command/{ => snapshot}/snapshot_command.go | 22 +++++++++++----------- command/snapshot/snapshot_command_test.go | 13 +++++++++++++ command/snapshot_command_test.go | 17 ----------------- 4 files changed, 26 insertions(+), 31 deletions(-) rename command/{ => snapshot}/snapshot_command.go (76%) create mode 100644 command/snapshot/snapshot_command_test.go delete mode 100644 command/snapshot_command_test.go diff --git a/command/commands.go b/command/commands.go index cb704debec..b08f9a66d7 100644 --- a/command/commands.go +++ b/command/commands.go @@ -37,6 +37,7 @@ import ( "github.com/hashicorp/consul/command/reload" "github.com/hashicorp/consul/command/rtt" "github.com/hashicorp/consul/command/validate" + "github.com/hashicorp/consul/snapshot" "github.com/hashicorp/consul/version" "github.com/mitchellh/cli" ) @@ -187,9 +188,7 @@ func init() { }, "snapshot": func() (cli.Command, error) { - return &SnapshotCommand{ - UI: ui, - }, nil + return snapshot.New(), nil }, "snapshot restore": func() (cli.Command, error) { diff --git a/command/snapshot_command.go b/command/snapshot/snapshot_command.go similarity index 76% rename from command/snapshot_command.go rename to command/snapshot/snapshot_command.go index 59520b743b..5353b229a6 100644 --- a/command/snapshot_command.go +++ b/command/snapshot/snapshot_command.go @@ -1,20 +1,24 @@ -package command +package snapshot import ( "github.com/mitchellh/cli" ) -// SnapshotCommand is a Command implementation that just shows help for -// the subcommands nested below it. -type SnapshotCommand struct { - UI cli.Ui +func New() *cmd { + return &cmd{} } -func (c *SnapshotCommand) Run(args []string) int { +type cmd struct{} + +func (c *cmd) Run(args []string) int { return cli.RunResultHelp } -func (c *SnapshotCommand) Help() string { +func (c *cmd) Synopsis() string { + return "Saves, restores and inspects snapshots of Consul server state" +} + +func (c *cmd) Help() string { return `Usage: consul snapshot [options] [args] This command has subcommands for saving, restoring, and inspecting the state @@ -45,7 +49,3 @@ func (c *SnapshotCommand) Help() string { For more examples, ask for subcommand help or view the documentation. ` } - -func (c *SnapshotCommand) Synopsis() string { - return "Saves, restores and inspects snapshots of Consul server state" -} diff --git a/command/snapshot/snapshot_command_test.go b/command/snapshot/snapshot_command_test.go new file mode 100644 index 0000000000..b2c848e463 --- /dev/null +++ b/command/snapshot/snapshot_command_test.go @@ -0,0 +1,13 @@ +package snapshot + +import ( + "strings" + "testing" +) + +func TestSnapshotCommand_noTabs(t *testing.T) { + t.Parallel() + if strings.ContainsRune(New().Help(), '\t') { + t.Fatal("usage has tabs") + } +} diff --git a/command/snapshot_command_test.go b/command/snapshot_command_test.go deleted file mode 100644 index 391e4b7cda..0000000000 --- a/command/snapshot_command_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package command - -import ( - "testing" - - "github.com/mitchellh/cli" -) - -func TestSnapshotCommand_implements(t *testing.T) { - t.Parallel() - var _ cli.Command = &SnapshotCommand{} -} - -func TestSnapshotCommand_noTabs(t *testing.T) { - t.Parallel() - assertNoTabs(t, new(SnapshotCommand)) -}