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.
This commit is contained in:
Andrew Gallant
2018-03-10 10:34:35 -05:00
parent 27fc9f2fd3
commit 11a8f0eaf0
3 changed files with 19 additions and 4 deletions

View File

@@ -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