Skip to content

Commit

Permalink
Switch from Docopt to Clap.
Browse files Browse the repository at this point in the history
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: clap-rs/clap#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, #189, #210, #230
  • Loading branch information
BurntSushi committed Nov 13, 2016
1 parent 4b18f82 commit d9bd654
Show file tree
Hide file tree
Showing 11 changed files with 1,048 additions and 639 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ matrix:
env: TARGET=x86_64-apple-darwin
# Minimum Rust supported channel.
- os: linux
rust: 1.9.0
env: TARGET=x86_64-unknown-linux-musl
- os: linux
rust: 1.9.0
rust: 1.11.0
env: TARGET=x86_64-unknown-linux-gnu
- os: osx
rust: 1.9.0
rust: 1.11.0
env: TARGET=x86_64-apple-darwin

before_install:
Expand Down
78 changes: 58 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readme = "README.md"
keywords = ["regex", "grep", "egrep", "search", "pattern"]
license = "Unlicense/MIT"
exclude = ["HomebrewFormula"]
build = "build.rs"

[[bin]]
bench = false
Expand All @@ -25,8 +26,8 @@ path = "tests/tests.rs"

[dependencies]
bytecount = "0.1.4"
clap = "2.18"
ctrlc = "2.0"
docopt = "0.6"
env_logger = "0.3"
grep = { version = "0.1.4", path = "grep" }
ignore = { version = "0.1.5", path = "ignore" }
Expand All @@ -37,13 +38,16 @@ memchr = "0.1"
memmap = "0.5"
num_cpus = "1"
regex = "0.1.77"
rustc-serialize = "=0.3.19"
term = "0.4"

[target.'cfg(windows)'.dependencies]
kernel32-sys = "0.2"
winapi = "0.2"

[build-dependencies]
clap = "2.18"
lazy_static = "0.2"

[features]
avx-accel = ["bytecount/avx-accel"]
simd-accel = ["bytecount/simd-accel", "regex/simd-accel"]
Expand Down
23 changes: 23 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[macro_use]
extern crate clap;
#[macro_use]
extern crate lazy_static;

use std::fs;

use clap::Shell;

#[allow(dead_code)]
#[path = "src/app.rs"]
mod app;

fn main() {
fs::create_dir_all(env!("OUT_DIR")).unwrap();

let mut app = app::app_short();
app.gen_completions("rg", Shell::Bash, env!("OUT_DIR"));
app.gen_completions("rg", Shell::Fish, env!("OUT_DIR"));
// Zsh seems to fail with a panic.
// app.gen_completions("rg", Shell::Zsh, env!("OUT_DIR"));
app.gen_completions("rg", Shell::PowerShell, env!("OUT_DIR"));
}
1 change: 1 addition & 0 deletions ci/before_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mk_tarball() {

cp target/$TARGET/release/rg "$td/$name/"
cp {doc/rg.1,README.md,UNLICENSE,COPYING,LICENSE-MIT} "$td/$name/"
cp target/$TARGET/release/build/ripgrep-*/out/{_rg.,rg.}* "$td/$name/"

pushd $td
tar czf "$out_dir/$name.tar.gz" *
Expand Down
Loading

0 comments on commit d9bd654

Please sign in to comment.