command/remote: general `-config` flag

This commit is contained in:
Mitchell Hashimoto 2015-02-23 10:51:31 -08:00
parent 4d126998b5
commit 84a0e512d3
2 changed files with 10 additions and 21 deletions

View File

@ -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

View File

@ -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())