feat(cli): add --output to write the JSON report to a file - #174
Merged
Muawiya-contact merged 1 commit intoSep 14, 2026
Merged
Conversation
Issue Coding-Moves#166. Large scans already emit a full JSON report, but the only destination was stdout — fine for a pipe into jq, awkward when the report is megabytes and the goal is to keep it. `diskern scan <dir> --json --output <file>` writes the same pretty document to the file instead of printing it; stdout stays empty and a confirmation goes to stderr, so the command composes in scripts either way. The flag requires --json (clap rejects it otherwise, exit 2) because it has no meaning in the human-readable path, and a failed write surfaces the path plus the OS error rather than a bare io failure. End-to-end tests pin the file carrying exactly what --json would print, the rejection without --json, and the exit-1 error on an unwritable path.
Muawiya-contact
approved these changes
Sep 14, 2026
Muawiya-contact
left a comment
Member
There was a problem hiding this comment.
Thanks for contributing again, Louis! The JSON export meets #166, keeps stdout clean, and handles invalid arguments and write failures clearly. I reviewed the implementation and regression tests, and current CI is green; approved. Local Rust tests were blocked by a missing C linker, so Rust validation relies on the passing CI runs.
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.
What & why
Closes #166.
Large scans already emit a full JSON report, but the only destination was stdout — fine for a pipe into
jq, awkward when the report is megabytes and the goal is to keep it.diskern scan <dir> --json --output <file>writes the same pretty-printed document to the file instead of printing it. Decisions a reviewer might otherwise have to guess:--output. The issue's motivation is avoiding huge terminal output, so teeing to both would defeat the point. A one-lineWrote JSON report to …confirmation goes to stderr, matching how--rulesalready announces its external database — it can't corrupt a pipe.--outputrequires--json(claprequires, exit 2). The issue offered "reject clearly or document"; rejecting is the clearer contract since the flag has no meaning in the human-readable path. Happy to switch to implying--jsonif you'd rather.load_rules.Docs: added the flag to the CLI README usage examples and flag table.
Checklist
cargo fmt --allandcargo clippy --workspaceare clean (ran-p diskern-core -p diskern-cli --all-targets -- -D warnings; workspace clippy needs the desktop webview deps)cargo test --workspacepasses (ran-p diskern-core -p diskern-cli: 99 + all cli tests; 3 new e2e tests)changelog.d/