Skip to content

Commit

Permalink
fix(SubCommands): fixed where subcmds weren't recognized after mult args
Browse files Browse the repository at this point in the history
Closes #405
  • Loading branch information
kbknapp committed Jan 31, 2016
1 parent 816cec8 commit c19c17a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {

// Has the user already passed '--'?
if !pos_only {
if !starts_new_arg || self.is_set(AppSettings::AllowLeadingHyphen) {
let pos_sc = self.subcommands.iter().any(|s| &s.0.meta.name[..] == &*arg_os);
if (!starts_new_arg || self.is_set(AppSettings::AllowLeadingHyphen)) && !pos_sc {
// Check to see if parsing a value from an option
if let Some(nvo) = needs_val_of {
// get the OptBuilder so we can check the settings
Expand Down Expand Up @@ -488,13 +489,11 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
}
}

// let arg_str = arg_os.to_str().expect(INVALID_UTF8);
if self.subcommands.iter().any(|s| &s.0.meta.name[..] == &*arg_os) {
if pos_sc {
if &*arg_os == "help" &&
self.settings.is_set(AppSettings::NeedsSubcommandHelp) {
return self._help();
}
// subcommands only support valid UTF-8
subcmd_name = Some(arg_os.to_str().expect(INVALID_UTF8).to_owned());
break;
} else if let Some(candidate) = suggestions::did_you_mean(
Expand Down Expand Up @@ -618,7 +617,7 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
mid_string.push_str(" ");
if let Some(ref mut sc) = self.subcommands
.iter_mut()
.filter(|s| &s.0.meta.name[..] == &sc_name)
.filter(|s| &s.0.meta.name == &sc_name)
.next() {
let mut sc_matcher = ArgMatcher::new();
// bin_name should be parent's bin_name + [<reqs>] + the sc's name separated by
Expand Down

2 comments on commit c19c17a

@Byron
Copy link
Contributor

@Byron Byron commented on c19c17a Feb 1, 2016

Choose a reason for hiding this comment

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

😊 for the fix
😥 For the missing test

@Byron
Copy link
Contributor

@Byron Byron commented on c19c17a Feb 1, 2016

Choose a reason for hiding this comment

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

Nevermind ! I found it :). Tears shed for no reason

Please sign in to comment.