mirror of
https://github.com/rust-lang/cargo
synced 2024-09-13 04:51:31 +00:00
Warn when alias shadows external subcommand
As per #10049, we start by emitting a warning when an alias shadows an existing external subcommand. After a transition period (duration not specified), we will make this a hard error.
This commit is contained in:
parent
3a3a071cc8
commit
5bfd345e1d
|
@ -261,6 +261,18 @@ fn expand_aliases(
|
|||
}
|
||||
(None, None) => {}
|
||||
(_, Some(mut alias)) => {
|
||||
// Check if this alias is shadowing an external subcommand
|
||||
// (binary of the form `cargo-<subcommand>`)
|
||||
// Currently this is only a warning, but after a transition period this will become
|
||||
// a hard error.
|
||||
if let Some(path) = super::find_external_subcommand(config, cmd) {
|
||||
config.shell().warn(format!(
|
||||
"user-defined alias `{}` is shadowing an external subcommand found at: `{}`",
|
||||
cmd,
|
||||
path.display(),
|
||||
))?;
|
||||
}
|
||||
|
||||
alias.extend(
|
||||
args.values_of("")
|
||||
.unwrap_or_default()
|
||||
|
|
|
@ -147,12 +147,16 @@ fn list_commands(config: &Config) -> BTreeMap<String, CommandInfo> {
|
|||
commands
|
||||
}
|
||||
|
||||
fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> CliResult {
|
||||
fn find_external_subcommand(config: &Config, cmd: &str) -> Option<PathBuf> {
|
||||
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
|
||||
let path = search_directories(config)
|
||||
search_directories(config)
|
||||
.iter()
|
||||
.map(|dir| dir.join(&command_exe))
|
||||
.find(|file| is_executable(file));
|
||||
.find(|file| is_executable(file))
|
||||
}
|
||||
|
||||
fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> CliResult {
|
||||
let path = find_external_subcommand(config, cmd);
|
||||
let command = match path {
|
||||
Some(command) => command,
|
||||
None => {
|
||||
|
|
Loading…
Reference in a new issue