mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-12 19:25:37 +00:00
Added prepend array example
This commit is contained in:
parent
9af55d555b
commit
00c2be541d
@ -86,6 +86,23 @@ will output
|
|||||||
a: ['dog', 'cat']
|
a: ['dog', 'cat']
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Prepend to existing array
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a:
|
||||||
|
- dog
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.a = ["cat"] + .a' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
a:
|
||||||
|
- cat
|
||||||
|
- dog
|
||||||
|
```
|
||||||
|
|
||||||
## Add new object to array
|
## Add new object to array
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -101,6 +101,14 @@ var addOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (doc)::a: ['dog', 'cat']\n",
|
"D0, P[], (doc)::a: ['dog', 'cat']\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Prepend to existing array",
|
||||||
|
document: `a: [dog]`,
|
||||||
|
expression: `.a = ["cat"] + .a`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (doc)::a: [cat, dog]\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
description: "Concatenate to existing array",
|
description: "Concatenate to existing array",
|
||||||
|
Loading…
Reference in New Issue
Block a user