-
Notifications
You must be signed in to change notification settings - Fork 182
Added support for complex variables #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
f8b286b
f8b7d64
26d1d5a
4503657
aff20cf
f5d7127
d8f50f2
f7eba5f
443b338
ddd14eb
0c4bf71
44b17cd
95c0032
59dba11
327d05e
2e3c97b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,6 +267,11 @@ func (r *Root) InitializeVariables(vars []string) error { | |
| if _, ok := r.Variables[name]; !ok { | ||
| return fmt.Errorf("variable %s has not been defined", name) | ||
| } | ||
|
|
||
| if r.Variables[name].IsComplex() { | ||
| return fmt.Errorf("setting variables of complex type via --var flag is not supported: %s", name) | ||
| } | ||
|
|
||
| err := r.Variables[name].Set(val) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to assign %s to %s: %s", val, name, err) | ||
|
|
@@ -419,7 +424,7 @@ func rewriteShorthands(v dyn.Value) (dyn.Value, error) { | |
| } | ||
|
|
||
| // For each variable, normalize its contents if it is a single string. | ||
| return dyn.Map(target, "variables", dyn.Foreach(func(_ dyn.Path, variable dyn.Value) (dyn.Value, error) { | ||
| return dyn.Map(target, "variables", dyn.Foreach(func(p dyn.Path, variable dyn.Value) (dyn.Value, error) { | ||
| switch variable.Kind() { | ||
|
|
||
| case dyn.KindString, dyn.KindBool, dyn.KindFloat, dyn.KindInt: | ||
|
|
@@ -430,6 +435,21 @@ func rewriteShorthands(v dyn.Value) (dyn.Value, error) { | |
| "default": variable, | ||
| }, variable.Location()), nil | ||
|
|
||
| case dyn.KindMap, dyn.KindSequence: | ||
| // Check if the original definition of variable has a type field. | ||
| typeV, err := dyn.GetByPath(v, p.Append(dyn.Key("type"))) | ||
| if err != nil { | ||
| return variable, nil | ||
| } | ||
|
|
||
| if typeV.MustString() == "complex" { | ||
| return dyn.NewValue(map[string]dyn.Value{ | ||
| "default": variable, | ||
| }, variable.Location()), nil | ||
| } | ||
|
|
||
| return variable, nil | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the PR include test coverage for this, i.e. both ways of setting the variable, as well as defining a top level complex variable and then specifying a different type in the override?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you TAL at this? |
||
| default: | ||
| return variable, nil | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.