Skip to content

Commit

Permalink
fix(did-you-mean): for review
Browse files Browse the repository at this point in the history
* unknown subcommand message altered to use similar language as is used
  everywhere around clap. Namely, we say 'invalid' instead of 'unknown'
* 'did-you-mean' message separator changed from '. ' to '\n\t'

Related to #103
  • Loading branch information
Byron authored and kbknapp committed May 5, 2015
1 parent 3631de5 commit 0535cfb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions clap-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@
help Prints this message
subcmd tests subcommands'''

_sc_dym_usage = '''Subcommand "subcm" is unknown. Did you mean "subcmd" ?
_sc_dym_usage = '''Subcommand "subcm" isn't valid
\tDid you mean "subcmd" ?
USAGE:
\tclaptests [POSITIONAL] [FLAGS] [OPTIONS] [SUBCOMMANDS]
For more information try --help'''

_arg_dym_usage = '''The argument --optio isn't valid. Did you mean --option ?
_arg_dym_usage = '''The argument --optio isn't valid
\tDid you mean --option ?
USAGE:
\tclaptests
For more information try --help'''

_pv_dym_usage = '''"slo" isn't a valid value for '--Option <option3>'
\t[valid values: fast slow]. Did you mean "slow" ?
\t[valid values: fast slow]
\tDid you mean "slow" ?
USAGE:
\tclaptests --Option <option3>
For more information try --help'''
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
I: IntoIterator<Item=&'z T> {
match did_you_mean(arg, values) {
Some(candidate) => {
let mut suffix = ". Did you mean ".to_string();
let mut suffix = "\n\tDid you mean ".to_string();
match style {
DidYouMeanMessageStyle::LongFlag => suffix.push_str("--"),
DidYouMeanMessageStyle::EnumValue => suffix.push('"'),
Expand Down Expand Up @@ -1371,7 +1371,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{

if let Some(candidate_subcommand) = did_you_mean(&arg, self.subcommands.keys()) {
self.report_error(
format!("Subcommand \"{}\" is unknown. Did you mean \"{}\" ?",
format!("Subcommand \"{}\" isn't valid\n\tDid you mean \"{}\" ?",
arg,
candidate_subcommand),
true,
Expand Down

0 comments on commit 0535cfb

Please sign in to comment.