mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-01 12:41:58 -07:00
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
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user