Merge pull request #1019 from wabain/fix-flag-after-subcommand-suggestion

Fix suggestions for flags under subcommands
This commit is contained in:
Kevin K 2017-08-14 22:41:36 -04:00 committed by GitHub
commit 05aec692cb
2 changed files with 7 additions and 6 deletions

View file

@ -58,9 +58,10 @@ pub fn did_you_mean_flag_suffix<'z, T, I>(arg: &str, longs: I, subcommands: &'z
if let Some(candidate) = did_you_mean(arg, opts) {
let suffix = format!(
"\n\tDid you mean to put '--{}' after the subcommand '{}'?",
Format::Good(arg),
Format::Good(candidate));
"\n\tDid you mean to put '{}{}' after the subcommand '{}'?",
Format::Good("--"),
Format::Good(candidate),
Format::Good(subcommand.get_name()));
return (suffix, Some(candidate));
}
}

View file

@ -43,8 +43,8 @@ USAGE:
For more information try --help";
#[cfg(feature = "suggestions")]
static DYM2: &'static str = "error: Found argument '--subcmdarg' which wasn't expected, or isn't valid in this context
\tDid you mean to put '--subcmdarg' after the subcommand 'subcmdarg'?
static DYM2: &'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'?
USAGE:
clap-test [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND]
@ -130,7 +130,7 @@ fn multiple_aliases() {
#[cfg(feature="suggestions")]
fn subcmd_did_you_mean_output() {
assert!(test::compare_output(test::complex_app(), "clap-test subcm", DYM, true));
assert!(test::compare_output(test::complex_app(), "clap-test --subcmdarg foo", DYM2, true));
assert!(test::compare_output(test::complex_app(), "clap-test --subcm foo", DYM2, true));
}
#[test]