-
Notifications
You must be signed in to change notification settings - Fork 2.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
cargo info
reads local crate instead of crates.io when running from the crate directory
#14810
Comments
@Rustin170506 unsure how to word the documentation besides just not saying where its coming from. |
Then I'm assuming the intent is to prefer the local crate if it exists. That's already good to know, because then I know I can always specify |
Yes, it was intentional though I don't remember why we chose that behavior. Another aspect dependent on your local project is what version is shown. It will prefer versions in your lockfile (and maybe also versions compatible with your MSRV?). This is purely meant to be a UX command and tries to give the information that can be assumed to be most helpful for the user.
If you are parsing the output, understand that the output is not a stable format intended for programmatic use. We can change pretty much anything about it without it being a breaking change. |
Ok, that would be an issue. However, with some quick testing, it seems that using
Yes, this is fine by me. I checked for a -cargo search "$name" | sed -n '1s/^'"$name"' = "\([0-9.]*\)".*$/\1/p'
+cargo info --registry=crates-io -q "$name" | sed -n 's/^version: //p' |
|
How about this? NAME
cargo-info — Display information about a package in the registry or a local crate. Default registry is crates.io
DESCRIPTION
This command displays information about a package in the registry or a local crate. It fetches data from the package’s
Cargo.toml file and presents it in a human-readable format. |
Thanks for the link! But this doesn't really contain a rationale for the current behavior though. Even Rustin170506/cargo-information#66 doesn't. It seems the history was (AFAICT):
The closest thing I found to a rationale is Rustin170506/cargo-information#66 (comment) but I'm not sure I interpret it correctly (I'm interpreting it as "we don't want to contact crates.io with a crate name if it happens to not have been published yet"). Is it possible to point to the rationale (if my archeology skills are failing) or document it here (otherwise)? |
I think we should probably be more brief in the Also iirc, we support a |
Actually, the documentation of
The user would then have to read further the documentation of
If we want, we can modify the description to say that what is meant by "the package" is contextual and depends on whether the package is part of the current workspace. But I don't think this is needed. |
Seems fine with me |
Problem
I naively expected that
cargo info
would always show information from crates.io (as its documentation suggests). However, it seems thatcargo info foo-bar
would not show information from crates.io if running from the directory of cratefoo-bar
itself. One has to explicitly pass--registry=crates-io
to obtain information from crates.io.Steps
Cargo.toml
file.cargo info foo-bar
(wherefoo-bar
is thepackage.name
value in theCargo.toml
file).Expected: It will contact crates.io and show information from there.
Actual: It reads and show information from the local crate.
Possible Solution(s)
Either update the documentation to mention that local crate is favored. Or always fetch from crates.io.
Notes
cargo help info
shows:It mentions things like
package
(something published on crates.io) andcrates.io
. It doesn't say that it will read the local file system.Version
The text was updated successfully, but these errors were encountered: