feat(Errors): Add Pattern suggestion to Unknown Arg Error Message

This commit is contained in:
Ross Harrison 2019-07-01 11:01:11 -05:00
parent 845a1ce4ed
commit 8d953cab08
3 changed files with 15 additions and 6 deletions

View file

@ -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")
),

View file

@ -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>...

View file

@ -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]