summaryrefslogtreecommitdiffstats
path: root/crates/core/args.rs
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2023-07-07 10:51:51 -0400
committerAndrew Gallant <jamslam@gmail.com>2023-07-08 18:52:42 -0400
commitd6758445109ae0f52fc3dd09ccb88a95263217cb (patch)
tree71de1d8f642b1c78d047eb80072680b4f4704a64 /crates/core/args.rs
parent54e609d65725ac6683714d365b65d3cf7832dd97 (diff)
core: don't let context flags override eachother
This matches the behavior of GNU grep which does not ignore before-context and after-context completely if the context flag is also provided. Note that this change wasn't done just to match GNU grep. In this case, GNU grep has the more sensible behavior. Fixes #2288, Closes #2451
Diffstat (limited to 'crates/core/args.rs')
-rw-r--r--crates/core/args.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/crates/core/args.rs b/crates/core/args.rs
index 5ad038ed..883bf0fb 100644
--- a/crates/core/args.rs
+++ b/crates/core/args.rs
@@ -992,10 +992,10 @@ impl ArgMatches {
/// If there was a problem parsing the values from the user as an integer,
/// then an error is returned.
fn contexts(&self) -> Result<(usize, usize)> {
- let after = self.usize_of("after-context")?.unwrap_or(0);
- let before = self.usize_of("before-context")?.unwrap_or(0);
let both = self.usize_of("context")?.unwrap_or(0);
- Ok(if both > 0 { (both, both) } else { (before, after) })
+ let after = self.usize_of("after-context")?.unwrap_or(both);
+ let before = self.usize_of("before-context")?.unwrap_or(both);
+ Ok((before, after))
}
/// Returns the unescaped context separator in UTF-8 bytes.