Skip to content

Commit e5d10f9

Browse files
committed
Implement warning for ignored trailing arguments
in case built-in `cargo` command was invoked with `--`
1 parent aa8b092 commit e5d10f9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/bin/cargo/cli.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use cargo::core::{features, CliUnstable};
22
use cargo::{self, drop_print, drop_println, CliResult, Config};
33
use clap::{AppSettings, Arg, ArgMatches};
4+
use itertools::Itertools;
45

56
use super::commands;
67
use super::list_commands;
@@ -169,6 +170,17 @@ fn expand_aliases(
169170
cmd,
170171
))?;
171172
}
173+
(Some(_), None) => {
174+
// Command is built-in and is not conflicting with alias, but contains ignored values.
175+
if let Some(mut values) = args.values_of("") {
176+
config.shell().warn(format!(
177+
"trailing arguments after built-in command `{}` are ignored: `{}`",
178+
cmd,
179+
values.join(" "),
180+
))?;
181+
}
182+
}
183+
(None, None) => {}
172184
(_, Some(mut alias)) => {
173185
alias.extend(
174186
args.values_of("")
@@ -186,7 +198,6 @@ fn expand_aliases(
186198
let (expanded_args, _) = expand_aliases(config, new_args)?;
187199
return Ok((expanded_args, global_args));
188200
}
189-
(_, None) => {}
190201
}
191202
};
192203

tests/testsuite/cargo_alias_config.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,21 @@ fn global_options_with_alias() {
192192
)
193193
.run();
194194
}
195+
196+
#[cargo_test]
197+
fn weird_check() {
198+
let p = project()
199+
.file("Cargo.toml", &basic_bin_manifest("foo"))
200+
.file("src/main.rs", "fn main() {}")
201+
.build();
202+
203+
p.cargo("-- check --invalid_argument -some-other-argument")
204+
.with_stderr(
205+
"\
206+
[WARNING] trailing arguments after built-in command `check` are ignored: `--invalid_argument -some-other-argument`
207+
[CHECKING] foo v0.5.0 ([..])
208+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
209+
",
210+
)
211+
.run();
212+
}

0 commit comments

Comments
 (0)