1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00
This commit is contained in:
Mike Farah
2020-12-27 22:14:26 +11:00
parent f7f8bed955
commit 7b54bead5e
6 changed files with 331 additions and 370 deletions

View File

@@ -2,8 +2,8 @@ This is the simplest (and perhaps most used) operator, it is used to navigate de
## Simple map navigation
Given a sample.yml file of:
```yaml
a: {b: apple}
'': null
a:
b: apple
```
then
```bash
@@ -11,7 +11,7 @@ yq eval '.a' sample.yml
```
will output
```yaml
{b: apple}
b: apple
```
## Splat
@@ -20,9 +20,7 @@ Often used to pipe children into other operators
Given a sample.yml file of:
```yaml
- b: apple
'': null
- c: banana
'': null
```
then
```bash
@@ -31,9 +29,7 @@ yq eval '.[]' sample.yml
will output
```yaml
b: apple
'': null
c: banana
'': null
```
## Special characters
@@ -42,7 +38,6 @@ Use quotes around path elements with special characters
Given a sample.yml file of:
```yaml
"{}": frog
'': null
```
then
```bash
@@ -59,7 +54,6 @@ Nodes are added dynamically while traversing
Given a sample.yml file of:
```yaml
c: banana
'': null
```
then
```bash
@@ -73,8 +67,9 @@ null
## Wildcard matching
Given a sample.yml file of:
```yaml
a: {cat: apple, mad: things}
'': null
a:
cat: apple
mad: things
```
then
```bash
@@ -89,9 +84,9 @@ things
## Aliases
Given a sample.yml file of:
```yaml
a: &cat {c: frog}
a: &cat
c: frog
b: *cat
'': null
```
then
```bash
@@ -105,9 +100,9 @@ will output
## Traversing aliases with splat
Given a sample.yml file of:
```yaml
a: &cat {c: frog}
a: &cat
c: frog
b: *cat
'': null
```
then
```bash
@@ -121,9 +116,9 @@ frog
## Traversing aliases explicitly
Given a sample.yml file of:
```yaml
a: &cat {c: frog}
a: &cat
c: frog
b: *cat
'': null
```
then
```bash
@@ -154,7 +149,6 @@ will output
Given a sample.yml file of:
```yaml
2: cat
'': null
```
then
```bash
@@ -162,13 +156,13 @@ yq eval '.[2]' sample.yml
```
will output
```yaml
cat
```
## Maps with non existing numeric keys
Given a sample.yml file of:
```yaml
a: b
'': null
```
then
```bash
@@ -176,6 +170,7 @@ yq eval '.[0]' sample.yml
```
will output
```yaml
null
```
## Traversing merge anchors
@@ -191,13 +186,14 @@ bar: &bar
c: bar_c
foobarList:
b: foobarList_b
!!merge <<: [*foo, *bar]
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
'': null
```
then
```bash
@@ -221,13 +217,14 @@ bar: &bar
c: bar_c
foobarList:
b: foobarList_b
!!merge <<: [*foo, *bar]
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
'': null
```
then
```bash
@@ -251,13 +248,14 @@ bar: &bar
c: bar_c
foobarList:
b: foobarList_b
!!merge <<: [*foo, *bar]
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
'': null
```
then
```bash
@@ -281,13 +279,14 @@ bar: &bar
c: bar_c
foobarList:
b: foobarList_b
!!merge <<: [*foo, *bar]
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
'': null
```
then
```bash
@@ -315,13 +314,14 @@ bar: &bar
c: bar_c
foobarList:
b: foobarList_b
!!merge <<: [*foo, *bar]
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
'': null
```
then
```bash
@@ -345,13 +345,14 @@ bar: &bar
c: bar_c
foobarList:
b: foobarList_b
!!merge <<: [*foo, *bar]
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
'': null
```
then
```bash
@@ -360,7 +361,26 @@ yq eval '.foobarList.[]' sample.yml
will output
```yaml
foobarList_b
[*foo, *bar]
- *foo
- *bar
foobarList_c
```
## Select multiple indices
Given a sample.yml file of:
```yaml
a:
- a
- b
- c
```
then
```bash
yq eval '.a[0, 2]' sample.yml
```
will output
```yaml
a
c
```