Skip to content

Commit 11fd9a5

Browse files
agent-friendly conversion CLIs (#274)
1 parent dc0fcc5 commit 11fd9a5

13 files changed

Lines changed: 3427 additions & 177 deletions

CLAUDE.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,52 @@ Follows the `json` module convention. All option parameters are keyword-only.
8080

8181
## CLI
8282

83-
Console scripts defined in `pyproject.toml`. Each uses argparse flags that map directly to the option dataclass fields above.
83+
Console scripts defined in `pyproject.toml`. All three CLIs accept positional `PATH` arguments (files, directories, glob patterns, or `-` for stdin). When no `PATH` is given, stdin is read by default (like `jq`).
8484

85+
### Exit Codes
86+
87+
All CLIs use structured error output (plain text to stderr) and distinct exit codes:
88+
89+
| Code | `hcl2tojson` | `jsontohcl2` | `hq` |
90+
|------|---|---|---|
91+
| 0 | Success | Success | Success |
92+
| 1 | Partial (some skipped) | JSON/encoding parse error | No results |
93+
| 2 | All unparsable | Bad HCL structure | Parse error |
94+
| 3 ||| Query error |
95+
| 4 | I/O error | I/O error | I/O error |
96+
| 5 || Differences found (`--diff` / `--semantic-diff`) ||
97+
98+
### `hcl2tojson`
99+
100+
```
101+
hcl2tojson file.tf # single file to stdout
102+
hcl2tojson --ndjson dir/ # directory → NDJSON to stdout
103+
hcl2tojson a.tf b.tf -o out/ # multiple files to output dir
104+
hcl2tojson --ndjson 'modules/**/*.tf' # glob + NDJSON streaming
105+
hcl2tojson --only resource,module file.tf # block type filtering
106+
hcl2tojson --exclude variable file.tf # exclude block types
107+
hcl2tojson --fields cpu,memory file.tf # field projection
108+
hcl2tojson --compact file.tf # single-line JSON
109+
hcl2tojson -q dir/ -o out/ # quiet (no stderr progress)
110+
echo 'x = 1' | hcl2tojson # stdin (no args needed)
85111
```
86-
hcl2tojson --json-indent 2 --with-meta file.tf
112+
113+
Key flags: `--ndjson`, `--compact`, `--only`/`--exclude`, `--fields`, `-q`/`--quiet`, `--json-indent N`, `--with-meta`, `--with-comments`, `--strip-string-quotes` (breaks round-trip). Multi-file NDJSON adds a `__file__` provenance key to each object.
114+
115+
### `jsontohcl2`
116+
117+
```
118+
jsontohcl2 file.json # single file to stdout
119+
jsontohcl2 --diff original.tf modified.json # preview text changes
120+
jsontohcl2 --semantic-diff original.tf modified.json # semantic-only changes
121+
jsontohcl2 --semantic-diff original.tf --diff-json m.json # semantic diff as JSON
122+
jsontohcl2 --dry-run file.json # convert without writing
123+
jsontohcl2 --fragment - # attribute snippets from stdin
87124
jsontohcl2 --indent 4 --no-align file.json
88125
```
89126

127+
Key flags: `--diff ORIGINAL`, `--semantic-diff ORIGINAL`, `--diff-json`, `--dry-run`, `--fragment`, `-q`/`--quiet`, `--indent N`, `--no-align`, `--colon-separator`.
128+
90129
Add new options as `parser.add_argument()` calls in the relevant entry point module.
91130

92131
## PostLexer (`postlexer.py`)

0 commit comments

Comments
 (0)