Skip to content

Commit

Permalink
Implement warning for ignored trailing arguments
Browse files Browse the repository at this point in the history
in case built-in `cargo` command was invoked with `--`
  • Loading branch information
In-line committed Jun 9, 2021
1 parent aa8b092 commit e5d10f9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use cargo::core::{features, CliUnstable};
use cargo::{self, drop_print, drop_println, CliResult, Config};
use clap::{AppSettings, Arg, ArgMatches};
use itertools::Itertools;

use super::commands;
use super::list_commands;
Expand Down Expand Up @@ -169,6 +170,17 @@ fn expand_aliases(
cmd,
))?;
}
(Some(_), None) => {
// Command is built-in and is not conflicting with alias, but contains ignored values.
if let Some(mut values) = args.values_of("") {
config.shell().warn(format!(
"trailing arguments after built-in command `{}` are ignored: `{}`",
cmd,
values.join(" "),
))?;
}
}
(None, None) => {}
(_, Some(mut alias)) => {
alias.extend(
args.values_of("")
Expand All @@ -186,7 +198,6 @@ fn expand_aliases(
let (expanded_args, _) = expand_aliases(config, new_args)?;
return Ok((expanded_args, global_args));
}
(_, None) => {}
}
};

Expand Down
18 changes: 18 additions & 0 deletions tests/testsuite/cargo_alias_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,21 @@ fn global_options_with_alias() {
)
.run();
}

#[cargo_test]
fn weird_check() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("-- check --invalid_argument -some-other-argument")
.with_stderr(
"\
[WARNING] trailing arguments after built-in command `check` are ignored: `--invalid_argument -some-other-argument`
[CHECKING] foo v0.5.0 ([..])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}

0 comments on commit e5d10f9

Please sign in to comment.