mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Added pick including all keys example
This commit is contained in:
parent
c76e432de3
commit
42b92aff13
@ -26,6 +26,30 @@ myMap:
|
|||||||
cat: meow
|
cat: meow
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Pick keys from map, included all the keys
|
||||||
|
We create a map of the picked keys plus all the current keys, and run that through unique
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
myMap:
|
||||||
|
cat: meow
|
||||||
|
dog: bark
|
||||||
|
thing: hamster
|
||||||
|
hamster: squeak
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq '.myMap |= pick( (["thing"] + keys) | unique)' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
myMap:
|
||||||
|
thing: hamster
|
||||||
|
cat: meow
|
||||||
|
dog: bark
|
||||||
|
hamster: squeak
|
||||||
|
```
|
||||||
|
|
||||||
## Pick indices from array
|
## Pick indices from array
|
||||||
Note that the order of the indices matches the pick order and non existent indices are skipped.
|
Note that the order of the indices matches the pick order and non existent indices are skipped.
|
||||||
|
|
||||||
|
@ -14,6 +14,15 @@ var pickOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!map)::myMap: {hamster: squeak, cat: meow}\n",
|
"D0, P[], (!!map)::myMap: {hamster: squeak, cat: meow}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "Pick keys from map, included all the keys",
|
||||||
|
subdescription: "We create a map of the picked keys plus all the current keys, and run that through unique",
|
||||||
|
document: "myMap: {cat: meow, dog: bark, thing: hamster, hamster: squeak}\n",
|
||||||
|
expression: `.myMap |= pick( (["thing"] + keys) | unique)`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!!map)::myMap: {thing: hamster, cat: meow, dog: bark, hamster: squeak}\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Pick splat",
|
description: "Pick splat",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user