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