mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
Extend hcl2 support with more functions
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
19
vendor/github.com/zclconf/go-cty/cty/convert/conversion_object.go
generated
vendored
19
vendor/github.com/zclconf/go-cty/cty/convert/conversion_object.go
generated
vendored
@ -11,17 +11,29 @@ import (
|
||||
// type, meaning that each attribute of the output type has a corresponding
|
||||
// attribute in the input type where a recursive conversion is available.
|
||||
//
|
||||
// If the "out" type has any optional attributes, those attributes may be
|
||||
// absent in the "in" type, in which case null values will be used in their
|
||||
// place in the result.
|
||||
//
|
||||
// Shallow object conversions work the same for both safe and unsafe modes,
|
||||
// but the safety flag is passed on to recursive conversions and may thus
|
||||
// limit the above definition of "subset".
|
||||
func conversionObjectToObject(in, out cty.Type, unsafe bool) conversion {
|
||||
inAtys := in.AttributeTypes()
|
||||
outAtys := out.AttributeTypes()
|
||||
outOptionals := out.OptionalAttributes()
|
||||
attrConvs := make(map[string]conversion)
|
||||
|
||||
for name, outAty := range outAtys {
|
||||
inAty, exists := inAtys[name]
|
||||
if !exists {
|
||||
if _, optional := outOptionals[name]; optional {
|
||||
// If it's optional then we'll skip inserting an
|
||||
// attribute conversion and then deal with inserting
|
||||
// the default value in our overall conversion logic
|
||||
// later.
|
||||
continue
|
||||
}
|
||||
// No conversion is available, then.
|
||||
return nil
|
||||
}
|
||||
@ -71,6 +83,13 @@ func conversionObjectToObject(in, out cty.Type, unsafe bool) conversion {
|
||||
attrVals[name] = val
|
||||
}
|
||||
|
||||
for name := range outOptionals {
|
||||
if _, exists := attrVals[name]; !exists {
|
||||
wantTy := outAtys[name]
|
||||
attrVals[name] = cty.NullVal(wantTy)
|
||||
}
|
||||
}
|
||||
|
||||
return cty.ObjectVal(attrVals), nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user