mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-31 12:12:00 -07:00
search: a few small touchups
This commit is contained in:
@@ -315,7 +315,24 @@ pub struct SearchWorker<W> {
|
|||||||
impl<W: WriteColor> SearchWorker<W> {
|
impl<W: WriteColor> SearchWorker<W> {
|
||||||
/// Execute a search over the given subject.
|
/// Execute a search over the given subject.
|
||||||
pub fn search(&mut self, subject: &Subject) -> io::Result<SearchResult> {
|
pub fn search(&mut self, subject: &Subject) -> io::Result<SearchResult> {
|
||||||
self.search_impl(subject)
|
let bin =
|
||||||
|
if subject.is_explicit() {
|
||||||
|
self.config.binary_explicit.clone()
|
||||||
|
} else {
|
||||||
|
self.config.binary_implicit.clone()
|
||||||
|
};
|
||||||
|
self.searcher.set_binary_detection(bin);
|
||||||
|
|
||||||
|
let path = subject.path();
|
||||||
|
if subject.is_stdin() {
|
||||||
|
self.search_reader(path, io::stdin().lock())
|
||||||
|
} else if self.should_preprocess(path) {
|
||||||
|
self.search_preprocessor(path)
|
||||||
|
} else if self.should_decompress(path) {
|
||||||
|
self.search_decompress(path)
|
||||||
|
} else {
|
||||||
|
self.search_path(path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a mutable reference to the underlying printer.
|
/// Return a mutable reference to the underlying printer.
|
||||||
@@ -341,30 +358,6 @@ impl<W: WriteColor> SearchWorker<W> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Search the given subject using the appropriate strategy.
|
|
||||||
fn search_impl(&mut self, subject: &Subject) -> io::Result<SearchResult> {
|
|
||||||
let bin =
|
|
||||||
if subject.is_explicit() {
|
|
||||||
self.config.binary_explicit.clone()
|
|
||||||
} else {
|
|
||||||
self.config.binary_implicit.clone()
|
|
||||||
};
|
|
||||||
self.searcher.set_binary_detection(bin);
|
|
||||||
|
|
||||||
let path = subject.path();
|
|
||||||
if subject.is_stdin() {
|
|
||||||
let stdin = io::stdin();
|
|
||||||
// A `return` here appeases the borrow checker. NLL will fix this.
|
|
||||||
return self.search_reader(path, stdin.lock());
|
|
||||||
} else if self.should_preprocess(path) {
|
|
||||||
self.search_preprocessor(path)
|
|
||||||
} else if self.should_decompress(path) {
|
|
||||||
self.search_decompress(path)
|
|
||||||
} else {
|
|
||||||
self.search_path(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if and only if the given file path should be
|
/// Returns true if and only if the given file path should be
|
||||||
/// decompressed before searching.
|
/// decompressed before searching.
|
||||||
fn should_decompress(&self, path: &Path) -> bool {
|
fn should_decompress(&self, path: &Path) -> bool {
|
||||||
@@ -392,8 +385,8 @@ impl<W: WriteColor> SearchWorker<W> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> io::Result<SearchResult> {
|
) -> io::Result<SearchResult> {
|
||||||
let bin = self.config.preprocessor.clone().unwrap();
|
let bin = self.config.preprocessor.as_ref().unwrap();
|
||||||
let mut cmd = Command::new(&bin);
|
let mut cmd = Command::new(bin);
|
||||||
cmd.arg(path).stdin(Stdio::from(File::open(path)?));
|
cmd.arg(path).stdin(Stdio::from(File::open(path)?));
|
||||||
|
|
||||||
let rdr = self
|
let rdr = self
|
||||||
|
Reference in New Issue
Block a user