Skip to content

Commit

Permalink
fix: fixes bug where one can't override version or help flags
Browse files Browse the repository at this point in the history
Closes #514
  • Loading branch information
kbknapp committed May 31, 2016
1 parent 24423e6 commit 90d7d6a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ impl<'a, 'b> Parser<'a, 'b>
l));
self.long_list.push(l);
if l == "help" {
self.set(AppSettings::NeedsLongHelp);
self.unset(AppSettings::NeedsLongHelp);
} else if l == "version" {
self.set(AppSettings::NeedsLongVersion);
self.unset(AppSettings::NeedsLongVersion);
}
}
if a.is_set(ArgSettings::Required) {
Expand Down Expand Up @@ -378,6 +378,10 @@ impl<'a, 'b> Parser<'a, 'b>
self.settings.set(s)
}

pub fn unset(&mut self, s: AppSettings) {
self.settings.unset(s)
}

pub fn verify_positionals(&mut self) {
// Because you must wait until all arguments have been supplied, this is the first chance
// to make assertions on positional argument indexes
Expand Down Expand Up @@ -929,13 +933,13 @@ impl<'a, 'b> Parser<'a, 'b>
debug!("Checking if -{} is help or version...", arg);
if let Some(h) = self.help_short {
sdebugln!("Help");
if arg == h {
if arg == h && self.settings.is_set(AppSettings::NeedsLongHelp) {
try!(self._help());
}
}
if let Some(v) = self.version_short {
sdebugln!("Help");
if arg == v {
if arg == v && self.settings.is_set(AppSettings::NeedsLongVersion) {
try!(self._version());
}
}
Expand Down

0 comments on commit 90d7d6a

Please sign in to comment.