mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
fix(error): Include -- in more cases
Inspired by rust-lang/cargo#12494. Part of this is that our "did you mean" does prefix checks so it can be overly aggressive in providing suggestions. To avoid providing needless suggestions I limited this change to `last` / `trailing_var_arg` as those convey that `--` is more likely a valid suggestion.
This commit is contained in:
parent
7de6df8782
commit
446328a8d3
2 changed files with 9 additions and 2 deletions
|
@ -1570,10 +1570,16 @@ impl<'cmd> Parser<'cmd> {
|
|||
.collect();
|
||||
|
||||
// `did_you_mean` is a lot more likely and should cause us to skip the `--` suggestion
|
||||
// with the one exception being that the CLI is trying to capture arguments
|
||||
//
|
||||
// In theory, this is only called for `--long`s, so we don't need to check
|
||||
let suggested_trailing_arg =
|
||||
did_you_mean.is_none() && !trailing_values && self.cmd.has_positionals();
|
||||
let suggested_trailing_arg = (did_you_mean.is_none()
|
||||
|| self
|
||||
.cmd
|
||||
.get_positionals()
|
||||
.any(|arg| arg.is_last_set() || arg.is_trailing_var_arg_set()))
|
||||
&& !trailing_values
|
||||
&& self.cmd.has_positionals();
|
||||
ClapError::unknown_argument(
|
||||
self.cmd,
|
||||
format!("--{arg}"),
|
||||
|
|
|
@ -165,6 +165,7 @@ fn suggest_trailing_last() {
|
|||
error: unexpected argument '--ignored' found
|
||||
|
||||
tip: a similar argument exists: '--ignore-rust-version'
|
||||
tip: to pass '--ignored' as a value, use '-- --ignored'
|
||||
|
||||
Usage: cargo --ignore-rust-version [-- <TESTNAME>]
|
||||
|
||||
|
|
Loading…
Reference in a new issue