Added with operator

This commit is contained in:
Mike Farah
2021-09-12 21:52:02 +10:00
parent 0c3334d838
commit 6002604251
11 changed files with 91 additions and 13 deletions
+1 -3
View File
@@ -18,8 +18,6 @@ a:
```
## Update and set style of a particular node using path variables
You can use a variable reference to re-use a path
Given a sample.yml file of:
```yaml
a:
@@ -28,7 +26,7 @@ a:
```
then
```bash
yq eval '.a.b ref $x | $x = "new" | $x style="double"' sample.yml
yq eval 'with(.a.b ; . = "new" | . style="double")' sample.yml
```
will output
```yaml
+2
View File
@@ -75,6 +75,8 @@ b: a_value
```
## Use ref to reference a path repeatedly
Note: You may find the `with` operator more useful.
Given a sample.yml file of:
```yaml
a:
+20
View File
@@ -0,0 +1,20 @@
Use the `with` operator to conveniently make multiple updates to a deeply nested path.
## Update and style
Given a sample.yml file of:
```yaml
a:
deeply:
nested: value
```
then
```bash
yq eval 'with(.a.deeply.nested ; . = "newValue" | . style="single")' sample.yml
```
will output
```yaml
a:
deeply:
nested: 'newValue'
```
+1
View File
@@ -0,0 +1 @@
Use the `with` operator to conveniently make multiple updates to a deeply nested path.