Skip to content

Implement --json flag for compact machine-readable output - #42

Merged
randileeharper merged 1 commit into
mainfrom
fix/cli-json-flag-dead-27
Jul 1, 2026
Merged

Implement --json flag for compact machine-readable output#42
randileeharper merged 1 commit into
mainfrom
fix/cli-json-flag-dead-27

Conversation

@randileeharper

Copy link
Copy Markdown
Owner

Summary

The --json flag (historian/cli.py) was parsed into args.as_json but never referenced — _print() always emitted indented JSON with indent=2. This was dead code from a planned feature that was never wired up.

Changes

  • historian/cli.py: Added a module-level _compact_json flag set from args.as_json in main(). _print() now outputs compact minified JSON (separators=(",", ":"), no indentation) when --json is passed, and indented JSON (indent=2) otherwise. Added a help string to the --json argument.
  • tests/test_cli.py: Two new tests:
    • test_default_output_is_indented — verifies default output has newlines and indentation.
    • test_json_flag_produces_compact_output — verifies --json produces single-line minified JSON.

Closes #27.

Test commands run

uv run pytest -q
uv run python -m compileall historian tests

All 84 tests pass; compile check clean.

The --json flag was parsed but never read — _print always emitted
indented JSON. When --json is passed, output is now compact minified
JSON (separators=(',',':')) suitable for piping to jq or scripts.
Without the flag, output remains indented as before.

Closes #27.
@randileeharper
randileeharper merged commit 9518375 into main Jul 1, 2026
1 check passed
@randileeharper
randileeharper deleted the fix/cli-json-flag-dead-27 branch July 1, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI --json flag is parsed but never read

1 participant