Improving docs

This commit is contained in:
Mike Farah 2021-02-26 11:31:43 +11:00
parent b1a5387cdd
commit e93c43f7a0
7 changed files with 55 additions and 8 deletions

View File

@ -1,10 +1,4 @@
This operator is used to update node values. It can be used in either the:
### plain form: `=`
Which will assign the LHS node values to the RHS node values. The RHS expression is run against the matching nodes in the pipeline.
### relative form: `|=`
This will do a similar thing to the plain form, however, the RHS expression is run against _the LHS nodes_. This is useful for updating values based on old values, e.g. increment.
## Create yaml file ## Create yaml file
Running Running
```bash ```bash

View File

@ -1,4 +1,15 @@
Use these comment operators to set or retrieve comments. Use these comment operators to set or retrieve comments.
Like the `=` and `|=` assign operators, the same syntax applies when updating comments:
### plain form: `=`
This will assign the LHS nodes comments to the expression on the RHS. The RHS is run against the matching nodes in the pipeline
### relative form: `|=`
Similar to the plain form, however the RHS evaluates against each matching LHS node! This is useful if you want to set the comments as a relative expression of the node, for instance its value or path.
## Set line comment ## Set line comment
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml

View File

@ -19,6 +19,29 @@ true
false false
``` ```
## Select, checking for existence of deep paths
Simply pipe in parent expressions into `has`
Given a sample.yml file of:
```yaml
- a:
b:
c: cat
- a:
b:
d: dog
```
then
```bash
yq eval '.[] | select(.a.b | has("c"))' sample.yml
```
will output
```yaml
a:
b:
c: cat
```
## Has array index ## Has array index
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml

View File

@ -1 +1,11 @@
Use these comment operators to set or retrieve comments. Use these comment operators to set or retrieve comments.
Like the `=` and `|=` assign operators, the same syntax applies when updating comments:
### plain form: `=`
This will assign the LHS nodes comments to the expression on the RHS. The RHS is run against the matching nodes in the pipeline
### relative form: `|=`
Similar to the plain form, however the RHS evaluates against each matching LHS node! This is useful if you want to set the comments as a relative expression of the node, for instance its value or path.

View File

@ -143,5 +143,5 @@ func TestAssignOperatorScenarios(t *testing.T) {
for _, tt := range assignOperatorScenarios { for _, tt := range assignOperatorScenarios {
testScenario(t, &tt) testScenario(t, &tt)
} }
documentScenarios(t, "Assign", assignOperatorScenarios) documentScenarios(t, "Assign (Update)", assignOperatorScenarios)
} }

View File

@ -28,6 +28,15 @@ var hasOperatorScenarios = []expressionScenario{
"D0, P[3], (!!bool)::false\n", "D0, P[3], (!!bool)::false\n",
}, },
}, },
{
description: "Select, checking for existence of deep paths",
subdescription: "Simply pipe in parent expressions into `has`",
document: "- {a: {b: {c: cat}}}\n- {a: {b: {d: dog}}}",
expression: `.[] | select(.a.b | has("c"))`,
expected: []string{
"D0, P[0], (!!map)::{a: {b: {c: cat}}}\n",
},
},
{ {
dontFormatInputForDoc: true, dontFormatInputForDoc: true,
description: "Has array index", description: "Has array index",