|
| 1 | +# yq builtin |
| 2 | + |
| 3 | +Bashkit ships a `yq` structured-data processor for the command shape agents |
| 4 | +commonly use with mikefarah/yq. It parses YAML or JSON, evaluates the existing |
| 5 | +`jq`/jaq expression engine, then emits YAML or JSON. Bashkit deliberately does |
| 6 | +not maintain a second YAML-specific query language. |
| 7 | + |
| 8 | +Enable the Cargo `jq` feature to register both `jq` and `yq`. |
| 9 | + |
| 10 | +## Examples |
| 11 | + |
| 12 | +```bash |
| 13 | +yq '.server.port' config.yml |
| 14 | +yq '.items[] | select(.enabled) | .name' config.yml |
| 15 | +yq '.values | map(. * 2)' config.yml |
| 16 | +yq -o=json -I=0 '.' config.yml |
| 17 | +yq -p=json -o=yaml '.' data.json |
| 18 | +yq -i '.server.port = 8080' config.yml |
| 19 | +``` |
| 20 | + |
| 21 | +With no expression, `.` is used. Input comes from the listed VFS files or |
| 22 | +stdin. YAML streams containing `---` are processed one document at a time; |
| 23 | +`-s` presents all input documents to the filter as one array. The optional |
| 24 | +`e` / `eval` subcommand alias is accepted for common generated invocations. |
| 25 | + |
| 26 | +## Flags |
| 27 | + |
| 28 | +| Flag | Behaviour | |
| 29 | +|------|-----------| |
| 30 | +| `-p`, `--input-format` | `auto`, `yaml`, or `json` | |
| 31 | +| `-o`, `--output-format` | `yaml` or `json` | |
| 32 | +| `-r`, `--raw-output` | Unwrap string results | |
| 33 | +| `-c`, `--compact-output` | Compact JSON output | |
| 34 | +| `-e`, `--exit-status` | Nonzero for no output, `null`, or `false` | |
| 35 | +| `-s`, `--slurp` | Read all documents into an array | |
| 36 | +| `-n`, `--null-input` | Evaluate once with `null` input | |
| 37 | +| `-i`, `--inplace` | Atomically replace exactly one input file | |
| 38 | +| `-I`, `--indent` | Set JSON indentation; `0` is compact | |
| 39 | +| `-N`, `--no-doc` | Omit separators between YAML results | |
| 40 | +| `--expression` | Force an otherwise ambiguous argument to be the expression | |
| 41 | + |
| 42 | +Short boolean flags combine (`-rce`, `-sn`). Attached value forms such as |
| 43 | +`-o=json`, `-p=json`, and `-I=0` are accepted. |
| 44 | + |
| 45 | +In-place evaluation and serialization finish before a sibling temporary file |
| 46 | +is written and renamed over the source. A parse, filter, output-limit, write, |
| 47 | +or rename failure leaves the source unchanged. |
| 48 | + |
| 49 | +## Compatibility boundary |
| 50 | + |
| 51 | +The expression language is jq, not mikefarah/yq's node/style language. Common |
| 52 | +selection, iteration, `select`, `map`, construction, reduction, and assignment |
| 53 | +filters work. mikefarah/yq-only operators for comments, styles, anchors, tags, |
| 54 | +file metadata, and cross-file evaluation are not implemented. |
| 55 | + |
| 56 | +YAML custom tags and non-string mapping keys are rejected rather than silently |
| 57 | +losing information. Mapping keys are sorted deterministically at the JSON-value |
| 58 | +boundary. Comments, scalar style, and anchors are not retained after |
| 59 | +conversion. The parser follows YAML 1.1. TOML, CSV, and XML conversion are not |
| 60 | +part of this builtin; Bashkit's separate `tomlq` and `csv` helpers remain |
| 61 | +available for their existing narrow command surfaces. |
| 62 | + |
| 63 | +## See also |
| 64 | + |
| 65 | +- [`jq_guide`](crate::jq_guide) — the shared expression engine and its jq compatibility notes. |
| 66 | +- [`threat_model`](crate::threat_model) — structured-input resource and information-disclosure controls. |
0 commit comments