mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
feat(Errors): Add Pattern suggestion to Unknown Arg Error Message
This commit is contained in:
parent
845a1ce4ed
commit
8d953cab08
3 changed files with 15 additions and 6 deletions
|
@ -852,19 +852,26 @@ impl Error {
|
|||
use_stderr: true,
|
||||
when: color,
|
||||
});
|
||||
|
||||
let suggest_pattern = format!("If you tried to supply `{}` as a PATTERN use `-- {}`", a, a);
|
||||
|
||||
let did_you_mean_message = if did_you_mean.is_empty() {
|
||||
"\n".to_owned()
|
||||
} else {
|
||||
format!("{}\n", did_you_mean)
|
||||
};
|
||||
|
||||
Error {
|
||||
message: format!(
|
||||
"{} Found argument '{}' which wasn't expected, or isn't valid in \
|
||||
this context{}\n\
|
||||
this context{}\
|
||||
{}\n\n\
|
||||
{}\n\n\
|
||||
For more information try {}",
|
||||
c.error("error:"),
|
||||
c.warning(&*a),
|
||||
if did_you_mean.is_empty() {
|
||||
"\n".to_owned()
|
||||
} else {
|
||||
format!("{}\n", did_you_mean)
|
||||
},
|
||||
did_you_mean_message,
|
||||
suggest_pattern,
|
||||
usage,
|
||||
c.good("--help")
|
||||
),
|
||||
|
|
|
@ -9,6 +9,7 @@ use clap::{App, Arg, ArgMatches, ArgSettings, ErrorKind};
|
|||
static DYM: &'static str =
|
||||
"error: Found argument '--optio' which wasn't expected, or isn't valid in this context
|
||||
\tDid you mean --option?
|
||||
If you tried to supply `--optio` as a PATTERN use `-- --optio`
|
||||
|
||||
USAGE:
|
||||
clap-test --option <opt>...
|
||||
|
|
|
@ -46,6 +46,7 @@ For more information try --help";
|
|||
static DYM_ARG: &'static str =
|
||||
"error: Found argument '--subcm' which wasn't expected, or isn't valid in this context
|
||||
\tDid you mean to put '--subcmdarg' after the subcommand 'subcmd'?
|
||||
If you tried to supply `--subcm` as a PATTERN use `-- --subcm`
|
||||
|
||||
USAGE:
|
||||
dym [SUBCOMMAND]
|
||||
|
|
Loading…
Add table
Reference in a new issue