summaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-03-10 10:34:35 -0500
committerAndrew Gallant <jamslam@gmail.com>2018-03-10 10:38:34 -0500
commit11a8f0eaf0f661c5b20c20fa2399314905d84fc1 (patch)
treec094e2ebb16b0c614e69f77d72852ce924893fbb /src/args.rs
parent27fc9f2fd341bd3ed672f79d43bf983514188b96 (diff)
args: treat --count --only-matching as --count-matches
Namely, when ripgrep is asked to count things and is also asked to print every match on its own line, then we should just automatically count the matches and not the lines. This is a departure from how GNU grep behaves, but there is a compelling argument to be made that GNU grep's behavior doesn't make a lot of sense. Note that since this changes the behavior of combining two existing flags, this is a breaking change.
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/args.rs b/src/args.rs
index 309f5db8..a5e13415 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -747,10 +747,16 @@ impl<'a> ArgMatches<'a> {
let count = self.is_present("count");
let count_matches = self.is_present("count-matches");
let invert_matches = self.is_present("invert-match");
+ let only_matching = self.is_present("only-matching");
if count_matches && invert_matches {
- return (true, false);
+ // Treat `-v --count-matches` as `-v -c`.
+ (true, false)
+ } else if count && only_matching {
+ // Treat `-c --only-matching` as `--count-matches`.
+ (false, true)
+ } else {
+ (count, count_matches)
}
- (count, count_matches)
}
/// Returns the user's color choice based on command line parameters and