Skip to content

jsontohcl2: --fragment and --dry-run are unnecessarily mutually exclusive #292

@kkozik-amplify

Description

@kkozik-amplify

Description

echo '{"cpu": 2048}' | jsontohcl2 - --fragment --dry-run
# → error: argument --dry-run: not allowed with argument --fragment

--fragment alone works fine and already outputs to stdout (same behavior as --dry-run), so the restriction is unexpected.

Root Cause

In cli/json_to_hcl.py (lines 138-160), all four flags (--diff, --dry-run, --semantic-diff, --fragment) are in a single add_mutually_exclusive_group(). This was intentional (test at line 247 validates it with "Fix #5" comment), but the grouping is overly broad.

--diff and --semantic-diff are properly exclusive (different comparison modes requiring different inputs). But --fragment is a conversion mode (how to convert), not an output mode (where to write). Combining --fragment --dry-run is redundant since --fragment already outputs to stdout, but it shouldn't be an error.

Expected Behavior

--fragment --dry-run should either work (producing the same output as --fragment alone) or --fragment should be an orthogonal flag separate from the output mode group.

Workaround

Use --fragment without --dry-run — the output is identical.

Suggested Fix

Move --fragment out of the mutually exclusive group and make it an orthogonal conversion-mode flag. Keep --diff, --dry-run, --semantic-diff in the exclusive group as proper output modes.

Metadata

Metadata

Labels

bugSomething isn't workingclihcl2tojson, jsontohcl2, and hq CLIsinternal-testingFound during internal test runs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions