mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-31 20:21:59 -07:00
cli: add --include-zero flag
This flag, when used in conjunction with --count or --count-matches, will print a result for each file searched even if there were zero matches in that file. This is off by default but can be enabled to make ripgrep behave more like grep. This also clarifies some of the defaults for the grep-printer::SummaryBuilder type. Closes #1370, Closes #1405
This commit is contained in:
committed by
Andrew Gallant
parent
4628d77808
commit
a070722ff2
@@ -392,6 +392,37 @@ rgtest!(count_matches_via_only, |dir: Dir, mut cmd: TestCommand| {
|
||||
eqnice!(expected, cmd.stdout());
|
||||
});
|
||||
|
||||
rgtest!(include_zero, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create("sherlock", SHERLOCK);
|
||||
cmd.args(&[
|
||||
"--count",
|
||||
"--include-zero",
|
||||
"nada",
|
||||
]);
|
||||
cmd.assert_err();
|
||||
|
||||
let output = cmd.cmd().output().unwrap();
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let expected = "sherlock:0\n";
|
||||
|
||||
eqnice!(expected, stdout);
|
||||
});
|
||||
|
||||
rgtest!(include_zero_override, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create("sherlock", SHERLOCK);
|
||||
cmd.args(&[
|
||||
"--count",
|
||||
"--include-zero",
|
||||
"--no-include-zero",
|
||||
"nada",
|
||||
]);
|
||||
cmd.assert_err();
|
||||
|
||||
let output = cmd.cmd().output().unwrap();
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert!(stdout.is_empty());
|
||||
});
|
||||
|
||||
rgtest!(files_with_matches, |dir: Dir, mut cmd: TestCommand| {
|
||||
dir.create("sherlock", SHERLOCK);
|
||||
cmd.arg("--files-with-matches").arg("Sherlock");
|
||||
|
Reference in New Issue
Block a user