diff --git a/command/remote.go b/command/remote.go index f8f8cffb3..ee98d1c8e 100644 --- a/command/remote.go +++ b/command/remote.go @@ -31,25 +31,21 @@ type RemoteCommand struct { func (c *RemoteCommand) Run(args []string) int { args = c.Meta.process(args, false) - var address, accessToken, name, path string + config := make(map[string]string) cmdFlags := flag.NewFlagSet("remote", flag.ContinueOnError) cmdFlags.BoolVar(&c.conf.disableRemote, "disable", false, "") cmdFlags.BoolVar(&c.conf.pullOnDisable, "pull", true, "") cmdFlags.StringVar(&c.conf.statePath, "state", DefaultStateFilename, "path") cmdFlags.StringVar(&c.conf.backupPath, "backup", "", "path") cmdFlags.StringVar(&c.remoteConf.Type, "backend", "atlas", "") - cmdFlags.StringVar(&address, "address", "", "") - cmdFlags.StringVar(&accessToken, "access-token", "", "") - cmdFlags.StringVar(&name, "name", "", "") - cmdFlags.StringVar(&path, "path", "", "") + cmdFlags.Var((*FlagKV)(&config), "config", "config") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 } // Show help if given no inputs - if !c.conf.disableRemote && c.remoteConf.Type == "atlas" && - name == "" && accessToken == "" { + if !c.conf.disableRemote && c.remoteConf.Type == "atlas" && len(config) == 0 { cmdFlags.Usage() return 1 } @@ -58,12 +54,7 @@ func (c *RemoteCommand) Run(args []string) int { c.statePath = c.conf.statePath // Populate the various configurations - c.remoteConf.Config = map[string]string{ - "address": address, - "access_token": accessToken, - "name": name, - "path": path, - } + c.remoteConf.Config = config // Get the state information. We specifically request the cache only // for the remote state here because it is possible the remote state diff --git a/command/remote_test.go b/command/remote_test.go index f656fc2fe..d0ca58609 100644 --- a/command/remote_test.go +++ b/command/remote_test.go @@ -243,8 +243,8 @@ func TestRemote_initBlank(t *testing.T) { args := []string{ "-backend=http", - "-address", "http://example.com", - "-access-token=test", + "-config", "address=http://example.com", + "-config", "access_token=test", } if code := c.Run(args); code != 0 { t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) @@ -319,9 +319,8 @@ func TestRemote_updateRemote(t *testing.T) { args := []string{ "-backend=http", - "-address", - "http://example.com", - "-access-token=test", + "-config", "address=http://example.com", + "-config", "access_token=test", } if code := c.Run(args); code != 0 { t.Fatalf("bad: \n%s", ui.ErrorWriter.String()) @@ -375,9 +374,8 @@ func TestRemote_enableRemote(t *testing.T) { args := []string{ "-backend=http", - "-address", - "http://example.com", - "-access-token=test", + "-config", "address=http://example.com", + "-config", "access_token=test", } if code := c.Run(args); code != 0 { t.Fatalf("bad: \n%s", ui.ErrorWriter.String())