mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Auto merge of #13613 - weihanglo:empty-alias, r=epage
fix(alias): dont panic when resolving an empty alias
This commit is contained in:
commit
d2fbe57b81
@ -148,6 +148,13 @@ fn aliased_command(gctx: &GlobalContext, command: &str) -> CargoResult<Option<Ve
|
||||
let result = user_alias.or_else(|| {
|
||||
builtin_aliases_execs(command).map(|command_str| vec![command_str.1.to_string()])
|
||||
});
|
||||
if result
|
||||
.as_ref()
|
||||
.map(|alias| alias.is_empty())
|
||||
.unwrap_or_default()
|
||||
{
|
||||
anyhow::bail!("subcommand is required, but `{alias_name}` is empty");
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
|
@ -429,3 +429,37 @@ To pass the arguments to the subcommand, remove `--`
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn empty_alias() {
|
||||
let p = project()
|
||||
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.file(
|
||||
".cargo/config.toml",
|
||||
r#"
|
||||
[alias]
|
||||
string = ""
|
||||
array = []
|
||||
"#,
|
||||
)
|
||||
.build();
|
||||
|
||||
p.cargo("string")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] subcommand is required, but `alias.string` is empty
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
||||
p.cargo("array")
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] subcommand is required, but `alias.array` is empty
|
||||
",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user