fix(Positional): positionals were ignored if they matched a subcmd, even after '--'

This commit is contained in:
Kevin K 2015-05-05 18:53:09 -04:00
parent a3e0671336
commit 90e7b08187

View file

@ -1238,7 +1238,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
I: IntoIterator<Item=&'z T> { I: IntoIterator<Item=&'z T> {
match did_you_mean(arg, values) { match did_you_mean(arg, values) {
Some(candidate) => { Some(candidate) => {
let mut suffix = "\n\tDid you mean ".to_owned(); let mut suffix = "\n\tDid you mean ".to_string();
match style { match style {
DidYouMeanMessageStyle::LongFlag => suffix.push_str("--"), DidYouMeanMessageStyle::LongFlag => suffix.push_str("--"),
DidYouMeanMessageStyle::EnumValue => suffix.push('\''), DidYouMeanMessageStyle::EnumValue => suffix.push('\''),
@ -1368,7 +1368,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
needs_val_of = self.parse_short_arg(matches, &arg); needs_val_of = self.parse_short_arg(matches, &arg);
} else { } else {
// Positional or Subcommand // Positional or Subcommand
// If the user pased `--` we don't check for subcommands, because the argument they // If the user pased `--` we don't check for subcommands, because the argument they
// may be trying to pass might match a subcommand name // may be trying to pass might match a subcommand name
if !pos_only { if !pos_only {
@ -1836,7 +1835,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
return None; return None;
} }
let mut suffix = App::did_you_mean_suffix(arg, self.opts.values() let suffix = App::did_you_mean_suffix(arg, self.opts.values()
.filter_map(|v| .filter_map(|v|
if let Some(ref l) = v.long { if let Some(ref l) = v.long {
Some(l) Some(l)
@ -1844,18 +1843,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
None None
} }
), DidYouMeanMessageStyle::LongFlag); ), DidYouMeanMessageStyle::LongFlag);
// If it didn't find a good match for opts, try flags
if suffix.is_empty() {
suffix = App::did_you_mean_suffix(arg, self.flags.values()
.filter_map(|v|
if let Some(ref l) = v.long {
Some(l)
} else {
None
}
), DidYouMeanMessageStyle::LongFlag);
}
self.report_error(format!("The argument --{} isn't valid{}", arg, suffix), self.report_error(format!("The argument --{} isn't valid{}", arg, suffix),
true, true,
true, true,