44bad6dbf5
This function returns the type of value that should be returned when decoding the given spec. As well as being generally useful to the caller for book-keeping purposes, this also allows us to return correct type information when we are returning null and empty values, where before we were leaning a little too much on cty.DynamicPseudoType.
37 lines
879 B
Go
37 lines
879 B
Go
package hcldec
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl2/hcl"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
func decode(body hcl.Body, blockLabels []blockLabel, ctx *hcl.EvalContext, spec Spec, partial bool) (cty.Value, hcl.Body, hcl.Diagnostics) {
|
|
schema := ImpliedSchema(spec)
|
|
|
|
var content *hcl.BodyContent
|
|
var diags hcl.Diagnostics
|
|
var leftovers hcl.Body
|
|
|
|
if partial {
|
|
content, leftovers, diags = body.PartialContent(schema)
|
|
} else {
|
|
content, diags = body.Content(schema)
|
|
}
|
|
|
|
val, valDiags := spec.decode(content, blockLabels, ctx)
|
|
diags = append(diags, valDiags...)
|
|
|
|
return val, leftovers, diags
|
|
}
|
|
|
|
func impliedType(spec Spec) cty.Type {
|
|
return spec.impliedType()
|
|
}
|
|
|
|
func sourceRange(body hcl.Body, blockLabels []blockLabel, spec Spec) hcl.Range {
|
|
schema := ImpliedSchema(spec)
|
|
content, _, _ := body.PartialContent(schema)
|
|
|
|
return spec.sourceRange(content, blockLabels)
|
|
}
|