summaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2017-03-12 22:30:54 -0400
committerAndrew Gallant <jamslam@gmail.com>2017-03-12 22:30:54 -0400
commit95bc678403b63d98b717636e79fdfbabc8949c8a (patch)
tree6d653125b9d02876c67a4eb374569582845239fc /src/args.rs
parent68af3bbdc450cc5bc1feb2d5a689783107d364fa (diff)
Fix interaction with clap.
Previously, `get_matches` would return even if --help or --version was given, and we could check for them manually. That behavior seems to have changed. Instead, we must use get_matches_safe to inspect the error to determine what happened. We can't use the same process for -V/--version since clap will unconditionally print its own version info. Instead, we rename (internally) the version flag so that clap doesn't interfere.
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/args.rs b/src/args.rs
index 148ae8b7..0b1aaa9a 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -88,18 +88,23 @@ impl Args {
///
/// Also, initialize a global logger.
pub fn parse() -> Result<Args> {
- let matches = app::app_short().get_matches();
+ use clap::ErrorKind::*;
+
+ let matches = match app::app_short().get_matches_safe() {
+ Ok(matches) => matches,
+ Err(clap::Error { kind: HelpDisplayed, .. }) => {
+ let _ = ::app::app_long().print_help();
+ println!("");
+ process::exit(0);
+ }
+ Err(err) => err.exit(),
+ };
if matches.is_present("help-short") {
let _ = ::app::app_short().print_help();
println!("");
process::exit(0);
}
- if matches.is_present("help") {
- let _ = ::app::app_long().print_help();
- println!("");
- process::exit(0);
- }
- if matches.is_present("version") {
+ if matches.is_present("ripgrep-version") {
println!("ripgrep {}", crate_version!());
process::exit(0);
}