]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/hcl2/hcldec/variables.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hcl2 / hcldec / variables.go
1 package hcldec
2
3 import (
4 "github.com/hashicorp/hcl2/hcl"
5 )
6
7 // Variables processes the given body with the given spec and returns a
8 // list of the variable traversals that would be required to decode
9 // the same pairing of body and spec.
10 //
11 // This can be used to conditionally populate the variables in the EvalContext
12 // passed to Decode, for applications where a static scope is insufficient.
13 //
14 // If the given body is not compliant with the given schema, the result may
15 // be incomplete, but that's assumed to be okay because the eventual call
16 // to Decode will produce error diagnostics anyway.
17 func Variables(body hcl.Body, spec Spec) []hcl.Traversal {
18 var vars []hcl.Traversal
19 schema := ImpliedSchema(spec)
20 content, _, _ := body.PartialContent(schema)
21
22 if vs, ok := spec.(specNeedingVariables); ok {
23 vars = append(vars, vs.variablesNeeded(content)...)
24 }
25
26 var visitFn visitFunc
27 visitFn = func(s Spec) {
28 if vs, ok := s.(specNeedingVariables); ok {
29 vars = append(vars, vs.variablesNeeded(content)...)
30 }
31 s.visitSameBodyChildren(visitFn)
32 }
33 spec.visitSameBodyChildren(visitFn)
34
35 return vars
36 }