Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
34 changes: 34 additions & 0 deletions tests/testsuite/cargo_alias_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}