Skip to content

Commit e8f0ca9

Browse files
draft hcl2 tree query system and hq cli
1 parent c886e46 commit e8f0ca9

54 files changed

Lines changed: 8921 additions & 179 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ The **Direct** pipeline (`parse_to_tree` → `transform` → `to_lark` → `reco
2828
| `cli/helpers.py` | File/directory/stdin conversion helpers |
2929
| `cli/hcl_to_json.py` | `hcl2tojson` entry point |
3030
| `cli/json_to_hcl.py` | `jsontohcl2` entry point |
31+
| `cli/hq.py` | `hq` CLI entry point — query dispatch, formatting, optional operator |
32+
| `hcl2/query/__init__.py` | Public query API exports |
33+
| `hcl2/query/_base.py` | `NodeView` base class, view registry, `view_for()` factory |
34+
| `hcl2/query/path.py` | Structural path parser (`PathSegment`, `parse_path`, `[select()]`, `type:name`) |
35+
| `hcl2/query/resolver.py` | Path resolver — segment-by-segment with label depth, type filter, FunctionCallView |
36+
| `hcl2/query/pipeline.py` | Pipe operator — `split_pipeline`, `classify_stage`, `execute_pipeline` |
37+
| `hcl2/query/builtins.py` | Built-in transforms: `keys`, `values`, `length` |
38+
| `hcl2/query/diff.py` | Structural diff between two HCL documents |
39+
| `hcl2/query/predicate.py` | `select()` predicate tokenizer, recursive descent parser, evaluator |
40+
| `hcl2/query/safe_eval.py` | AST-validated Python expression eval for hybrid/eval modes |
41+
| `hcl2/query/introspect.py` | `--describe` and `--schema` output generation |
3142

3243
`hcl2/__main__.py` is a thin wrapper that imports `cli.hcl_to_json:main`.
3344

@@ -141,4 +152,4 @@ Hooks are defined in `.pre-commit-config.yaml` (includes black, mypy, pylint, an
141152

142153
## Keeping Docs Current
143154

144-
Update this file when architecture, modules, API surface, or testing conventions change. Also update `README.md` and `docs/usage.md` when changes affect the public API, CLI flags, or option fields.
155+
Update this file when architecture, modules, API surface, or testing conventions change. Also update `README.md` and the docs in `docs/` (`01_getting_started.md`, `02_querying.md`, `03_advanced_api.md`, `04_hq.md`, `05_hq_examples.md`) when changes affect the public API, CLI flags, or option fields.

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ res.block("tags", Name="HelloWorld")
6767
hcl_string = hcl2.dumps(doc.build())
6868
```
6969

70-
For the full API reference, option dataclasses, intermediate pipeline stages, and more examples
71-
see [docs/usage.md](https://github.com/amplify-education/python-hcl2/blob/main/docs/usage.md).
70+
### Documentation
71+
72+
| Guide | Contents |
73+
|---|---|
74+
| [Getting Started](docs/01_getting_started.md) | Installation, load/dump, options, CLI converters |
75+
| [Querying HCL (Python)](docs/02_querying.md) | DocumentView, BlockView, tree walking, view hierarchy |
76+
| [Advanced API](docs/03_advanced_api.md) | Pipeline stages, Builder |
77+
| [hq Reference](docs/04_hq.md) | `hq` CLI — structural queries, hybrid/eval, introspection |
7278

7379
### CLI Tools
7480

75-
python-hcl2 ships two command-line converters:
81+
python-hcl2 ships three command-line tools:
7682

7783
```sh
7884
# HCL2 → JSON
@@ -84,9 +90,13 @@ hcl2tojson terraform/ output/ # converts a directory
8490
jsontohcl2 output.json # prints HCL2 to stdout
8591
jsontohcl2 output.json main.tf # writes to file
8692
jsontohcl2 output/ terraform/ # converts a directory
93+
94+
# Query HCL2 files
95+
hq 'resource.aws_instance.main.ami' main.tf
96+
hq 'variable[*]' variables.tf --json
8797
```
8898

89-
Both commands accept `-` as PATH to read from stdin. Run `hcl2tojson --help` or `jsontohcl2 --help` for the full list of flags.
99+
All commands accept `-` as PATH to read from stdin. Run `--help` on any command for the full list of flags.
90100

91101
## Building From Source
92102

0 commit comments

Comments
 (0)