calculate document,filename and fileindex by parent

This commit is contained in:
Mike Farah
2023-05-05 15:19:58 +10:00
parent 68df67f550
commit 0ca8a13e36
25 changed files with 141 additions and 146 deletions
@@ -54,7 +54,6 @@ yq eval-all 'file_index' sample.yml another.yml
will output
```yaml
0
---
1
```
+4 -13
View File
@@ -6,9 +6,7 @@ Filters an array (or map values) by the expression given. Equivalent to doing `m
## Filter array
Given a sample.yml file of:
```yaml
- 1
- 2
- 3
[1, 2, 3]
```
then
```bash
@@ -16,19 +14,13 @@ yq 'filter(. < 3)' sample.yml
```
will output
```yaml
- 1
- 2
[1, 2]
```
## Filter map values
Given a sample.yml file of:
```yaml
c:
things: cool
frog: yes
d:
things: hot
frog: false
{c: {things: cool, frog: yes}, d: {things: hot, frog: false}}
```
then
```bash
@@ -36,7 +28,6 @@ yq 'filter(.things == "cool")' sample.yml
```
will output
```yaml
- things: cool
frog: yes
[{things: cool, frog: yes}]
```
+7 -17
View File
@@ -6,9 +6,7 @@ Recursively flattens all arrays
Given a sample.yml file of:
```yaml
- 1
- - 2
- - - 3
[1, [2], [[3]]]
```
then
```bash
@@ -16,17 +14,13 @@ yq 'flatten' sample.yml
```
will output
```yaml
- 1
- 2
- 3
[1, 2, 3]
```
## Flatten with depth of one
Given a sample.yml file of:
```yaml
- 1
- - 2
- - - 3
[1, [2], [[3]]]
```
then
```bash
@@ -34,15 +28,13 @@ yq 'flatten(1)' sample.yml
```
will output
```yaml
- 1
- 2
- - 3
[1, 2, [3]]
```
## Flatten empty array
Given a sample.yml file of:
```yaml
- []
[[]]
```
then
```bash
@@ -56,8 +48,7 @@ will output
## Flatten array of objects
Given a sample.yml file of:
```yaml
- foo: bar
- - foo: baz
[{foo: bar}, [{foo: baz}]]
```
then
```bash
@@ -65,7 +56,6 @@ yq 'flatten' sample.yml
```
will output
```yaml
- foo: bar
- foo: baz
[{foo: bar}, {foo: baz}]
```
+10 -28
View File
@@ -5,12 +5,7 @@ This is used to group items in an array by an expression.
## Group by field
Given a sample.yml file of:
```yaml
- foo: 1
bar: 10
- foo: 3
bar: 100
- foo: 1
bar: 1
[{foo: 1, bar: 10}, {foo: 3, bar: 100}, {foo: 1, bar: 1}]
```
then
```bash
@@ -18,25 +13,15 @@ yq 'group_by(.foo)' sample.yml
```
will output
```yaml
- - foo: 1
bar: 10
- foo: 1
bar: 1
- - foo: 3
bar: 100
- - [{foo: 1, bar: 10}, {foo: 3, bar: 100}, {foo: 1, bar: 1}]
- [{foo: 1, bar: 10}, {foo: 3, bar: 100}, {foo: 1, bar: 1}]
- - [{foo: 1, bar: 10}, {foo: 3, bar: 100}, {foo: 1, bar: 1}]
```
## Group by field, with nuls
Given a sample.yml file of:
```yaml
- cat: dog
- foo: 1
bar: 10
- foo: 3
bar: 100
- no: foo for you
- foo: 1
bar: 1
[{cat: dog}, {foo: 1, bar: 10}, {foo: 3, bar: 100}, {no: foo for you}, {foo: 1, bar: 1}]
```
then
```bash
@@ -44,13 +29,10 @@ yq 'group_by(.foo)' sample.yml
```
will output
```yaml
- - cat: dog
- no: foo for you
- - foo: 1
bar: 10
- foo: 1
bar: 1
- - foo: 3
bar: 100
- - [{cat: dog}, {foo: 1, bar: 10}, {foo: 3, bar: 100}, {no: foo for you}, {foo: 1, bar: 1}]
- [{cat: dog}, {foo: 1, bar: 10}, {foo: 3, bar: 100}, {no: foo for you}, {foo: 1, bar: 1}]
- - [{cat: dog}, {foo: 1, bar: 10}, {foo: 3, bar: 100}, {no: foo for you}, {foo: 1, bar: 1}]
- [{cat: dog}, {foo: 1, bar: 10}, {foo: 3, bar: 100}, {no: foo for you}, {foo: 1, bar: 1}]
- - [{cat: dog}, {foo: 1, bar: 10}, {foo: 3, bar: 100}, {no: foo for you}, {foo: 1, bar: 1}]
```