Skip to content

Commit cae1867

Browse files
committed
Make celq work without 'this'
1 parent cb0bfd4 commit cae1867

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

docs/manual.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ celq --from-yaml 'this[1].tags' < multi.yaml
432432
With that being said, `celq` can pretty-print JSON via the `-p` flag:
433433

434434
```bash
435-
echo '{"a": 1, "b": 2}' | celq -p 'this'
435+
echo '{"a": 1, "b": 2}' | celq -p
436436
```
437437

438438
Outputs:
@@ -467,7 +467,7 @@ grocery_list_cli --item $FRUIT --quantity 5
467467
468468
For example, to chain `celq` with ripgrep to find all fields containing `regularMarket`:
469469
```bash
470-
celq -g 'this' < yfinance.json | rg '\bregularMarket\w*'
470+
celq -g < yfinance.json | rg '\bregularMarket\w*'
471471
```
472472

473473
Outputs:
@@ -481,7 +481,7 @@ json.chart.result[0].meta.regularMarketTime = 1767387600;
481481
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:
482482

483483
```bash
484-
celq --from-toml -g -S 'this' < Cargo.toml > cargo_toml.js
484+
celq --from-toml -g -S < Cargo.toml > cargo_toml.js
485485
```
486486

487487
Writes the following to `cargo_toml.js`:
@@ -506,7 +506,7 @@ For NDJSON inputs, `--greppable` outputs only the last line. This happens to pre
506506
For example:
507507

508508
```bash
509-
celq -g 'this' < yfinance.json | rg '\bregularMarket\w*' | celq --from-gron -S -p 'this'
509+
celq -g < yfinance.json | rg '\bregularMarket\w*' | celq --from-gron -S -p
510510
```
511511

512512
Outputs:

src/cli.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ impl std::str::FromStr for Argument {
7777
long_about = None,
7878
group(
7979
ArgGroup::new("program")
80-
.required(true)
8180
.args(&["expression", "from_file"])
8281
),
8382
group(
@@ -173,7 +172,7 @@ pub struct Cli {
173172
pub no_extensions: bool,
174173

175174
/// CEL expression to evaluate
176-
#[arg(value_name = "expr")]
175+
#[arg(value_name = "expr", default_value = "this")]
177176
pub expression: Option<String>,
178177
}
179178

tests/golden.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,14 @@ test!(
893893
"[10,15,20]"
894894
);
895895

896+
// Default expr test
897+
test!(
898+
default_expression,
899+
&[],
900+
r#"{"value":100}"#,
901+
r#"{"value":100}"#
902+
);
903+
896904
#[test]
897905
fn test_boolean_false_exit_code() -> io::Result<()> {
898906
let mut child = process::Command::new(env!("CARGO_BIN_EXE_celq"))

0 commit comments

Comments
 (0)