mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-06-25 14:22:54 +02:00
printer: --only-matching works with --replace
When -o/--only-matching is used with -r/--replace, the replacement works as expected. This is not a breaking change because the flags were previously set to conflict.
This commit is contained in:
committed by
Andrew Gallant
parent
363a4fa9b7
commit
f887bc1f86
@ -162,7 +162,7 @@ pub fn app() -> App<'static, 'static> {
|
||||
.arg(flag("no-ignore-parent"))
|
||||
.arg(flag("no-ignore-vcs"))
|
||||
.arg(flag("null").short("0"))
|
||||
.arg(flag("only-matching").short("o").conflicts_with("replace"))
|
||||
.arg(flag("only-matching").short("o"))
|
||||
.arg(flag("path-separator").value_name("SEPARATOR").takes_value(true))
|
||||
.arg(flag("pretty").short("p"))
|
||||
.arg(flag("replace").short("r")
|
||||
|
@ -316,7 +316,12 @@ impl<W: WriteColor> Printer<W> {
|
||||
let line = {
|
||||
let replacer = CountingReplacer::new(
|
||||
self.replace.as_ref().unwrap(), &mut count, &mut offsets);
|
||||
re.replace_all(&buf[start..end], replacer)
|
||||
if self.only_matching {
|
||||
re.replace_all(
|
||||
&buf[start + match_start..start + match_end], replacer)
|
||||
} else {
|
||||
re.replace_all(&buf[start..end], replacer)
|
||||
}
|
||||
};
|
||||
if self.max_columns.map_or(false, |m| line.len() > m) {
|
||||
let msg = format!(
|
||||
|
Reference in New Issue
Block a user