diff options
author | Charles Blake <cb@cblake.net> | 2018-07-13 09:54:51 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2018-07-21 17:25:12 -0400 |
commit | 231456c409ff38c75c39d01b781b569965ddf808 (patch) | |
tree | 592b89acd3172b0c23acdfe6113bcd70ea11aa3a /src/args.rs | |
parent | 1d09d4d31ba3ac2eb09edf31e8ec46b2b5cec388 (diff) |
ripgrep: add --pre flag
The preprocessor flag accepts a command program and executes this
program for every input file that is searched. Instead of searching the
file directly, ripgrep will instead search the stdout contents of the
program.
Closes #978, Closes #981
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs index aca9bcd5..302e330e 100644 --- a/src/args.rs +++ b/src/args.rs @@ -80,6 +80,7 @@ pub struct Args { types: Types, with_filename: bool, search_zip_files: bool, + preprocessor: Option<PathBuf>, stats: bool } @@ -288,6 +289,7 @@ impl Args { .quiet(self.quiet) .text(self.text) .search_zip_files(self.search_zip_files) + .preprocessor(self.preprocessor.clone()) .build() } @@ -429,6 +431,7 @@ impl<'a> ArgMatches<'a> { types: self.types()?, with_filename: with_filename, search_zip_files: self.is_present("search-zip"), + preprocessor: self.preprocessor(), stats: self.stats() }; if args.mmap { @@ -722,6 +725,19 @@ impl<'a> ArgMatches<'a> { } } + /// Returns the preprocessor command + fn preprocessor(&self) -> Option<PathBuf> { + if let Some(path) = self.value_of_os("pre") { + if path.is_empty() { + None + } else { + Some(Path::new(path).to_path_buf()) + } + } else { + None + } + } + /// Returns the unescaped path separator in UTF-8 bytes. fn path_separator(&self) -> Result<Option<u8>> { match self.value_of_lossy("path-separator") { |