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:
10
src/args.rs
10
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
|
||||
|
||||
Reference in New Issue
Block a user