mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Better recursive decent docs
This commit is contained in:
parent
8027f4c568
commit
a0e1f65b20
@ -33,6 +33,8 @@ frog
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Recursively find nodes with keys
|
## Recursively find nodes with keys
|
||||||
|
Note that this example has wrapped the expression in `[]` to show that there are two matches returned. You do not have to wrap in `[]` in your path expression.
|
||||||
|
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
a:
|
a:
|
||||||
@ -43,16 +45,16 @@ a:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq eval '.. | select(has("name"))' sample.yml
|
yq eval '[.. | select(has("name"))]' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
name: frog
|
- name: frog
|
||||||
b:
|
b:
|
||||||
name: blog
|
name: blog
|
||||||
age: 12
|
age: 12
|
||||||
name: blog
|
- name: blog
|
||||||
age: 12
|
age: 12
|
||||||
```
|
```
|
||||||
|
|
||||||
## Recursively find nodes with values
|
## Recursively find nodes with values
|
@ -64,11 +64,11 @@ var recursiveDescentOperatorScenarios = []expressionScenario{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Recursively find nodes with keys",
|
description: "Recursively find nodes with keys",
|
||||||
|
subdescription: "Note that this example has wrapped the expression in `[]` to show that there are two matches returned. You do not have to wrap in `[]` in your path expression.",
|
||||||
document: `{a: {name: frog, b: {name: blog, age: 12}}}`,
|
document: `{a: {name: frog, b: {name: blog, age: 12}}}`,
|
||||||
expression: `.. | select(has("name"))`,
|
expression: `[.. | select(has("name"))]`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[a], (!!map)::{name: frog, b: {name: blog, age: 12}}\n",
|
"D0, P[a], (!!seq)::- {name: frog, b: {name: blog, age: 12}}\n- {name: blog, age: 12}\n",
|
||||||
"D0, P[a b], (!!map)::{name: blog, age: 12}\n",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -233,5 +233,5 @@ func TestRecursiveDescentOperatorScenarios(t *testing.T) {
|
|||||||
for _, tt := range recursiveDescentOperatorScenarios {
|
for _, tt := range recursiveDescentOperatorScenarios {
|
||||||
testScenario(t, &tt)
|
testScenario(t, &tt)
|
||||||
}
|
}
|
||||||
documentScenarios(t, "Recursive Descent", recursiveDescentOperatorScenarios)
|
documentScenarios(t, "Recursive Descent (Glob)", recursiveDescentOperatorScenarios)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user