mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-05 00:54:51 +08:00
Update document generation script
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# Boolean Operators
|
||||
|
||||
The `or` and `and` operators take two parameters and return a boolean result.
|
||||
The `or` and `and` operators take two parameters and return a boolean result.
|
||||
|
||||
`not` flips a boolean from true to false, or vice versa.
|
||||
`not` flips a boolean from true to false, or vice versa.
|
||||
|
||||
`any` will return `true` if there are any `true` values in a array sequence, and `all` will return true if _all_ elements in an array are true.
|
||||
|
||||
@@ -11,37 +11,27 @@ The `or` and `and` operators take two parameters and return a boolean result.
|
||||
These are most commonly used with the `select` operator to filter particular nodes.
|
||||
|
||||
## `or` example
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input 'true or false'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
true
|
||||
```
|
||||
|
||||
## `and` example
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input 'true and false'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
false
|
||||
```
|
||||
|
||||
## Matching nodes with select, equals and or
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
- a: bird
|
||||
b: dog
|
||||
@@ -50,15 +40,11 @@ Given a sample.yml file of:
|
||||
- a: cat
|
||||
b: fly
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '[.[] | select(.a == "cat" or .b == "dog")]' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
- a: bird
|
||||
b: dog
|
||||
@@ -67,50 +53,36 @@ will output
|
||||
```
|
||||
|
||||
## `any` returns true if any boolean in a given array is true
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
- false
|
||||
- true
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'any' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
true
|
||||
```
|
||||
|
||||
## `any` returns false for an empty array
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
[]
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'any' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
false
|
||||
```
|
||||
|
||||
## `any_c` returns true if any element in the array is true for the given condition.
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
a:
|
||||
- rad
|
||||
@@ -119,65 +91,47 @@ b:
|
||||
- meh
|
||||
- whatever
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '.[] |= any_c(. == "awesome")' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
a: true
|
||||
b: false
|
||||
```
|
||||
|
||||
## `all` returns true if all booleans in a given array are true
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
- true
|
||||
- true
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'all' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
true
|
||||
```
|
||||
|
||||
## `all` returns true for an empty array
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
[]
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval 'all' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
true
|
||||
```
|
||||
|
||||
## `all_c` returns true if all elements in the array are true for the given condition.
|
||||
|
||||
Given a sample.yml file of:
|
||||
|
||||
```yaml
|
||||
a:
|
||||
- rad
|
||||
@@ -186,114 +140,83 @@ b:
|
||||
- meh
|
||||
- 12
|
||||
```
|
||||
|
||||
then
|
||||
|
||||
```bash
|
||||
yq eval '.[] |= all_c(tag == "!!str")' sample.yml
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
a: true
|
||||
b: false
|
||||
```
|
||||
|
||||
## Not true is false
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input 'true | not'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
false
|
||||
```
|
||||
|
||||
## Not false is true
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input 'false | not'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
true
|
||||
```
|
||||
|
||||
## String values considered to be true
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input '"cat" | not'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
false
|
||||
```
|
||||
|
||||
## Empty string value considered to be true
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input '"" | not'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
false
|
||||
```
|
||||
|
||||
## Numbers are considered to be true
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input '1 | not'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
false
|
||||
```
|
||||
|
||||
## Zero is considered to be true
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input '0 | not'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
false
|
||||
```
|
||||
|
||||
## Null is considered to be false
|
||||
|
||||
Running
|
||||
|
||||
```bash
|
||||
yq eval --null-input '~ | not'
|
||||
```
|
||||
|
||||
will output
|
||||
|
||||
```yaml
|
||||
true
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user