fix(cli): respect --json flag in all diff output paths#187
Merged
rocketman-code merged 1 commit intomainfrom Mar 9, 2026
Merged
fix(cli): respect --json flag in all diff output paths#187rocketman-code merged 1 commit intomainfrom
rocketman-code merged 1 commit intomainfrom
Conversation
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
93e9b3e to
dc4c435
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
trace --diffsilently ignored the--jsonflag —handle_trace_diffunconditionally calledto_terminal()without checkingargs.jsondiffsubcommand had no--jsonflag at allmain.rsused ad-hocif json { to_json() } else { to_terminal() }patterns, making it easy to forget the json checkFix
report::emit()helper that centralizes json/terminal dispatch — new output paths naturally useemit()rather than ad-hoc if/elsejsonflag through tohandle_trace_diff--jsonflag to thediffsubcommandreport::emit()Note on issue #150
Issue #150 reports that
--diff-fromignores--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— verifiestrace --diff <entry> --jsonproduces valid JSON with expected fieldsdiff_snapshot_json— verifiesdiff <snap_a> <snap_b> --jsonproduces valid JSONcargo clippy --workspace --all-targets -- -D warningscleancargo fmt --checkcleanFixes #150