Skip to content

feat: add support for json flag#218

Open
mgi388 wants to merge 5 commits intobnjbvr:mainfrom
mgi388:json-flag
Open

feat: add support for json flag#218
mgi388 wants to merge 5 commits intobnjbvr:mainfrom
mgi388:json-flag

Conversation

@mgi388
Copy link

@mgi388 mgi388 commented Jan 19, 2026

Fixes #217.

Copy link
Owner

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. One small comment and one question, and this should be good to go!

src/main.rs Outdated
Comment on lines 160 to 164
if !args.json {
eprintln!("Analyzing dependencies of crates in this directory...");
}
args.paths.push(PathBuf::from("."));
} else {
} else if !args.json {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these if !args.json required? The fact the tool is outputting with eprintln means this is going to stderr, and a user emitting JSON would likely be fine piping from stdout, so I think we could keep the stderr output as is. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and made this change (and have pushed the commits), however I think we want to go back to something like I had originally. Look at: https://doc.rust-lang.org/std/macro.eprintln.html

Use eprintln! only for error and progress messages. Use println! instead for the primary output of your program.

When not in --json mode, the primary output is what it used to print, and so that should use println!. So even

eprintln!("Analyzing dependencies of crates in this directory...");

Should change to use just println! according to that.

Now, if we do that, we cannot output both JSON and plain text, so I think I'll need to make a change to make it either or.

  1. If --json flag is on, then it will only print JSON to stdout (using println!).
  2. Else, then it will only print the plain text it previously printed to stdout (using println!).

I will wait to hear back before I make this change though.

@mgi388 mgi388 requested a review from bnjbvr January 22, 2026 04:16

if args.version {
println!("{}", env!("CARGO_PKG_VERSION"));
eprintln!("{}", env!("CARGO_PKG_VERSION"));
Copy link
Author

@mgi388 mgi388 Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Printing the version should go to stdout, so this change is wrong and will need to be reverted one way or another in this PR.

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.

Interest in a PR for --json flag to support a VS Code extension?

2 participants