mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
Merge pull request #3391 from epage/possible
fix(error): Consistently respect possible values order
This commit is contained in:
commit
d4cfceedab
2 changed files with 7 additions and 8 deletions
|
@ -642,7 +642,7 @@ impl Error {
|
||||||
let suffix = suggestions::did_you_mean(&bad_val, good_vals.iter()).pop();
|
let suffix = suggestions::did_you_mean(&bad_val, good_vals.iter()).pop();
|
||||||
let arg = arg.to_string();
|
let arg = arg.to_string();
|
||||||
|
|
||||||
let mut sorted: Vec<String> = good_vals
|
let good_vals: Vec<String> = good_vals
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&v| {
|
.map(|&v| {
|
||||||
if v.contains(char::is_whitespace) {
|
if v.contains(char::is_whitespace) {
|
||||||
|
@ -652,7 +652,6 @@ impl Error {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
sorted.sort();
|
|
||||||
|
|
||||||
start_error(&mut c, "");
|
start_error(&mut c, "");
|
||||||
c.warning(format!("{:?}", bad_val));
|
c.warning(format!("{:?}", bad_val));
|
||||||
|
@ -660,7 +659,7 @@ impl Error {
|
||||||
c.warning(&*arg);
|
c.warning(&*arg);
|
||||||
c.none("'\n\t[possible values: ");
|
c.none("'\n\t[possible values: ");
|
||||||
|
|
||||||
if let Some((last, elements)) = sorted.split_last() {
|
if let Some((last, elements)) = good_vals.split_last() {
|
||||||
for v in elements {
|
for v in elements {
|
||||||
c.good(v);
|
c.good(v);
|
||||||
c.none(", ");
|
c.none(", ");
|
||||||
|
@ -681,7 +680,7 @@ impl Error {
|
||||||
try_help(app, &mut c);
|
try_help(app, &mut c);
|
||||||
|
|
||||||
let mut info = vec![arg, bad_val];
|
let mut info = vec![arg, bad_val];
|
||||||
info.extend(sorted);
|
info.extend(good_vals);
|
||||||
|
|
||||||
Self::for_app(app, c, ErrorKind::InvalidValue, info)
|
Self::for_app(app, c, ErrorKind::InvalidValue, info)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use clap::{App, Arg, ErrorKind, PossibleValue};
|
||||||
|
|
||||||
#[cfg(feature = "suggestions")]
|
#[cfg(feature = "suggestions")]
|
||||||
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'
|
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'
|
||||||
\t[possible values: \"ludicrous speed\", fast, slow]
|
\t[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
\tDid you mean \"slow\"?
|
\tDid you mean \"slow\"?
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ For more information try --help
|
||||||
|
|
||||||
#[cfg(not(feature = "suggestions"))]
|
#[cfg(not(feature = "suggestions"))]
|
||||||
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'
|
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'
|
||||||
\t[possible values: \"ludicrous speed\", fast, slow]
|
\t[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
clap-test -O <option>
|
clap-test -O <option>
|
||||||
|
@ -26,7 +26,7 @@ For more information try --help
|
||||||
|
|
||||||
#[cfg(feature = "suggestions")]
|
#[cfg(feature = "suggestions")]
|
||||||
static PV_ERROR_ESCAPED: &str = "error: \"ludicrous\" isn't a valid value for '-O <option>'
|
static PV_ERROR_ESCAPED: &str = "error: \"ludicrous\" isn't a valid value for '-O <option>'
|
||||||
\t[possible values: \"ludicrous speed\", fast, slow]
|
\t[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
\tDid you mean \"ludicrous speed\"?
|
\tDid you mean \"ludicrous speed\"?
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ For more information try --help
|
||||||
|
|
||||||
#[cfg(not(feature = "suggestions"))]
|
#[cfg(not(feature = "suggestions"))]
|
||||||
static PV_ERROR_ESCAPED: &str = "error: \"ludicrous\" isn't a valid value for '-O <option>'
|
static PV_ERROR_ESCAPED: &str = "error: \"ludicrous\" isn't a valid value for '-O <option>'
|
||||||
\t[possible values: \"ludicrous speed\", fast, slow]
|
\t[possible values: slow, fast, \"ludicrous speed\"]
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
clap-test -O <option>
|
clap-test -O <option>
|
||||||
|
|
Loading…
Reference in a new issue