Skip to content

Commit 9e52039

Browse files
committed
Documentation improvements
1 parent 148fa77 commit 9e52039

1 file changed

Lines changed: 32 additions & 13 deletions

File tree

docs/manual.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ This file contains the simplified response from the Yahoo Finance Unofficial JSO
141141
### Table of Contents
142142

143143
* [Reading Files](#reading-files)
144+
* [this keyword](#this-keyword)
144145
* [Writing Files](#writing-files)
145146
* [Output JSON](#output-json)
146147
* [Slicing lists](#slicing-lists)
@@ -175,6 +176,24 @@ cat yfinance.json | celq "this.chart.result[0].meta.symbol"
175176

176177
Both command outputs: `"AAPL"`.
177178

179+
### this keyword
180+
181+
`celq` can access the input in CEL expressions with the `this` keyword. For example:
182+
183+
```bash
184+
echo '["apples", "bananas", "blueberry"]' | celq 'this[1]'
185+
# Outputs: "bananas"
186+
```
187+
188+
If we take the array of fruits is the input, `this[1]` refers to the element in index 1 of the input. In this case, `"bananas"`.
189+
190+
If no CEL expression is provided, `celq` outputs the input:
191+
192+
```bash
193+
echo '["apples", "bananas", "blueberry"]' | celq
194+
# Outputs: ["apples", "bananas", "blueberry"]
195+
```
196+
178197
### Writing Files
179198

180199
`celq` writes by default to the standard output. That output can be piped to a file.
@@ -204,19 +223,6 @@ Notice that by default `celq` does not guarantee the key order of the output. If
204223
cat yfinance.json | celq --sort-keys '{"symbol": this.chart.result[0].meta.longName, "price": this.chart.result[0].meta.regularMarketPrice}'
205224
```
206225

207-
### Slicing lists
208-
209-
`celq` implements the popular slice extension for CEL. For example:
210-
211-
```bash
212-
echo '["apples", "bananas", "blueberry"]' | celq 'this.slice(1, 3)'
213-
# Outputs: ["bananas", "blueberry"]
214-
```
215-
216-
Slicing follows Python conventions: it is 0-indexed and works with negative indices. The `.slice()` calls always requires two arguments. If you need to slice until the end of the list, do `this.slice(pos, size(this.slice))`. Similarly, do `this.slice(0, pos)` to start from the beginning.
217-
218-
If you want to keep your CEL code portable, pass the `--no-extensions` arguments to disable slicing and all other extensions.
219-
220226
### Reading CEL from a file
221227

222228
In the previous example, the CEL expression for the JSON became long. Let's say we saved the expression in `stock.cel` with the following contents:
@@ -234,6 +240,19 @@ If we pass the `--from-file` argument, we can load the expression and keep the c
234240
cat yfinance.json | celq --from-file stock.cel
235241
```
236242

243+
### Slicing lists
244+
245+
`celq` implements the popular slice extension for CEL. For example:
246+
247+
```bash
248+
echo '["apples", "bananas", "blueberry"]' | celq 'this.slice(1, 3)'
249+
# Outputs: ["bananas", "blueberry"]
250+
```
251+
252+
Slicing follows Python conventions: it is 0-indexed and works with negative indices. The `.slice()` calls always requires two arguments. If you need to slice until the end of the list, do `this.slice(pos, size(this.slice))`. Similarly, do `this.slice(0, pos)` to start from the beginning.
253+
254+
If you want to keep your CEL code portable, pass the `--no-extensions` arguments to disable slicing and all other extensions.
255+
237256
### Dealing with NDJSON
238257

239258
`celq` can deal with [Newline-Delimited JSON (NDJSON)](https://web.archive.org/web/20231218162511/https://ndjson.org/). That format is also called [JSON Lines (JSONL)](https://web.archive.org/web/20251130123805/https://jsonlines.org./).

0 commit comments

Comments
 (0)