feat: Add info cargo subcommand#14141
Conversation
|
I remembered last time when we imported new commands we insta-stablized them ( If the Cargo team are happy with making this a built-in command, I suppose we could do the same thing. |
f582df0 to
476969f
Compare
791dad8 to
242919d
Compare
Added. Thank you! |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
|
@epage @weihanglo I guess this PR is ready to merge. Could you please help merge it when you have time? If there is anything I need to update, please let me know. @epage Thank you for guiding me in this work, I really appreciate it. Thank you for all your time. |
weihanglo
left a comment
There was a problem hiding this comment.
I didn't look too closer to the implementation. That seems pretty solid. Thank you hi-rustin!
|
|
||
| _crate_`@`_version_: Fetch from a registry with a version constraint of "_version_" | ||
|
|
||
| If the specified package is part of the current workspace, the information from the local Cargo.toml file will be |
There was a problem hiding this comment.
How do we override the local query with registry query? This guide doesn't talk about that. Should we mention it or put an example for this use case?
There was a problem hiding this comment.
You can specify a specific version(a different version) or you need to check it out of the workspace. I guess it's okay to not mention it. I believe checking it out of the workspace is quite straightforward.
| return (Some(package_id), false); | ||
| } | ||
|
|
||
| if let Some(package_id) = ws |
There was a problem hiding this comment.
I understand that we handle duplicate package by max_by regardless MSRV of globally maximum. Should we have something reminding user when a query is ambiguous?
There was a problem hiding this comment.
I'm not sure if we should mention this detail here. From the start, I provided all the details about how we select a package, but Ed thought it was too detailed. He believes it might create more work if we want to change these implementation details.
|
I tried giving this a spin, and was very surprised to find that it was requesting my token for crates.io. Is there a reason it must do that? That seems like it will be a bad user experience if someone needs to enter a password or use a biometric or hardware key in order to use this command. |
I will take a look. It shouldn't require it. I remember I fixed it in my previous local test. |
|
I tested it locally: ❯ ./target/debug/cargo logout
Logout token for `crates-io` has been removed from local storage
note: This does not revoke the token on the registry server.
If you need to revoke the token, visit <https://crates.io/me> and follow the instructions there.
cargo on rustin-patch-info is 📦 v0.83.0 via 🐍 v3.12.4 via 🦀 v1.82.0-nightly
❯ ./target/debug/cargo info serde
serde #serde #serialization #no_std
A generic serialization/deserialization framework
version: 1.0.204
license: MIT OR Apache-2.0
rust-version: 1.31
documentation: https://docs.rs/serde
homepage: https://serde.rs
repository: https://github.com/serde-rs/serde
crates.io: https://crates.io/crates/serde/1.0.204
features:
+default = [std]
std = []
alloc = []
derive = [serde_derive]
rc = []
serde_derive = [dep:serde_derive]
unstable = []
note: to see how you depend on serde, run `cargo tree --invert --package serde@1.0.204`It seemed it doesn't require it. |
156c865 to
a4c7dfc
Compare
0xPoe
left a comment
There was a problem hiding this comment.
🔢 Self-check (PR reviewed by myself and ready for feedback.)
|
I also logged out and couldn't reproduce. As we develop reproduction steps, we can iterate from there. @bors r+ |
|
☀️ Test successful - checks-actions |
1 similar comment
|
☀️ Test successful - checks-actions |
|
👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request. |
|
Opened #14409 regarding the authentication problem. |
close #14081
close #948
fcp #14141 (comment)
This PR added a new
infocargo subcommand.Background
This adds a new subcommand to Cargo,
cargo info. This subcommand would allow users to get information about a crate from the command line, without having to go to the web.The main motivation for this is to make it easier to get information about a crate from the command line. Currently, the way to get information about a crate is to go to the web and look it up on crates.io or find the crate's source code and look at the
Cargo.tomlfile. This is not very convenient, especially not all information is displayed on the crates.io page.This command also has been requested by the community for a long time. You can find more discussion about this in cargo#948.
Another motivation is to make the workflow of finding and evaluating crates more efficient. In the current workflow, users can search for crates using
cargo search, but then they have to go to the web to get more information about the crate. This is not very efficient, especially if the user is just trying to get a quick overview of the crate. This would allow users to quickly get information about a crate without having to leave the terminal.Example usage:
note: this is showing the
--verboseoutput to show every thing the user can possibly see. Normal operation does not includeDetailed design
cargo tree --invert --package clap@4.5.8Rendering features
Rendering deps
Only show dependencies in verbose mode.
Some important notes
Downloading the crate from any Cargo compatible registry
The
cargo infocommand will download the crate from any Cargo compatible registry. It will then extract the information from theCargo.tomlfile and display it in the terminal.If the crate is already in the local cache, it will not download the crate again. It will get the information from the local cache.
Pick the correct version from the workspace
When executed in a workspace directory, the cargo info command chooses the version that the workspace is currently using.
If there's a lock file available, the version from this file will be used. In the absence of a lock file, the command attempts to select a version that is compatible with the Minimum Supported Rust Version (MSRV). And the lock file will be generated automatically.
The following hierarchy is used to determine the MSRV:
Prior art
NPM
npm has a similar command called
npm info.For example:
Poetry
Poetry has a similar command called
poetry show.For example:
insta-stable
As @weihanglo mentioned in #14141 (comment), commands that shadow third-party commands tend to be insta-stabilized to avoid an intermediate period where users can't access the third-party command (built-ins get priority) nor the built-in command (requires nightly)
For the cargo-info command, there are two commands that this would shadow
We might be able to get away with having this unstable but starting from the assumption of insta-stabilization.