From 01cd761023aa20d13eb080101733534d7811cfa0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 4 Mar 2015 16:17:30 -0800 Subject: [PATCH] command: move remote configuration stuff --- command/init.go | 2 +- command/{remote.go => remote_config.go} | 20 +++++------ command/{pull.go => remote_pull.go} | 8 ++--- command/{pull_test.go => remote_pull_test.go} | 8 ++--- command/{push.go => remote_push.go} | 8 ++--- command/{push_test.go => remote_push_test.go} | 8 ++--- command/remote_test.go | 36 +++++++++---------- commands.go | 12 ------- 8 files changed, 45 insertions(+), 57 deletions(-) rename command/{remote.go => remote_config.go} (94%) rename command/{pull.go => remote_pull.go} (90%) rename command/{pull_test.go => remote_pull_test.go} (94%) rename command/{push.go => remote_push.go} (91%) rename command/{push_test.go => remote_push_test.go} (89%) diff --git a/command/init.go b/command/init.go index 643b34973..328c473d0 100644 --- a/command/init.go +++ b/command/init.go @@ -120,7 +120,7 @@ func (c *InitCommand) Run(args []string) int { } // Initialize a blank state file with remote enabled - remoteCmd := &RemoteCommand{ + remoteCmd := &RemoteConfigCommand{ Meta: c.Meta, remoteConf: remoteConf, } diff --git a/command/remote.go b/command/remote_config.go similarity index 94% rename from command/remote.go rename to command/remote_config.go index f304a0aa2..cb95c4b94 100644 --- a/command/remote.go +++ b/command/remote_config.go @@ -21,15 +21,15 @@ type remoteCommandConfig struct { backupPath string } -// RemoteCommand is a Command implementation that is used to +// RemoteConfigCommand is a Command implementation that is used to // enable and disable remote state management -type RemoteCommand struct { +type RemoteConfigCommand struct { Meta conf remoteCommandConfig remoteConf terraform.RemoteState } -func (c *RemoteCommand) Run(args []string) int { +func (c *RemoteConfigCommand) Run(args []string) int { args = c.Meta.process(args, false) config := make(map[string]string) cmdFlags := flag.NewFlagSet("remote", flag.ContinueOnError) @@ -115,7 +115,7 @@ func (c *RemoteCommand) Run(args []string) int { // disableRemoteState is used to disable remote state management, // and move the state file into place. -func (c *RemoteCommand) disableRemoteState() int { +func (c *RemoteConfigCommand) disableRemoteState() int { if c.stateResult == nil { c.Ui.Error(fmt.Sprintf( "Internal error. State() must be called internally before remote\n" + @@ -173,7 +173,7 @@ func (c *RemoteCommand) disableRemoteState() int { // validateRemoteConfig is used to verify that the remote configuration // we have is valid -func (c *RemoteCommand) validateRemoteConfig() error { +func (c *RemoteConfigCommand) validateRemoteConfig() error { conf := c.remoteConf _, err := remote.NewClient(conf.Type, conf.Config) if err != nil { @@ -184,7 +184,7 @@ func (c *RemoteCommand) validateRemoteConfig() error { // initBlank state is used to initialize a blank state that is // remote enabled -func (c *RemoteCommand) initBlankState() int { +func (c *RemoteConfigCommand) initBlankState() int { // Validate the remote configuration if err := c.validateRemoteConfig(); err != nil { return 1 @@ -212,7 +212,7 @@ func (c *RemoteCommand) initBlankState() int { // updateRemoteConfig is used to update the configuration of the // remote state store -func (c *RemoteCommand) updateRemoteConfig() int { +func (c *RemoteConfigCommand) updateRemoteConfig() int { // Validate the remote configuration if err := c.validateRemoteConfig(); err != nil { return 1 @@ -240,7 +240,7 @@ func (c *RemoteCommand) updateRemoteConfig() int { // enableRemoteState is used to enable remote state management // and to move a state file into place -func (c *RemoteCommand) enableRemoteState() int { +func (c *RemoteConfigCommand) enableRemoteState() int { // Validate the remote configuration if err := c.validateRemoteConfig(); err != nil { return 1 @@ -299,7 +299,7 @@ func (c *RemoteCommand) enableRemoteState() int { return 0 } -func (c *RemoteCommand) Help() string { +func (c *RemoteConfigCommand) Help() string { helpText := ` Usage: terraform remote [options] @@ -334,6 +334,6 @@ Options: return strings.TrimSpace(helpText) } -func (c *RemoteCommand) Synopsis() string { +func (c *RemoteConfigCommand) Synopsis() string { return "Configures remote state management" } diff --git a/command/pull.go b/command/remote_pull.go similarity index 90% rename from command/pull.go rename to command/remote_pull.go index e5976f2a5..3965f0d42 100644 --- a/command/pull.go +++ b/command/remote_pull.go @@ -8,11 +8,11 @@ import ( "github.com/hashicorp/terraform/state" ) -type PullCommand struct { +type RemotePullCommand struct { Meta } -func (c *PullCommand) Run(args []string) int { +func (c *RemotePullCommand) Run(args []string) int { args = c.Meta.process(args, false) cmdFlags := flag.NewFlagSet("pull", flag.ContinueOnError) cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } @@ -67,7 +67,7 @@ func (c *PullCommand) Run(args []string) int { return 0 } -func (c *PullCommand) Help() string { +func (c *RemotePullCommand) Help() string { helpText := ` Usage: terraform pull [options] @@ -77,6 +77,6 @@ Usage: terraform pull [options] return strings.TrimSpace(helpText) } -func (c *PullCommand) Synopsis() string { +func (c *RemotePullCommand) Synopsis() string { return "Refreshes the local state copy from the remote server" } diff --git a/command/pull_test.go b/command/remote_pull_test.go similarity index 94% rename from command/pull_test.go rename to command/remote_pull_test.go index d0bd08b86..94b52ce2b 100644 --- a/command/pull_test.go +++ b/command/remote_pull_test.go @@ -15,12 +15,12 @@ import ( "github.com/mitchellh/cli" ) -func TestPull_noRemote(t *testing.T) { +func TestRemotePull_noRemote(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) ui := new(cli.MockUi) - c := &PullCommand{ + c := &RemotePullCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -33,7 +33,7 @@ func TestPull_noRemote(t *testing.T) { } } -func TestPull_local(t *testing.T) { +func TestRemotePull_local(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) @@ -62,7 +62,7 @@ func TestPull_local(t *testing.T) { } ui := new(cli.MockUi) - c := &PullCommand{ + c := &RemotePullCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, diff --git a/command/push.go b/command/remote_push.go similarity index 91% rename from command/push.go rename to command/remote_push.go index a02553c21..259c82863 100644 --- a/command/push.go +++ b/command/remote_push.go @@ -8,11 +8,11 @@ import ( "github.com/hashicorp/terraform/state" ) -type PushCommand struct { +type RemotePushCommand struct { Meta } -func (c *PushCommand) Run(args []string) int { +func (c *RemotePushCommand) Run(args []string) int { var force bool args = c.Meta.process(args, false) cmdFlags := flag.NewFlagSet("push", flag.ContinueOnError) @@ -71,7 +71,7 @@ func (c *PushCommand) Run(args []string) int { return 0 } -func (c *PushCommand) Help() string { +func (c *RemotePushCommand) Help() string { helpText := ` Usage: terraform push [options] @@ -87,6 +87,6 @@ Options: return strings.TrimSpace(helpText) } -func (c *PushCommand) Synopsis() string { +func (c *RemotePushCommand) Synopsis() string { return "Uploads the the local state to the remote server" } diff --git a/command/push_test.go b/command/remote_push_test.go similarity index 89% rename from command/push_test.go rename to command/remote_push_test.go index 59c1c834e..d92c3e8ab 100644 --- a/command/push_test.go +++ b/command/remote_push_test.go @@ -9,12 +9,12 @@ import ( "github.com/mitchellh/cli" ) -func TestPush_noRemote(t *testing.T) { +func TestRemotePush_noRemote(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) ui := new(cli.MockUi) - c := &PushCommand{ + c := &RemotePushCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -27,7 +27,7 @@ func TestPush_noRemote(t *testing.T) { } } -func TestPush_local(t *testing.T) { +func TestRemotePush_local(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) @@ -56,7 +56,7 @@ func TestPush_local(t *testing.T) { } ui := new(cli.MockUi) - c := &PushCommand{ + c := &RemotePushCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, diff --git a/command/remote_test.go b/command/remote_test.go index be93eaf24..0452e3416 100644 --- a/command/remote_test.go +++ b/command/remote_test.go @@ -13,7 +13,7 @@ import ( ) // Test disabling remote management -func TestRemote_disable(t *testing.T) { +func TestRemoteConfig_disable(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) @@ -39,7 +39,7 @@ func TestRemote_disable(t *testing.T) { } ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -68,7 +68,7 @@ func TestRemote_disable(t *testing.T) { } // Test disabling remote management without pulling -func TestRemote_disable_noPull(t *testing.T) { +func TestRemoteConfig_disable_noPull(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) @@ -94,7 +94,7 @@ func TestRemote_disable_noPull(t *testing.T) { } ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -122,12 +122,12 @@ func TestRemote_disable_noPull(t *testing.T) { } // Test disabling remote management when not enabled -func TestRemote_disable_notEnabled(t *testing.T) { +func TestRemoteConfig_disable_notEnabled(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -141,7 +141,7 @@ func TestRemote_disable_notEnabled(t *testing.T) { } // Test disabling remote management with a state file in the way -func TestRemote_disable_otherState(t *testing.T) { +func TestRemoteConfig_disable_otherState(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) @@ -171,7 +171,7 @@ func TestRemote_disable_otherState(t *testing.T) { } ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -185,7 +185,7 @@ func TestRemote_disable_otherState(t *testing.T) { } // Test the case where both managed and non managed state present -func TestRemote_managedAndNonManaged(t *testing.T) { +func TestRemoteConfig_managedAndNonManaged(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) @@ -215,7 +215,7 @@ func TestRemote_managedAndNonManaged(t *testing.T) { } ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -229,12 +229,12 @@ func TestRemote_managedAndNonManaged(t *testing.T) { } // Test initializing blank state -func TestRemote_initBlank(t *testing.T) { +func TestRemoteConfig_initBlank(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -269,12 +269,12 @@ func TestRemote_initBlank(t *testing.T) { } // Test initializing without remote settings -func TestRemote_initBlank_missingRemote(t *testing.T) { +func TestRemoteConfig_initBlank_missingRemote(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -288,7 +288,7 @@ func TestRemote_initBlank_missingRemote(t *testing.T) { } // Test updating remote config -func TestRemote_updateRemote(t *testing.T) { +func TestRemoteConfig_updateRemote(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) @@ -310,7 +310,7 @@ func TestRemote_updateRemote(t *testing.T) { } ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, @@ -345,7 +345,7 @@ func TestRemote_updateRemote(t *testing.T) { } // Test enabling remote state -func TestRemote_enableRemote(t *testing.T) { +func TestRemoteConfig_enableRemote(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) @@ -365,7 +365,7 @@ func TestRemote_enableRemote(t *testing.T) { } ui := new(cli.MockUi) - c := &RemoteCommand{ + c := &RemoteConfigCommand{ Meta: Meta{ ContextOpts: testCtxConfig(testProvider()), Ui: ui, diff --git a/commands.go b/commands.go index 8c10a9a06..c585b7827 100644 --- a/commands.go +++ b/commands.go @@ -80,18 +80,6 @@ func init() { }, nil }, - "pull": func() (cli.Command, error) { - return &command.PullCommand{ - Meta: meta, - }, nil - }, - - "push": func() (cli.Command, error) { - return &command.PushCommand{ - Meta: meta, - }, nil - }, - "refresh": func() (cli.Command, error) { return &command.RefreshCommand{ Meta: meta,