Skip to content

feat: --json flag for machine-readable output#30

Open
bionicles wants to merge 1 commit into
mainfrom
rust-json-flag
Open

feat: --json flag for machine-readable output#30
bionicles wants to merge 1 commit into
mainfrom
rust-json-flag

Conversation

@bionicles

Copy link
Copy Markdown
Owner

Item 2 of the post-port roadmap; directly requested in #7 ("add a --json flag for structured output").

What

  • TreePlus::to_json() in core: nested JSON objects with category, name, aggregated n_folders/n_files/n_lines/n_tokens, components on file nodes, subtrees on container nodes.
  • -j/--json on the CLI: prints the JSON document (pretty, deterministic) instead of the rendered tree; no footer noise, so stdout parses directly with jq/json.loads.
  • Composes with existing flags (--concise empties components, --ignore/--glob filter as usual).

Example

tprs --json tests/path_to_test | jq '.subtrees[] | select(.name=="file.py").components'

Tests

Two CLI integration tests: document parses, root/aggregate fields correct, file nodes carry components and no subtrees; --concise empties components. 83 tests total, stable clippy -D warnings clean.

🤖 Generated with Claude Code

Adds TreePlus::to_json() (nested objects with category, name, aggregated
counts, components on file nodes, subtrees on containers) and a
-j/--json CLI flag that prints the JSON document instead of the rendered
tree and footer. Requested in issue #7; makes tprs scriptable in
pipelines (jq, LLM tooling) without parsing the unicode render.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant