Skip to content

Commit

Permalink
fix(Positional): positionals were ignored if they matched a subcmd, e…
Browse files Browse the repository at this point in the history
…ven after '--'
  • Loading branch information
kbknapp committed May 6, 2015
1 parent a3e0671 commit 90e7b08
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,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 = "\n\tDid you mean ".to_owned();
let mut suffix = "\n\tDid you mean ".to_string();
match style {
DidYouMeanMessageStyle::LongFlag => suffix.push_str("--"),
DidYouMeanMessageStyle::EnumValue => suffix.push('\''),
Expand Down Expand Up @@ -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);
} else {
// Positional or Subcommand

// If the user pased `--` we don't check for subcommands, because the argument they
// may be trying to pass might match a subcommand name
if !pos_only {
Expand Down Expand Up @@ -1836,26 +1835,14 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
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|
if let Some(ref l) = v.long {
Some(l)
} else {
None
}
), 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),
true,
true,
Expand Down

1 comment on commit 90e7b08

@Byron
Copy link
Contributor

@Byron Byron commented on 90e7b08 May 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I was staring at this part and wondered if something like it would be possible, after the merge though. But I came to the wrong conclusion .

In other words: thanks for catching this !

Please sign in to comment.