summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2021-05-29 11:56:43 -0400
committerAndrew Gallant <jamslam@gmail.com>2021-05-31 21:51:18 -0400
commita77b914e7ac9fe83602d7e43f8c2187cb5b03dc1 (patch)
tree9628c07dd5a88c893d2416a0f3e1ff4702666961
parent2e2af50a4df0bd424c3a06eabf42fa0ea0aad1bc (diff)
args: make --passthru and -A/-B/-C override each other
Fixes #1868
-rw-r--r--CHANGELOG.md2
-rw-r--r--crates/core/app.rs17
-rw-r--r--tests/regression.rs25
3 files changed, 40 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index baaafa75..dcf8aa87 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,6 +49,8 @@ Bug fixes:
Clarify how the `--hidden` flag works.
* [BUG #1866](https://github.com/BurntSushi/ripgrep/issues/1866#issuecomment-841635553):
Fix bug when computing column numbers in `--vimgrep` mode.
+* [BUG #1868](https://github.com/BurntSushi/ripgrep/issues/1868):
+ Fix bug where `--passthru` and `-A/-B/-C` did not override each other.
* [BUG #1878](https://github.com/BurntSushi/ripgrep/issues/1878):
Fix bug where `\A` could produce unanchored matches in multiline search.
* [BUG 94e4b8e3](https://github.com/BurntSushi/ripgrep/commit/94e4b8e3):
diff --git a/crates/core/app.rs b/crates/core/app.rs
index 50215837..496eef38 100644
--- a/crates/core/app.rs
+++ b/crates/core/app.rs
@@ -696,7 +696,7 @@ fn flag_after_context(args: &mut Vec<RGArg>) {
"\
Show NUM lines after each match.
-This overrides the --context flag.
+This overrides the --context and --passthru flags.
"
);
let arg = RGArg::flag("after-context", "NUM")
@@ -704,6 +704,7 @@ This overrides the --context flag.
.help(SHORT)
.long_help(LONG)
.number()
+ .overrides("passthru")
.overrides("context");
args.push(arg);
}
@@ -765,7 +766,7 @@ fn flag_before_context(args: &mut Vec<RGArg>) {
"\
Show NUM lines before each match.
-This overrides the --context flag.
+This overrides the --context and --passthru flags.
"
);
let arg = RGArg::flag("before-context", "NUM")
@@ -773,6 +774,7 @@ This overrides the --context flag.
.help(SHORT)
.long_help(LONG)
.number()
+ .overrides("passthru")
.overrides("context");
args.push(arg);
}
@@ -1005,7 +1007,8 @@ fn flag_context(args: &mut Vec<RGArg>) {
Show NUM lines before and after each match. This is equivalent to providing
both the -B/--before-context and -A/--after-context flags with the same value.
-This overrides both the -B/--before-context and -A/--after-context flags.
+This overrides both the -B/--before-context and -A/--after-context flags,
+in addition to the --passthru flag.
"
);
let arg = RGArg::flag("context", "NUM")
@@ -1013,6 +1016,7 @@ This overrides both the -B/--before-context and -A/--after-context flags.
.help(SHORT)
.long_help(LONG)
.number()
+ .overrides("passthru")
.overrides("before-context")
.overrides("after-context");
args.push(arg);
@@ -2348,12 +2352,17 @@ the empty string. For example, if you are searching using 'rg foo' then using
'rg \"^|foo\"' instead will emit every line in every file searched, but only
occurrences of 'foo' will be highlighted. This flag enables the same behavior
without needing to modify the pattern.
+
+This overrides the --context, --after-context and --before context flags.
"
);
let arg = RGArg::switch("passthru")
.help(SHORT)
.long_help(LONG)
- .alias("passthrough");
+ .alias("passthrough")
+ .overrides("after-context")
+ .overrides("before-context")
+ .overrides("context");
args.push(arg);
}
diff --git a/tests/regression.rs b/tests/regression.rs
index 9aba2746..6e3454f6 100644
--- a/tests/regression.rs
+++ b/tests/regression.rs
@@ -883,6 +883,31 @@ test:3:5:foo quux
eqnice!(expected, cmd.stdout());
});
+// See: https://github.com/BurntSushi/ripgrep/issues/1868
+rgtest!(r1868_context_passthru_override, |dir: Dir, _: TestCommand| {
+ dir.create("test", "foo\nbar\nbaz\nquux\n");
+
+ let args = &["-C1", "bar", "test"];
+ eqnice!("foo\nbar\nbaz\n", dir.command().args(args).stdout());
+ let args = &["--passthru", "bar", "test"];
+ eqnice!("foo\nbar\nbaz\nquux\n", dir.command().args(args).stdout());
+
+ let args = &["--passthru", "-C1", "bar", "test"];
+ eqnice!("foo\nbar\nbaz\n", dir.command().args(args).stdout());
+ let args = &["-C1", "--passthru", "bar", "test"];
+ eqnice!("foo\nbar\nbaz\nquux\n", dir.command().args(args).stdout());
+
+ let args = &["--passthru", "-B1", "bar", "test"];
+ eqnice!("foo\nbar\n", dir.command().args(args).stdout());
+ let args = &["-B1", "--passthru", "bar", "test"];
+ eqnice!("foo\nbar\nbaz\nquux\n", dir.command().args(args).stdout());
+
+ let args = &["--passthru", "-A1", "bar", "test"];
+ eqnice!("bar\nbaz\n", dir.command().args(args).stdout());
+ let args = &["-A1", "--passthru", "bar", "test"];
+ eqnice!("foo\nbar\nbaz\nquux\n", dir.command().args(args).stdout());
+});
+
rgtest!(r1878, |dir: Dir, _: TestCommand| {
dir.create("test", "a\nbaz\nabc\n");