Skip to content

Commit

Permalink
fix: fixes a bug that wasn't allowing help and version to be properly…
Browse files Browse the repository at this point in the history
… overridden

One should be able to override the auto generated help and version flags
by simply providing an arg with a long of `help` or `version`
respectively. This bug was preventing that from happening.

However, now that it's fixed if one was relying on adding an arg with a
long of `help` or `version` and using `get_matches_safe` to produce the
`ErrorKind::HelpDisplayed` or `ErrorKind::VersionDisplayed` errors they
**WILL NOT** happen anymore.

This is because the bug was causing those "errors" to occur (i.e. the
help or version message to be displayed). The "fix" to get that
functionality back is to either:

 * Remove the arg with the long of `help` or `version`
 * Use `ArgMatches::is_present` instead of `App::get_matches_safe` to check for the presence of your custom help or version flag

Option 1 is the easiest provided one wasn't using said arg to *also*
override other aspects of the flags as well (short, help message, etc.)

Even though this may break some code, as per the compatibility policy
listed in the readme; code that breaks due to relying on a bug does
*not* constitute a major version bump. I will however be bumping the
minor version instead of just the patch version. I will also be
searching for, contacting, and attempting to submit PRs to any affected
projects prior to releasing the next version to crates.io

Closes #922
  • Loading branch information
kbknapp committed Apr 4, 2017
1 parent 92cc305 commit 8b2ceb8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ impl<'a, 'b> Parser<'a, 'b>
self.set(AS::DontCollapseArgsInUsage);
self.set(AS::ContainsLast);
}
if let Some(l) = a.s.long {
if l == "version" {
self.unset(AS::NeedsLongVersion);
} else if l == "help" {
self.unset(AS::NeedsLongHelp);
}
}
}

// actually adds the arguments
Expand Down

0 comments on commit 8b2ceb8

Please sign in to comment.