-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support json output for outdated command #27271
base: main
Are you sure you want to change the base?
Conversation
Supports json output for the outdated command. This is useful for automated tools that need to parse the output of the outdated command. The json output can be specified using the `--output json` flag.
This change-set also updates a small typo in the `--recursive` flag help text. The first word should have been capitalized.
To be consistent with print_outdated_table, use the println! macro to print the output.
Arg::new("json") | ||
.long("json") | ||
.action(ArgAction::SetTrue) | ||
.help("Output outdated packages in JSON format") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the other --json
flags, we've wanted to require people to specify the version of json output that they want similar to what Rust requires. This allows us to break the output over time while maintaining backwards compatibility.
If adding this flag, we should probably proactively do that here, but I'm not sure what that would look like. There's an open issue for this somewhere I think, but it's hard to search for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that it would be specified on the cmd line, something like --json v1
?
I just checked what npm outdated --json
does and here is an example of the output it uses:
{
"@types/node": {
"current": "20.11.30",
"wanted": "20.17.9",
"latest": "22.10.1",
"dependent": "deno-astro-adapter",
"location": "/Users/irbull/git/deno/deno-astro-adapter/node_modules/@types/node"
},
...
Do you think we should align with that format? It's a bit different, particularly that the package is the key.
match output_fmt { | ||
OutdatedOutputFmt::Table => print_outdated_table(&outdated), | ||
OutdatedOutputFmt::Json => { | ||
let json = serde_json::to_string_pretty(&outdated)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this feature is added, we should use object notation and then include a version number (ex. "1"), similar to the other --json
output. That allows adding new properties in the future in a backwards compatible way and also attaches a version to the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Let's hammer out the format first (see above) and then we can add a version field. Typically semantic version I guess (like 1.0.0)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a single integer is fine. Additions fall under the same version, but breaking changes cause a version bump. Otherwise people need to parse the version with something like std/semver
to see if they can understand it rather than just doing an equality check.
Introduce JSON output for the
outdated
command via the--json
flag. This enables automated tools to easily parse and process the command's output.Additionally, update the
--recursive
flag's help text to capitalize the first word, ensuring consistency with other command descriptions.