summaryrefslogtreecommitdiff
path: root/cmd/hcldec
AgeCommit message (Collapse)Author
2023-02-28[COMPLIANCE] Add Copyright and License Headers (#586)hashicorp-copywrite[bot]
* [COMPLIANCE] Add Copyright and License Headers * add copywrite file and revert headers in testdata --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>
2020-01-09Fix various stale links to spec.mdMasayuki Morita
These resulted from repository reorganization in preparation for the 2.0.0 release.
2019-12-11Fix import ordering from the move from hcl2 repositoryMartin Atkins
When we did the automatic rewriting from the hashicorp/hcl2 import paths to hashicorp/hcl/v2 import paths, our automatic rewrite script did not run "go fmt" afterwards and so left some imports misordered as a result of the slightly-differently-shaped directory structure in the new repository.
2019-10-01cmd/hcldec: Allow overriding the removal of nullsMartin Atkins
We remove properties whose values are null by default in order to produce output that is more convenient to consume in the common case. However, sometimes those nulls are significant, so we'll allow the user to opt in to retaining them, at the expense of producing a result that is more noisy if the spec contains lots of optional attributes that are not set.
2019-09-09Unfold the "hcl" directory up into the rootMartin Atkins
The main HCL package is more visible this way, and so it's easier than having to pick it out from dozens of other package directories.
2019-09-09Change module path to github.com/hashicorp/hcl/v2Martin Atkins
This is in preparation for the first v2 release from the main HCL repository.
2019-07-22Remove incorrect quotes around types in examples (#119)Buck Doyle
When I tried a spec with quoted types, I got this error: `A type is required, not string.` Later in the document, the types don’t have quotes, so I figured that’s what’s expected.
2018-08-22hcldec: Handle or forbid cty.DynamicPseudoType attributes in nested blocksMartin Atkins
Our BlockList, BlockSet, and BlockMap specs all produce cty collection values, which require all elements to have a homogeneous type. If the nested spec contained an attribute of type cty.DynamicPseudoType, that would create the risk of each element having a different type, which would previously have caused decoding to panic. Now we either handle this during decode (BlockList, BlockSet) or forbid it outright (BlockMap) to prevent that crash. BlockMap could _potentially_ also handle this during decode, but that would require a more significant reorganization of its implementation than I want to take on right now, and decoding dynamically-typed values inside collections is an edge case anyway.
2018-08-10cmd/hclspecsuite: basic runner functionality for successful casesMartin Atkins
The harness can now run tests that decode successfully and compare the result with a given value. Further work is required in later commits to deal with other cases, such as tests that intentionally produce errors.
2018-08-09cmd/hcldec: opt-in JSON-formatted diagnosticsMartin Atkins
By default we generate human-readable diagnostics on the assumption that the caller is a simple program that is capturing stdin via a pipe and letting stderr go to the terminal. More sophisticated callers may wish to analyze the diagnostics themselves and perhaps present them in a different way, such as via a GUI.
2018-08-09cmd/hcldec: --var-refs optionMartin Atkins
This option skips the usual decoding step and instead prints out a JSON- formatted list of the variables that are referenced by the configuration. In simple cases this is not required, but for more complex use-cases it can be useful to first analyze the input to see which variables need to be in the scope, then construct a suitable set of variables before finally decoding the input. For example, some of the variable values may be expensive to produce.
2018-08-09hcldec: BlockAttrsSpec spec typeMartin Atkins
This is the hcldec interface to Body.JustAttributes, producing a map whose keys are the child attribute names and whose values are the results of evaluating those expressions. We can't just expose a JustAttributes-style spec directly here because it's not really compatible with how hcldec thinks about things, but we can expose a spec that decodes a specific child block because that can then compose properly with other specs at the same level without interfering with their operation. The primary use for this is to allow the use of the block syntax to define a map: dynamic_stuff { foo = "bar" } JustAttributes is normally used in static analysis situations such as enumerating the contents of a block to decide what to include in the final EvalContext. That's not really possible with the hcldec model because both structural decoding and expression evaluation happen together. Therefore the use of this is pretty limited: it's useful if you want to be compatible with an existing format based on legacy HCL where a map was conventionally defined using block syntax, relying on the fact that HCL did not make a strong distinction between attribute and block syntax.
2018-02-04ext/userfunc: use bare identifiers for param namesMartin Atkins
Now that we have the necessary functions to deal with this in the low-level HCL API, it's more intuitive to use bare identifiers for these parameter names. This reinforces the idea that they are symbols being defined rather than arbitrary string expressions.
2018-02-04cmd/hcldec: allow spec file to define variables and functionsMartin Atkins
The spec file can now additionally define default variables and functions for the eval context used to evaluate the input file.
2018-02-04cmd/hcldec: make cty stdlib functions available to specsMartin Atkins
In a few specific portions of the spec format it's convenient to have access to some of the functions defined in the cty stdlib. Here we allow them to be used when constructing the value for a "literal" spec and in the result expression for a "transform" spec.
2018-02-04cmd/hcldec: "transform" spec typeMartin Atkins
This new spec type allows evaluating an arbitrary expression on the result of a nested spec, for situations where the a value must be transformed in some way.
2018-02-04cmd/hcldec: decode "array" blocksMartin Atkins
These were missed on the previous pass, causing a disagreement with the documentation.
2018-02-03cmd/hcldec: Command-line tool for converting HCL config to JSONMartin Atkins
This is essentially a CLI wrapper around the hcldec package, accepting a decoding specification via a HCL-based language and using it to translate input HCL files into JSON values while performing basic structural and type validation of the input files.