Skip to content

Commit c6dd5ad

Browse files
committed
Add greppable documentation
1 parent 8899759 commit c6dd5ad

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/manual.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Options:
5656
-S, --sort-keys Output the fields of each object with the keys in sorted order
5757
-f, --from-file <FILE> Read CEL expression from a file
5858
-p, --pretty-print
59+
-g, --greppable Output in a greppable format (gron style)
5960
-h, --help Print help
6061
-V, --version Print version
6162
```
@@ -412,6 +413,42 @@ grocery_list_cli --item $FRUIT --quantity 5
412413

413414
`celq`'s output will be saved to the `FRUIT` environment variable as `apples`. That variable can then be used with other commands.
414415
416+
### Grep friendly output
417+
418+
`celq` has a `--greppable` flag that is inspired by [gron](https://github.com/tomnomnom/gron). If you pass `-g` or `--greppable`, the usual JSON output is converted to a format that can be more easily queried by grep or [ripgrep](https://github.com/BurntSushi/ripgrep).
419+
420+
For example, to chain `celq` with ripgrep to find all fields containing `regularMarket`:
421+
```bash
422+
celq -g 'this' < yfinance.json | rg '\bregularMarket\w*'
423+
```
424+
425+
Outputs:
426+
```none
427+
json.chart.result[0].meta.regularMarketDayHigh = 277.825;
428+
json.chart.result[0].meta.regularMarketDayLow = 269.02;
429+
json.chart.result[0].meta.regularMarketPrice = 271.01;
430+
json.chart.result[0].meta.regularMarketTime = 1767387600;
431+
```
432+
433+
One interesting property about `--greppable` is that the output is valid JavaScript code. This unlocks use cases such as embedding TOML, YAML, and JSON5 configs as JavaScript source code. For example:
434+
435+
```bash
436+
celq --from-toml -g -S 'this' < Cargo.toml > cargo_toml.js
437+
```
438+
439+
Writes the following to `cargo_toml.js`:
440+
441+
```javacript
442+
json = {};
443+
json.bin = [];
444+
json.bin[0] = {};
445+
json.bin[0].name = "celq";
446+
json.bin[0].path = "src/main.rs";
447+
/* Many lines follow */
448+
```
449+
450+
If you need deterministic outputs, we recommend using the `-S` flag for sorting the output.
451+
415452
## Quirks
416453

417454
1. Do not rely on the order of the JSON output, by default it is randomized due to Rust implementation details. If you need ordering, pass `--sort-keys` as an argument

0 commit comments

Comments
 (0)