summaryrefslogtreecommitdiffstats
path: root/src/worker.rs
diff options
context:
space:
mode:
authorBalaji Sivaraman <balaji@balajisivaraman.com>2018-02-20 21:03:07 +0530
committerAndrew Gallant <jamslam@gmail.com>2018-03-10 10:38:25 -0500
commit27fc9f2fd341bd3ed672f79d43bf983514188b96 (patch)
tree6a0d42ebe069ac6077eace1968332246ab51cb77 /src/worker.rs
parent96f73293c0b734d91b55ad1e6940da0f706eed65 (diff)
search: add a --count-matches flag
This commit introduces a new flag, --count-matches, which will cause ripgrep to report a total count of all matches instead of a count of total lines matched. Closes #566, Closes #814
Diffstat (limited to 'src/worker.rs')
-rw-r--r--src/worker.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/worker.rs b/src/worker.rs
index e5f7546a..a8327cda 100644
--- a/src/worker.rs
+++ b/src/worker.rs
@@ -35,6 +35,7 @@ struct Options {
before_context: usize,
byte_offset: bool,
count: bool,
+ count_matches: bool,
files_with_matches: bool,
files_without_matches: bool,
eol: u8,
@@ -56,6 +57,7 @@ impl Default for Options {
before_context: 0,
byte_offset: false,
count: false,
+ count_matches: false,
files_with_matches: false,
files_without_matches: false,
eol: b'\n',
@@ -126,6 +128,15 @@ impl WorkerBuilder {
self
}
+ /// If enabled, searching will print the count of individual matches
+ /// instead of each match.
+ ///
+ /// Disabled by default.
+ pub fn count_matches(mut self, yes: bool) -> Self {
+ self.opts.count_matches = yes;
+ self
+ }
+
/// Set the encoding to use to read each file.
///
/// If the encoding is `None` (the default), then the encoding is
@@ -297,6 +308,7 @@ impl Worker {
.before_context(self.opts.before_context)
.byte_offset(self.opts.byte_offset)
.count(self.opts.count)
+ .count_matches(self.opts.count_matches)
.files_with_matches(self.opts.files_with_matches)
.files_without_matches(self.opts.files_without_matches)
.eol(self.opts.eol)
@@ -337,6 +349,7 @@ impl Worker {
Ok(searcher
.byte_offset(self.opts.byte_offset)
.count(self.opts.count)
+ .count_matches(self.opts.count_matches)
.files_with_matches(self.opts.files_with_matches)
.files_without_matches(self.opts.files_without_matches)
.eol(self.opts.eol)