mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
fix(alias): Aliases without subcommands should not panic
This commit is contained in:
parent
b9d913e532
commit
45851ef31e
@ -356,7 +356,13 @@ For more information, see issue #12207 <https://github.com/rust-lang/cargo/issue
|
||||
let global_args = GlobalArgs::new(sub_args);
|
||||
let new_args = cli(gctx).no_binary_name(true).try_get_matches_from(alias)?;
|
||||
|
||||
let new_cmd = new_args.subcommand_name().expect("subcommand is required");
|
||||
let Some(new_cmd) = new_args.subcommand_name() else {
|
||||
return Err(anyhow!(
|
||||
"subcommand is required, add a subcommand to the command alias `alias.{cmd}`"
|
||||
)
|
||||
.into());
|
||||
};
|
||||
|
||||
already_expanded.push(cmd.to_string());
|
||||
if already_expanded.contains(&new_cmd.to_string()) {
|
||||
// Crash if the aliases are corecursive / unresolvable
|
||||
|
@ -463,3 +463,27 @@ fn empty_alias() {
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn alias_no_subcommand() {
|
||||
let p = project()
|
||||
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.file(
|
||||
".cargo/config.toml",
|
||||
r#"
|
||||
[alias]
|
||||
a = "--locked"
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("a")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] subcommand is required, add a subcommand to the command alias `alias.a`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user