MCPcopy
hub / github.com/hashicorp/hcl / decodeSpecDecls

Function decodeSpecDecls

cmd/hcldec/spec.go:46–75  ·  view source on GitHub ↗
(body hcl.Body)

Source from the content-addressed store, hash-verified

44}
45
46func decodeSpecDecls(body hcl.Body) (map[string]cty.Value, map[string]function.Function, hcl.Body, hcl.Diagnostics) {
47 funcs, body, diags := userfunc.DecodeUserFunctions(body, "function", func() *hcl.EvalContext {
48 return specCtx
49 })
50
51 content, body, moreDiags := body.PartialContent(&hcl.BodySchema{
52 Blocks: []hcl.BlockHeaderSchema{
53 {
54 Type: "variables",
55 },
56 },
57 })
58 diags = append(diags, moreDiags...)
59
60 vars := make(map[string]cty.Value)
61 for _, block := range content.Blocks {
62 // We only have one block type in our schema, so we can assume all
63 // blocks are of that type.
64 attrs, moreDiags := block.Body.JustAttributes()
65 diags = append(diags, moreDiags...)
66
67 for name, attr := range attrs {
68 val, moreDiags := attr.Expr.Value(specCtx)
69 diags = append(diags, moreDiags...)
70 vars[name] = val
71 }
72 }
73
74 return vars, funcs, body, diags
75}
76
77func decodeSpecRoot(body hcl.Body) (hcldec.Spec, hcl.Diagnostics) {
78 content, diags := body.Content(specSchemaUnlabelled)

Callers 1

loadSpecFileFunction · 0.85

Calls 4

DecodeUserFunctionsFunction · 0.92
PartialContentMethod · 0.65
JustAttributesMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected