Switch from Docopt to Clap.
There were two important reasons for the switch:
1. Performance. Docopt does poorly when the argv becomes large, which is
a reasonable common use case for search tools. (e.g., use with xargs)
2. Better failure modes. Clap knows a lot more about how a particular
argv might be invalid, and can therefore provide much clearer error
messages.
While both were important, (1) made it urgent.
Note that since Clap requires at least Rust 1.11, this will in turn
increase the minimum Rust version supported by ripgrep from Rust 1.9 to
Rust 1.11. It is therefore a breaking change, so the soonest release of
ripgrep with Clap will have to be 0.3.
There is also at least one subtle breaking change in real usage.
Previous to this commit, this used to work:
rg -e -foo
Where this would cause ripgrep to search for the string `-foo`. Clap
currently has problems supporting this use case
(see: https://github.com/kbknapp/clap-rs/issues/742),
but it can be worked around by using this instead:
rg -e [-]foo
or even
rg [-]foo
and this still works:
rg -- -foo
This commit also adds Bash, Fish and PowerShell completion files to the
release, fixes a bug that prevented ripgrep from working on file
paths containing invalid UTF-8 and shows short descriptions in the
output of `-h` but longer descriptions in the output of `--help`.
Fixes #136, Fixes #189, Fixes #210, Fixes #230
This commit is contained in:
23
src/main.rs
23
src/main.rs
@@ -1,5 +1,9 @@
|
||||
#![allow(dead_code, unused_imports)]
|
||||
|
||||
extern crate bytecount;
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
extern crate ctrlc;
|
||||
extern crate docopt;
|
||||
extern crate env_logger;
|
||||
extern crate grep;
|
||||
extern crate ignore;
|
||||
@@ -14,7 +18,6 @@ extern crate memchr;
|
||||
extern crate memmap;
|
||||
extern crate num_cpus;
|
||||
extern crate regex;
|
||||
extern crate rustc_serialize;
|
||||
extern crate term;
|
||||
#[cfg(windows)]
|
||||
extern crate winapi;
|
||||
@@ -48,6 +51,7 @@ macro_rules! eprintln {
|
||||
}}
|
||||
}
|
||||
|
||||
mod app;
|
||||
mod args;
|
||||
mod atty;
|
||||
mod out;
|
||||
@@ -57,6 +61,7 @@ mod search_buffer;
|
||||
mod search_stream;
|
||||
#[cfg(windows)]
|
||||
mod terminal_win;
|
||||
mod unescape;
|
||||
mod worker;
|
||||
|
||||
pub type Result<T> = result::Result<T, Box<Error + Send + Sync>>;
|
||||
@@ -288,6 +293,20 @@ fn get_or_log_dir_entry(
|
||||
}
|
||||
}
|
||||
|
||||
fn version() -> String {
|
||||
let (maj, min, pat) = (
|
||||
option_env!("CARGO_PKG_VERSION_MAJOR"),
|
||||
option_env!("CARGO_PKG_VERSION_MINOR"),
|
||||
option_env!("CARGO_PKG_VERSION_PATCH"),
|
||||
);
|
||||
match (maj, min, pat) {
|
||||
(Some(maj), Some(min), Some(pat)) => {
|
||||
format!("ripgrep {}.{}.{}", maj, min, pat)
|
||||
}
|
||||
_ => "".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn eprint_nothing_searched() {
|
||||
eprintln!("No files were searched, which means ripgrep probably \
|
||||
applied a filter you didn't expect. \
|
||||
|
||||
Reference in New Issue
Block a user