mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Added another |= example
This commit is contained in:
parent
b0074f5eba
commit
b4b2e1217a
@ -28,6 +28,24 @@ a:
|
|||||||
g: foof
|
g: foof
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Double elements in an array
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 3
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq eval '.[] |= . * 2' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
- 2
|
||||||
|
- 4
|
||||||
|
- 6
|
||||||
|
```
|
||||||
|
|
||||||
## Update node from another file
|
## Update node from another file
|
||||||
Note this will also work when the second file is a scalar (string/number)
|
Note this will also work when the second file is a scalar (string/number)
|
||||||
|
|
||||||
@ -75,7 +93,7 @@ c: fieldC
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '(.a, .c) |= "potatoe"' sample.yml
|
yq eval '(.a, .c) = "potatoe"' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -36,6 +36,14 @@ var assignOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (doc)::{a: {g: foof}}\n",
|
"D0, P[], (doc)::{a: {g: foof}}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Double elements in an array",
|
||||||
|
document: `[1,2,3]`,
|
||||||
|
expression: `.[] |= . * 2`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (doc)::[2, 4, 6]\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Update node from another file",
|
description: "Update node from another file",
|
||||||
subdescription: "Note this will also work when the second file is a scalar (string/number)",
|
subdescription: "Note this will also work when the second file is a scalar (string/number)",
|
||||||
@ -57,7 +65,7 @@ var assignOperatorScenarios = []expressionScenario{
|
|||||||
{
|
{
|
||||||
description: "Updated multiple paths",
|
description: "Updated multiple paths",
|
||||||
document: `{a: fieldA, b: fieldB, c: fieldC}`,
|
document: `{a: fieldA, b: fieldB, c: fieldC}`,
|
||||||
expression: `(.a, .c) |= "potatoe"`,
|
expression: `(.a, .c) = "potatoe"`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (doc)::{a: potatoe, b: fieldB, c: potatoe}\n",
|
"D0, P[], (doc)::{a: potatoe, b: fieldB, c: potatoe}\n",
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user