Added prepend array example

This commit is contained in:
Mike Farah 2023-01-11 12:19:46 +11:00
parent 9af55d555b
commit 00c2be541d
2 changed files with 25 additions and 0 deletions

View File

@ -86,6 +86,23 @@ will output
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
Given a sample.yml file of:
```yaml

View File

@ -101,6 +101,14 @@ var addOperatorScenarios = []expressionScenario{
"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,
description: "Concatenate to existing array",