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
This commit is contained in:
committed by
Andrew Gallant
parent
1d09d4d31b
commit
231456c409
16
src/args.rs
16
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") {
|
||||
|
||||
Reference in New Issue
Block a user