Merge pull request #4798 from epage/similar

fix(error): Give more idea why we are suggesting an arg
This commit is contained in:
Ed Page 2023-03-28 06:24:24 -05:00 committed by GitHub
commit 53cb165b3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 22 deletions

View file

@ -429,19 +429,22 @@ fn try_help(styled: &mut StyledStr, help: Option<&str>) {
fn did_you_mean(styled: &mut StyledStr, context: &str, valid: &ContextValue) { fn did_you_mean(styled: &mut StyledStr, context: &str, valid: &ContextValue) {
if let ContextValue::String(valid) = valid { if let ContextValue::String(valid) = valid {
styled.none(TAB); styled.none(TAB);
styled.good("tip: "); styled.good("tip: a similar ");
styled.none(context); styled.none(context);
styled.none(" '"); styled.none(" exists: '");
styled.good(valid); styled.good(valid);
styled.none("' exists"); styled.none("'");
} else if let ContextValue::Strings(valid) = valid { } else if let ContextValue::Strings(valid) = valid {
styled.none(TAB); styled.none(TAB);
styled.good("tip: "); if valid.len() == 1 {
styled.none(context); styled.good("tip: a similar ");
if valid.len() > 1 { styled.none(context);
styled.none("s"); styled.none(" exists: ");
} else {
styled.good("tip: some similar ");
styled.none(context);
styled.none("s exist: ");
} }
styled.none(" ");
for (i, valid) in valid.iter().enumerate() { for (i, valid) in valid.iter().enumerate() {
if i != 0 { if i != 0 {
styled.none(", "); styled.none(", ");
@ -450,11 +453,6 @@ fn did_you_mean(styled: &mut StyledStr, context: &str, valid: &ContextValue) {
styled.good(valid); styled.good(valid);
styled.none("'"); styled.none("'");
} }
if valid.len() == 1 {
styled.none(" exists");
} else {
styled.none(" exist");
}
} }
} }

View file

@ -448,7 +448,7 @@ fn did_you_mean() {
static DYM: &str = "\ static DYM: &str = "\
error: unexpected argument '--optio' found error: unexpected argument '--optio' found
tip: argument '--option' exists tip: a similar argument exists: '--option'
Usage: clap-test --option <opt>... [positional] [positional2] [positional3]... Usage: clap-test --option <opt>... [positional] [positional2] [positional3]...
@ -546,7 +546,7 @@ fn issue_1073_suboptimal_flag_suggestion() {
static DYM_ISSUE_1073: &str = "\ static DYM_ISSUE_1073: &str = "\
error: unexpected argument '--files-without-matches' found error: unexpected argument '--files-without-matches' found
tip: argument '--files-without-match' exists tip: a similar argument exists: '--files-without-match'
Usage: ripgrep-616 --files-without-match Usage: ripgrep-616 --files-without-match

View file

@ -181,7 +181,7 @@ fn possible_values_output() {
error: invalid value 'slo' for '-O <option>' error: invalid value 'slo' for '-O <option>'
[possible values: slow, fast, \"ludicrous speed\"] [possible values: slow, fast, \"ludicrous speed\"]
tip: value 'slow' exists tip: a similar value exists: 'slow'
For more information, try '--help'. For more information, try '--help'.
"; ";
@ -215,7 +215,7 @@ fn possible_values_alias_output() {
error: invalid value 'slo' for '-O <option>' error: invalid value 'slo' for '-O <option>'
[possible values: slow, fast, \"ludicrous speed\"] [possible values: slow, fast, \"ludicrous speed\"]
tip: value 'slow' exists tip: a similar value exists: 'slow'
For more information, try '--help'. For more information, try '--help'.
"; ";
@ -253,7 +253,7 @@ fn possible_values_hidden_output() {
error: invalid value 'slo' for '-O <option>' error: invalid value 'slo' for '-O <option>'
[possible values: slow, fast, \"ludicrous speed\"] [possible values: slow, fast, \"ludicrous speed\"]
tip: value 'slow' exists tip: a similar value exists: 'slow'
For more information, try '--help'. For more information, try '--help'.
"; ";
@ -292,7 +292,7 @@ fn escaped_possible_values_output() {
error: invalid value 'ludicrous' for '-O <option>' error: invalid value 'ludicrous' for '-O <option>'
[possible values: slow, fast, \"ludicrous speed\"] [possible values: slow, fast, \"ludicrous speed\"]
tip: value 'ludicrous speed' exists tip: a similar value exists: 'ludicrous speed'
For more information, try '--help'. For more information, try '--help'.
"; ";

View file

@ -100,7 +100,7 @@ fn subcmd_did_you_mean_output() {
static DYM_SUBCMD: &str = "\ static DYM_SUBCMD: &str = "\
error: unrecognized subcommand 'subcm' error: unrecognized subcommand 'subcm'
tip: subcommand 'subcmd' exists tip: a similar subcommand exists: 'subcmd'
tip: to pass 'subcm' as a value, use 'dym -- subcm' tip: to pass 'subcm' as a value, use 'dym -- subcm'
Usage: dym [COMMAND] Usage: dym [COMMAND]
@ -120,7 +120,7 @@ fn subcmd_did_you_mean_output_ambiguous() {
static DYM_SUBCMD_AMBIGUOUS: &str = "\ static DYM_SUBCMD_AMBIGUOUS: &str = "\
error: unrecognized subcommand 'te' error: unrecognized subcommand 'te'
tip: subcommands 'test', 'temp' exist tip: some similar subcommands exist: 'test', 'temp'
tip: to pass 'te' as a value, use 'dym -- te' tip: to pass 'te' as a value, use 'dym -- te'
Usage: dym [COMMAND] Usage: dym [COMMAND]
@ -517,7 +517,7 @@ For more information, try 'help'.
static BAZ_EXPECTED: &str = "\ static BAZ_EXPECTED: &str = "\
error: unrecognized subcommand 'baz' error: unrecognized subcommand 'baz'
tip: subcommand 'bar' exists tip: a similar subcommand exists: 'bar'
tip: to pass 'baz' as a value, use ' -- baz' tip: to pass 'baz' as a value, use ' -- baz'
Usage: <COMMAND> Usage: <COMMAND>