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

Function Variables

hcldec/variables.go:20–39  ·  view source on GitHub ↗

Variables processes the given body with the given spec and returns a list of the variable traversals that would be required to decode the same pairing of body and spec. This can be used to conditionally populate the variables in the EvalContext passed to Decode, for applications where a static scop

(body hcl.Body, spec Spec)

Source from the content-addressed store, hash-verified

18// be incomplete, but that's assumed to be okay because the eventual call
19// to Decode will produce error diagnostics anyway.
20func Variables(body hcl.Body, spec Spec) []hcl.Traversal {
21 var vars []hcl.Traversal
22 schema := ImpliedSchema(spec)
23 content, _, _ := body.PartialContent(schema)
24
25 if vs, ok := spec.(specNeedingVariables); ok {
26 vars = append(vars, vs.variablesNeeded(content)...)
27 }
28
29 var visitFn visitFunc
30 visitFn = func(s Spec) {
31 if vs, ok := s.(specNeedingVariables); ok {
32 vars = append(vars, vs.variablesNeeded(content)...)
33 }
34 s.visitSameBodyChildren(visitFn)
35 }
36 spec.visitSameBodyChildren(visitFn)
37
38 return vars
39}

Callers 10

realmainFunction · 0.92
TestTerraformLikeFunction · 0.92
variablesNeededMethod · 0.70
variablesNeededMethod · 0.70
variablesNeededMethod · 0.70
variablesNeededMethod · 0.70
variablesNeededMethod · 0.70
variablesNeededMethod · 0.70
TestDefaultSpecFunction · 0.70
TestVariablesFunction · 0.70

Calls 4

ImpliedSchemaFunction · 0.85
PartialContentMethod · 0.65
variablesNeededMethod · 0.65
visitSameBodyChildrenMethod · 0.65

Tested by 3

TestTerraformLikeFunction · 0.74
TestDefaultSpecFunction · 0.56
TestVariablesFunction · 0.56