summaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authorBalaji Sivaraman <balaji@balajisivaraman.com>2018-02-12 22:47:22 +0530
committerAndrew Gallant <jamslam@gmail.com>2018-03-10 10:59:00 -0500
commit00520b30f5f38e543e17b1a4cc5e8417bc488ea4 (patch)
tree154aee40835b6a0d2fe945ccc065ff3ee0b8d8c0 /src/args.rs
parent11a8f0eaf0f661c5b20c20fa2399314905d84fc1 (diff)
output: add --stats flag
This commit provides basic support for a --stats flag, which will print various aggregate statistics about a search after all of the results have been printed. This is mostly intended to support a similar feature found in the Silver Searcher. Note though that we don't emit the total bytes searched; this is a first pass at an implementation and we can improve upon it later. Closes #411, Closes #799
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/args.rs b/src/args.rs
index a5e13415..d2077d67 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -79,7 +79,8 @@ pub struct Args {
type_list: bool,
types: Types,
with_filename: bool,
- search_zip_files: bool
+ search_zip_files: bool,
+ stats: bool
}
impl Args {
@@ -221,6 +222,12 @@ impl Args {
self.max_count == Some(0)
}
+
+ /// Returns whether ripgrep should track stats for this run
+ pub fn stats(&self) -> bool {
+ self.stats
+ }
+
/// Create a new writer for single-threaded searching with color support.
pub fn stdout(&self) -> termcolor::StandardStream {
termcolor::StandardStream::stdout(self.color_choice)
@@ -411,7 +418,8 @@ impl<'a> ArgMatches<'a> {
type_list: self.is_present("type-list"),
types: self.types()?,
with_filename: with_filename,
- search_zip_files: self.is_present("search-zip")
+ search_zip_files: self.is_present("search-zip"),
+ stats: self.stats()
};
if args.mmap {
debug!("will try to use memory maps");
@@ -825,6 +833,19 @@ impl<'a> ArgMatches<'a> {
}
}
+ /// Returns whether status should be tracked for this run of ripgrep
+
+ /// This is automatically disabled if we're asked to only list the
+ /// files that wil be searched, files with matches or files
+ /// without matches.
+ fn stats(&self) -> bool {
+ if self.is_present("files-with-matches") ||
+ self.is_present("files-without-match") {
+ return false;
+ }
+ self.is_present("stats")
+ }
+
/// Returns the approximate number of threads that ripgrep should use.
fn threads(&self) -> Result<usize> {
if self.is_present("sort-files") {