summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin K <kbknapp@gmail.com>2017-04-05 01:14:55 -0400
committerAndrew Gallant <jamslam@gmail.com>2017-04-05 11:38:58 -0400
commit0c298f60a68ed9c98192adaa23f1f517366ce336 (patch)
tree1016f6fdea5d36bc911f0952cec5f5d80358a069 /src
parent79271fcb33a7fa1a13df4e9aa3b268e0e8bb3605 (diff)
updates clap and removes home rolled -h/--help distinction
This commit updates clap to v2.23.0 The update contained a bug fix in clap that results in broken code in ripgrep. ripgrep was relying on the bug, but this commit fixes that issue. The bug centered around not being able to override the auto-generated help message by supplying a flag with a long of `help`. Normally, supplying a flag with a long of `help` means whenever the user passes `--help`, the consuming code (e.g. ripgrep) is responsible for displaying the help message. However, due to the bug in clap this wasn't necessary for ripgrep to do unless the user passed `-h`. With the bug fixed, it meant the user passing `--help` and clap expected ripgrep to display the help, yet ripgrep expected clap to display the help. This has been fixed in this commit of ripgrep. All well now! v2.23.0 also brings the abilty to use `Arg::help` or `Arg::long_help` allowing one to distinguish between `-h` and `--help`. This commit leaves all doc strings in the `lazy_static!` hashmap however only for aesthetic reasons. This means all home rolled handling of `-h`/`--help` has been removed from ripgrep, yet functionality *and* appearances are 100% the same.
Diffstat (limited to 'src')
-rw-r--r--src/app.rs21
-rw-r--r--src/args.rs22
2 files changed, 4 insertions, 39 deletions
diff --git a/src/app.rs b/src/app.rs
index d09160ac..f19ff8cf 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -32,16 +32,6 @@ ARGS:
OPTIONS:
{unified}";
-/// Build a clap application with short help strings.
-pub fn app_short() -> App<'static, 'static> {
- app(false, |k| USAGES[k].short)
-}
-
-/// Build a clap application with long help strings.
-pub fn app_long() -> App<'static, 'static> {
- app(true, |k| USAGES[k].long)
-}
-
/// Build a clap application parameterized by usage strings.
///
/// The function given should take a clap argument name and return a help
@@ -49,10 +39,9 @@ pub fn app_long() -> App<'static, 'static> {
///
/// This is an intentionally stand-alone module so that it can be used easily
/// in a `build.rs` script to build shell completion files.
-fn app<F>(next_line_help: bool, doc: F) -> App<'static, 'static>
- where F: Fn(&'static str) -> &'static str {
+pub fn app() -> App<'static, 'static> {
let arg = |name| {
- Arg::with_name(name).help(doc(name)).next_line_help(next_line_help)
+ Arg::with_name(name).help(USAGES[name].short).long_help(USAGES[name].long)
};
let flag = |name| arg(name).long(name);
@@ -64,11 +53,7 @@ fn app<F>(next_line_help: bool, doc: F) -> App<'static, 'static>
.setting(AppSettings::UnifiedHelpMessage)
.usage(USAGE)
.template(TEMPLATE)
- // Handle help/version manually to make their output formatting
- // consistent with short/long views.
- .arg(arg("help-short").short("h"))
- .arg(flag("help"))
- .arg(arg("ripgrep-version").long("version").short("V"))
+ .help_message("Prints help information. Use --help for more details.")
// First, set up primary positional/flag arguments.
.arg(arg("pattern")
.required_unless_one(&[
diff --git a/src/args.rs b/src/args.rs
index 2d046fd6..90e5a9a4 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -5,7 +5,6 @@ use std::fs;
use std::io::{self, BufRead};
use std::ops;
use std::path::{Path, PathBuf};
-use std::process;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
@@ -88,26 +87,7 @@ impl Args {
///
/// Also, initialize a global logger.
pub fn parse() -> Result<Args> {
- 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("ripgrep-version") {
- println!("ripgrep {}", crate_version!());
- process::exit(0);
- }
+ let matches = app::app().get_matches();
let mut logb = env_logger::LogBuilder::new();
if matches.is_present("debug") {