-
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
List available packages if providing --package
with an empty value
#8808
Conversation
r? @Eh2406 (rust_highfive has picked a reviewer for you, use r? to override) |
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.
Thanks! Looks useful!
I noticed that some commands do not seem to correctly validate the argument with this change. clean
, tree
, uninstall
, and update
will silently run with a -p
argument without a value, when they should return an error. Can you adjust those so that they will fail (and preferably print out an available list)?
I also noticed that the single-argument commands (rustc
, rustdoc
, pkgid
, and run
) don't print the available list. I won't block the PR if you don't want to add them, but I think it would be nice.
Finally, I'm a little concerned that this might contribute some confusion. In most cases, the -p
argument can accept any package in the resolve graph, not just workspace members. However, I think listing everything would be too noisy. I'm not sure how to improve that. Maybe if it said "Available workspace members:" or something like that?
src/cargo/util/workspace.rs
Outdated
fn print_availables(output: String, availables: &[&str], plural_name: &str) -> CargoResult<()> { | ||
let mut output = output; |
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.
fn print_availables(output: String, availables: &[&str], plural_name: &str) -> CargoResult<()> { | |
let mut output = output; | |
fn print_availables(mut output: String, availables: &[&str], plural_name: &str) -> CargoResult<()> { |
src/cargo/util/workspace.rs
Outdated
let mut output = String::new(); | ||
writeln!( | ||
output, | ||
"\"--package <SPEC>\" requires a SPEC format value.\n\ | ||
Run `cargo help pkgid` for more infomation about SPEC 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.
let mut output = String::new(); | |
writeln!( | |
output, | |
"\"--package <SPEC>\" requires a SPEC format value.\n\ | |
Run `cargo help pkgid` for more infomation about SPEC format." | |
)?; | |
let output = "\"--package <SPEC>\" requires a SPEC format value.\n\ | |
Run `cargo help pkgid` for more infomation about SPEC format.\n" | |
.to_string(); |
Oh I see. I was thinking that the only accept one package so showing a list does not help. But I was wrong. It still benefits 😂. Will fix it.
That’s also what I was concerned about, therefore I decided to add a help message guiding people to learn more about pkgid. Showing "Available workspace members:" seems very straightforward. However, if a single-package crate shows message like that, would it confuses user about workspace/package, though both kind of compilations can get workspace information internally in cargo. Would this be better?
|
Looks good, thanks! |
📌 Commit 4b9c503 has been approved by |
☀️ Test successful - checks-actions |
May resolves #8591
How
First we need to take the responsibility of check command line arguments from claps. I've examine all 10 build commands and all of them call
ArgMatchesExt::compile_options
directly or indirectly. Andcompile_options
callscheck_optional_opts
to check if target selection options given an empty value. So we can do the same logic there.I've also add a error message for an edge case though that one would never trigger at this moment.