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, Fixes #189, Fixes #210, Fixes #230
  • Loading branch information
BurntSushi committed Nov 18, 2016
1 parent a3f5e0c commit 92dc402
Show file tree
Hide file tree
Showing 14 changed files with 1,173 additions and 656 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
25 changes: 22 additions & 3 deletions doc/rg.1
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
rg \- recursively search current directory for lines matching a pattern
.SH SYNOPSIS
.PP
rg [\f[I]options\f[]] \-e PATTERN ...
[\f[I]<\f[]path\f[I]> ...\f[]]
.PP
rg [\f[I]options\f[]] <\f[I]pattern\f[]> [\f[I]<\f[]path\f[I]> ...\f[]]
.PP
rg [\f[I]options\f[]] (\-e PATTERN | \-f FILE) ...
[\f[I]<\f[]path\f[I]> ...\f[]]
.PP
rg [\f[I]options\f[]] \-\-files [\f[I]<\f[]path\f[I]> ...\f[]]
.PP
rg [\f[I]options\f[]] \-\-type\-list
Expand Down Expand Up @@ -163,6 +163,15 @@ Show debug messages.
.RS
.RE
.TP
.B \-f, \-\-file FILE ...
Search for patterns from the given file, with one pattern per line.
When this flag is used or multiple times or in combination with the
\-e/\-\-regexp flag, then all patterns provided are searched.
Empty pattern lines will match all input lines, and the newline is not
counted as part of the pattern.
.RS
.RE
.TP
.B \-\-files
Print each file that would be searched (but don\[aq]t search).
.RS
Expand Down Expand Up @@ -202,6 +211,16 @@ Search hidden directories and files.
.RS
.RE
.TP
.B \-\-ignore\-file FILE ...
Specify additional ignore files for filtering file paths.
Ignore files should be in the gitignore format and are matched relative
to the current working directory.
These ignore files have lower precedence than all other ignore files.
When specifying multiple ignore files, earlier files have lower
precedence than later files.
.RS
.RE
.TP
.B \-L, \-\-follow
Follow symlinks.
.RS
Expand Down
18 changes: 16 additions & 2 deletions doc/rg.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ rg - recursively search current directory for lines matching a pattern

# SYNOPSIS

rg [*options*] -e PATTERN ... [*<*path*> ...*]

rg [*options*] <*pattern*> [*<*path*> ...*]

rg [*options*] (-e PATTERN | -f FILE) ... [*<*path*> ...*]

rg [*options*] --files [*<*path*> ...*]

rg [*options*] --type-list
Expand Down Expand Up @@ -107,6 +107,12 @@ Project home page: https://github.com/BurntSushi/ripgrep
--debug
: Show debug messages.

-f, --file FILE ...
: Search for patterns from the given file, with one pattern per line. When this
flag is used or multiple times or in combination with the -e/--regexp flag,
then all patterns provided are searched. Empty pattern lines will match all
input lines, and the newline is not counted as part of the pattern.

--files
: Print each file that would be searched (but don't search).

Expand All @@ -132,6 +138,14 @@ Project home page: https://github.com/BurntSushi/ripgrep
: Search hidden directories and files. (Hidden directories and files are
skipped by default.)

--ignore-file FILE ...
: Specify additional ignore files for filtering file paths.
Ignore files should be in the gitignore format and are matched
relative to the current working directory. These ignore files
have lower precedence than all other ignore files. When
specifying multiple ignore files, earlier files have lower
precedence than later files.

-L, --follow
: Follow symlinks.

Expand Down
Loading

0 comments on commit 92dc402

Please sign in to comment.