Skip to content

Commit 8f8a79a

Browse files
committed
fix(cli): Error trailing args rather than ignore
This warning has been in for a sufficient time, requires a hack from clap to avoid all argument ID validation, and allows users to run the wrong command (imagine `cargo -- publish --dry-run`). See also https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Cargo.20ignoring.20arguments.20with.20.60cargo.20--.20check.20--ignored.60
1 parent 8dea819 commit 8f8a79a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/bin/cargo/cli.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,15 @@ fn expand_aliases(
242242
(Some(_), None) => {
243243
// Command is built-in and is not conflicting with alias, but contains ignored values.
244244
if let Some(mut values) = args.get_many::<String>("") {
245-
config.shell().warn(format!(
246-
"trailing arguments after built-in command `{}` are ignored: `{}`",
245+
return Err(anyhow::format_err!(
246+
"\
247+
trailing arguments after built-in command `{}` are unsupported: `{}`
248+
249+
To pass the arguments to the subcommand, remove `--`",
247250
cmd,
248251
values.join(" "),
249-
))?;
252+
)
253+
.into());
250254
}
251255
}
252256
(None, None) => {}

tests/testsuite/cargo_alias_config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,12 @@ fn weird_check() {
324324
.build();
325325

326326
p.cargo("-- check --invalid_argument -some-other-argument")
327+
.with_status(101)
327328
.with_stderr(
328329
"\
329-
[WARNING] trailing arguments after built-in command `check` are ignored: `--invalid_argument -some-other-argument`
330-
[CHECKING] foo v0.5.0 ([..])
331-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
330+
[ERROR] trailing arguments after built-in command `check` are unsupported: `--invalid_argument -some-other-argument`
331+
332+
To pass the arguments to the subcommand, remove `--`
332333
",
333334
)
334335
.run();

0 commit comments

Comments
 (0)