1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-08-04 21:52:54 +02:00

printer: support -r/--replace with --json

This adds a `replacement` field to each submatch object in the JSON
output. In effect, this extends the `-r/--replace` flag so that it works
with `--json`.

This adds a new field instead of replacing the match text (which is how
the standard printer works) for maximum flexibility. This way, consumers
of the JSON output can access the original match text (and always rely
on it corresponding to the original match text) while also getting the
replacement text without needing to do the replacement themselves.

Closes #1872, Closes #2883
This commit is contained in:
Stephan Badragan
2024-09-08 01:59:46 -07:00
committed by Andrew Gallant
parent 0904f55d3e
commit cf91d6e67a
5 changed files with 180 additions and 9 deletions

View File

@ -589,6 +589,7 @@ impl HiArgs {
.pretty(false)
.max_matches(self.max_count)
.always_begin_end(false)
.replacement(self.replace.clone().map(|r| r.into()))
.build(wtr)
}