command: Input tells us whether we should ask for input or not
This commit is contained in:
parent
a918833edd
commit
5b0859b3f5
|
@ -30,6 +30,7 @@ type Meta struct {
|
|||
// Variables for the context (private)
|
||||
autoKey string
|
||||
autoVariables map[string]string
|
||||
input bool
|
||||
variables map[string]string
|
||||
|
||||
color bool
|
||||
|
@ -105,6 +106,11 @@ func (m *Meta) Context(copts contextOpts) (*terraform.Context, bool, error) {
|
|||
return ctx, false, nil
|
||||
}
|
||||
|
||||
// Input returns true if we should ask for input for context.
|
||||
func (m *Meta) Input() bool {
|
||||
return m.input && len(m.variables) == 0
|
||||
}
|
||||
|
||||
// contextOpts returns the options to use to initialize a Terraform
|
||||
// context with the settings from this Meta.
|
||||
func (m *Meta) contextOpts() *terraform.ContextOpts {
|
||||
|
@ -127,6 +133,7 @@ func (m *Meta) contextOpts() *terraform.ContextOpts {
|
|||
vs[k] = v
|
||||
}
|
||||
opts.Variables = vs
|
||||
opts.UIInput = new(UIInput)
|
||||
|
||||
return &opts
|
||||
}
|
||||
|
@ -134,6 +141,7 @@ func (m *Meta) contextOpts() *terraform.ContextOpts {
|
|||
// flags adds the meta flags to the given FlagSet.
|
||||
func (m *Meta) flagSet(n string) *flag.FlagSet {
|
||||
f := flag.NewFlagSet(n, flag.ContinueOnError)
|
||||
f.BoolVar(&m.input, "input", true, "input")
|
||||
f.Var((*FlagVar)(&m.variables), "var", "variables")
|
||||
f.Var((*FlagVarFile)(&m.variables), "var-file", "variable file")
|
||||
|
||||
|
|
|
@ -47,3 +47,45 @@ func TestMetaColorize(t *testing.T) {
|
|||
t.Fatal("should be disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetaInput(t *testing.T) {
|
||||
m := new(Meta)
|
||||
args := []string{}
|
||||
|
||||
fs := m.flagSet("foo")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !m.Input() {
|
||||
t.Fatal("should input")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetaInput_disable(t *testing.T) {
|
||||
m := new(Meta)
|
||||
args := []string{"-input=false"}
|
||||
|
||||
fs := m.flagSet("foo")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if m.Input() {
|
||||
t.Fatal("should not input")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetaInput_vars(t *testing.T) {
|
||||
m := new(Meta)
|
||||
args := []string{"-var", "foo=bar"}
|
||||
|
||||
fs := m.flagSet("foo")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if m.Input() {
|
||||
t.Fatal("should not input")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,6 +167,8 @@ Options:
|
|||
-destroy If set, a plan will be generated to destroy all resources
|
||||
managed by the given configuration and state.
|
||||
|
||||
-input=true Ask for input for variables if not directly set.
|
||||
|
||||
-module-depth=n Specifies the depth of modules to show in the output.
|
||||
This does not affect the plan itself, only the output
|
||||
shown. By default, this is zero. -1 will expand all.
|
||||
|
|
Loading…
Reference in New Issue