Skip to content

Commit

Permalink
fix: fixes a bug where args that allow values to start with a hyphen …
Browse files Browse the repository at this point in the history
…couldnt contain a double hyphen -- as a value

Closes #960
  • Loading branch information
kbknapp committed May 15, 2017
1 parent 43e6a43 commit ebf73a0
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,10 @@ impl<'a, 'b> Parser<'a, 'b>
// Is this a new argument, or values from a previous option?
let mut ret = if arg_os.starts_with(b"--") {
debugln!("Parser::is_new_arg: -- found");
if arg_os.len_() == 2 {
if arg_os.len_() == 2 && !arg_allows_tac {
return true; // We have to return true so override everything else
} else if arg_allows_tac {
return false;
}
true
} else if arg_os.starts_with(b"-") {
Expand Down Expand Up @@ -800,7 +802,7 @@ impl<'a, 'b> Parser<'a, 'b>
self.unset(AS::ValidNegNumFound);
// Is this a new argument, or values from a previous option?
let starts_new_arg = self.is_new_arg(&arg_os, needs_val_of);
if arg_os.starts_with(b"--") && arg_os.len_() == 2 {
if arg_os.starts_with(b"--") && arg_os.len_() == 2 && starts_new_arg {
debugln!("Parser::get_matches_with: setting TrailingVals=true");
self.set(AS::TrailingValues);
continue;
Expand Down Expand Up @@ -850,9 +852,6 @@ impl<'a, 'b> Parser<'a, 'b>
ParseResult::ValuesDone => continue,
_ => (),
}
// if !(needs_val_of == ParseResult::Flag && self.is_set(AS::AllowLeadingHyphen)) {
// continue;
// }
} else if arg_os.starts_with(b"-") && arg_os.len_() != 1 {
// Try to parse short args like normal, if AllowLeadingHyphen or
// AllowNegativeNumbers is set, parse_short_arg will *not* throw
Expand All @@ -871,7 +870,6 @@ impl<'a, 'b> Parser<'a, 'b>
self.color()));
}
}
// ParseResult::MaybeHyphenValue => (),
ParseResult::Opt(..) |
ParseResult::Flag |
ParseResult::ValuesDone => continue,
Expand Down

0 comments on commit ebf73a0

Please sign in to comment.