1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Added pipe and length docs, fix pipe precedence

This commit is contained in:
Mike Farah
2020-12-01 17:58:07 +11:00
parent da027f69d7
commit c9dbf04da3
18 changed files with 233 additions and 71 deletions

View File

@@ -8,7 +8,7 @@ This will do a similar thing to the plain form, however, the RHS expression is r
## Create yaml file
Running
```bash
yq eval --null-input '(.a.b = "cat") | (.x = "frog")'
yq eval --null-input '.a.b = "cat" | .x = "frog"'
```
will output
```yaml
@@ -112,7 +112,7 @@ a:
```
then
```bash
yq eval '.a.[] | select(. == "apple") |= "frog"' sample.yml
yq eval '(.a.[] | select(. == "apple")) = "frog"' sample.yml
```
will output
```yaml
@@ -130,7 +130,7 @@ Given a sample.yml file of:
```
then
```bash
yq eval '.[] | select(. == "*andy") |= "bogs"' sample.yml
yq eval '(.[] | select(. == "*andy")) = "bogs"' sample.yml
```
will output
```yaml

54
pkg/yqlib/doc/Length.md Normal file
View File

@@ -0,0 +1,54 @@
Returns the lengths of the nodes. Length is defined according to the type of the node.
## String length
returns length of string
Given a sample.yml file of:
```yaml
a: cat
```
then
```bash
yq eval '.a | length' sample.yml
```
will output
```yaml
3
```
## Map length
returns number of entries
Given a sample.yml file of:
```yaml
a: cat
c: dog
```
then
```bash
yq eval 'length' sample.yml
```
will output
```yaml
2
```
## Array length
returns number of elements
Given a sample.yml file of:
```yaml
- 2
- 4
- 6
- 8
```
then
```bash
yq eval 'length' sample.yml
```
will output
```yaml
4
```

35
pkg/yqlib/doc/Pipe.md Normal file
View File

@@ -0,0 +1,35 @@
Pipe the results of an expression into another. Like the bash operator.
## Simple Pipe
Given a sample.yml file of:
```yaml
a:
b: cat
```
then
```bash
yq eval '.a | .b' sample.yml
```
will output
```yaml
cat
```
## Multiple updates
Given a sample.yml file of:
```yaml
a: cow
b: sheep
c: same
```
then
```bash
yq eval '.a = "cat" | .b = "dog"' sample.yml
```
will output
```yaml
a: cat
b: dog
c: same
```

View File

@@ -0,0 +1 @@
Returns the lengths of the nodes. Length is defined according to the type of the node.

View File

@@ -0,0 +1 @@
Pipe the results of an expression into another. Like the bash operator.