config: change Default to an interface{}
This commit is contained in:
parent
9c164c6015
commit
b0ce89b805
|
@ -53,9 +53,8 @@ type Provisioner struct {
|
||||||
// Variable is a variable defined within the configuration.
|
// Variable is a variable defined within the configuration.
|
||||||
type Variable struct {
|
type Variable struct {
|
||||||
Name string
|
Name string
|
||||||
Default string
|
Default interface{}
|
||||||
Description string
|
Description string
|
||||||
defaultSet bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output is an output defined within the configuration. An output is
|
// Output is an output defined within the configuration. An output is
|
||||||
|
@ -310,9 +309,8 @@ func (v *Variable) Merge(v2 *Variable) *Variable {
|
||||||
// The names should be the same, but the second name always wins.
|
// The names should be the same, but the second name always wins.
|
||||||
result.Name = v2.Name
|
result.Name = v2.Name
|
||||||
|
|
||||||
if v2.defaultSet {
|
if v2.Default != nil {
|
||||||
result.Default = v2.Default
|
result.Default = v2.Default
|
||||||
result.defaultSet = true
|
|
||||||
}
|
}
|
||||||
if v2.Description != "" {
|
if v2.Description != "" {
|
||||||
result.Description = v2.Description
|
result.Description = v2.Description
|
||||||
|
@ -331,7 +329,7 @@ func (v *Variable) mergerMerge(m merger) merger {
|
||||||
|
|
||||||
// Required tests whether a variable is required or not.
|
// Required tests whether a variable is required or not.
|
||||||
func (v *Variable) Required() bool {
|
func (v *Variable) Required() bool {
|
||||||
return !v.defaultSet
|
return v.Default == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewResourceVariable(key string) (*ResourceVariable, error) {
|
func NewResourceVariable(key string) (*ResourceVariable, error) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (t *libuclConfigurable) Config() (*Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LibuclVariable struct {
|
type LibuclVariable struct {
|
||||||
Default string
|
Default interface{}
|
||||||
Description string
|
Description string
|
||||||
Fields []string `libucl:",decodedFields"`
|
Fields []string `libucl:",decodedFields"`
|
||||||
}
|
}
|
||||||
|
@ -51,19 +51,10 @@ func (t *libuclConfigurable) Config() (*Config, error) {
|
||||||
if len(rawConfig.Variable) > 0 {
|
if len(rawConfig.Variable) > 0 {
|
||||||
config.Variables = make([]*Variable, 0, len(rawConfig.Variable))
|
config.Variables = make([]*Variable, 0, len(rawConfig.Variable))
|
||||||
for k, v := range rawConfig.Variable {
|
for k, v := range rawConfig.Variable {
|
||||||
defaultSet := false
|
|
||||||
for _, f := range v.Fields {
|
|
||||||
if f == "Default" {
|
|
||||||
defaultSet = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config.Variables = append(config.Variables, &Variable{
|
config.Variables = append(config.Variables, &Variable{
|
||||||
Name: k,
|
Name: k,
|
||||||
Default: v.Default,
|
Default: v.Default,
|
||||||
Description: v.Description,
|
Description: v.Description,
|
||||||
defaultSet: defaultSet,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,20 +437,20 @@ func variablesStr(vs []*Variable) string {
|
||||||
for _, k := range ks {
|
for _, k := range ks {
|
||||||
v := m[k]
|
v := m[k]
|
||||||
|
|
||||||
if v.Default == "" {
|
required := ""
|
||||||
|
if v.Required() {
|
||||||
|
required = " (required)"
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Default == nil || v.Default == "" {
|
||||||
v.Default = "<>"
|
v.Default = "<>"
|
||||||
}
|
}
|
||||||
if v.Description == "" {
|
if v.Description == "" {
|
||||||
v.Description = "<>"
|
v.Description = "<>"
|
||||||
}
|
}
|
||||||
|
|
||||||
required := ""
|
|
||||||
if v.Required() {
|
|
||||||
required = " (required)"
|
|
||||||
}
|
|
||||||
|
|
||||||
result += fmt.Sprintf(
|
result += fmt.Sprintf(
|
||||||
"%s%s\n %s\n %s\n",
|
"%s%s\n %v\n %s\n",
|
||||||
k,
|
k,
|
||||||
required,
|
required,
|
||||||
v.Default,
|
v.Default,
|
||||||
|
|
|
@ -103,7 +103,7 @@ func TestMerge(t *testing.T) {
|
||||||
&Resource{Name: "bar"},
|
&Resource{Name: "bar"},
|
||||||
},
|
},
|
||||||
Variables: []*Variable{
|
Variables: []*Variable{
|
||||||
&Variable{Name: "foo", Default: "bar", defaultSet: true},
|
&Variable{Name: "foo", Default: "bar"},
|
||||||
&Variable{Name: "bar"},
|
&Variable{Name: "bar"},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ func TestMerge(t *testing.T) {
|
||||||
&Resource{Name: "bar"},
|
&Resource{Name: "bar"},
|
||||||
},
|
},
|
||||||
Variables: []*Variable{
|
Variables: []*Variable{
|
||||||
&Variable{Name: "foo", Default: "bar", defaultSet: true},
|
&Variable{Name: "foo", Default: "bar"},
|
||||||
&Variable{Name: "foo"},
|
&Variable{Name: "foo"},
|
||||||
&Variable{Name: "bar"},
|
&Variable{Name: "bar"},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue