List available packages if providing --package with an empty value#8808
List available packages if providing --package with an empty value#8808bors merged 12 commits intorust-lang:masterfrom
--package with an empty value#8808Conversation
|
r? @Eh2406 (rust_highfive has picked a reviewer for you, use r? to override) |
ehuss
left a comment
There was a problem hiding this comment.
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.
| 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.
| 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_optionsdirectly or indirectly. Andcompile_optionscallscheck_optional_optsto 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.