Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement warning for ignored trailing arguments #9561

Merged
merged 1 commit into from
Jun 10, 2021
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
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!(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an error would be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehuss It can break backward compatability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're concerned about back compat, that's fine too. It can always be changed to an error in the future if desired.

"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();
}