Skip to content

fix(cli): respect --json flag in all diff output paths#187

Merged
rocketman-code merged 1 commit intomainfrom
fix/issue-150
Mar 9, 2026
Merged

fix(cli): respect --json flag in all diff output paths#187
rocketman-code merged 1 commit intomainfrom
fix/issue-150

Conversation

@rocketman-code
Copy link
Owner

Summary

  • trace --diff silently ignored the --json flag — handle_trace_diff unconditionally called to_terminal() without checking args.json
  • The diff subcommand had no --json flag at all
  • All 7 output paths in main.rs used ad-hoc if json { to_json() } else { to_terminal() } patterns, making it easy to forget the json check

Fix

  • Add report::emit() helper that centralizes json/terminal dispatch — new output paths naturally use emit() rather than ad-hoc if/else
  • Pass json flag through to handle_trace_diff
  • Add --json flag to the diff subcommand
  • Convert all output sites to use report::emit()

Note on issue #150

Issue #150 reports that --diff-from ignores --json. This was already fixed in commit 2ea1fe6. However, --diff (a different flag) had the same class of bug — this PR fixes that and adds structural prevention.

Test plan

  • trace_diff_json — verifies trace --diff <entry> --json produces valid JSON with expected fields
  • diff_snapshot_json — verifies diff <snap_a> <snap_b> --json produces valid JSON
  • All existing tests pass (cargo test --workspace: 276+ tests)
  • cargo clippy --workspace --all-targets -- -D warnings clean
  • cargo fmt --check clean
  • Pre-commit hook passes

Fixes #150

trace --diff unconditionally called to_terminal() without checking
args.json, silently ignoring the --json flag. The diff subcommand
also lacked a --json flag entirely.

Add report::emit() helper that centralizes the json/terminal dispatch
pattern, converting all 7 output sites to use it. This makes the
pattern structural: new output paths naturally use emit() rather than
ad-hoc if/else that can forget the json check.

Changes:
- Pass json flag through to handle_trace_diff
- Add --json flag to the diff subcommand (Commands::Diff, finish_diff)
- Add report::emit() to centralize json/terminal output dispatch
- Convert all output sites in run_trace, run_packages, handle_trace_diff,
  and finish_diff to use report::emit()
- Add integration tests: trace_diff_json, diff_snapshot_json

Fixes #150
@rocketman-code rocketman-code merged commit 6f1477d into main Mar 9, 2026
8 checks passed
@rocketman-code rocketman-code deleted the fix/issue-150 branch March 9, 2026 03:25
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.

bug(cli): --diff-from silently ignores --json flag

1 participant