mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Improving docs
This commit is contained in:
@@ -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
|
||||
Running
|
||||
```bash
|
||||
@@ -1,4 +1,15 @@
|
||||
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
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
|
||||
@@ -19,6 +19,29 @@ true
|
||||
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
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user