Skip to content

Commit 7717ed7

Browse files
committed
Handle NDJSON differently for greppable
1 parent 50b8eae commit 7717ed7

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

docs/manual.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ json.bin[0].path = "src/main.rs";
476476

477477
If you need deterministic outputs, we recommend using the `-S` flag for sorting the output.
478478

479+
For NDJSON inputs, `--greppable` outputs only the last line. This happens to prevent redefinitions of the `json` variable. If you are dealing with NDJSON and want this feature, consider using the `--slurp` flag.
480+
479481
### Reverting filtered grep output
480482

481483
`celq` also has a `--from-gron` flag that parsers the output of `gron` and `celq --greppable`. It is equivalent to `gron -u`. That can be useful for converting output filtered by grep back to JSON.

src/main.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,16 @@ fn main() -> io::Result<()> {
9191
Ok(results) => {
9292
// Print all outputs, unless void mode is enabled
9393
if !cli.void {
94-
for (output, _) in &results {
95-
println!("{}", output);
94+
if !cli.greppable {
95+
for (output, _) in &results {
96+
println!("{}", output);
97+
}
98+
} else {
99+
let last_gron = results
100+
.last()
101+
.map(|(output, _)| output.as_str())
102+
.unwrap_or("");
103+
println!("{}", last_gron);
96104
}
97105
}
98106

0 commit comments

Comments
 (0)