Fixed typo

This commit is contained in:
Mike Farah 2020-11-20 15:31:49 +11:00
parent f03005f86d
commit 663413cd7a
2 changed files with 21 additions and 134 deletions

View File

@ -1,157 +1,44 @@
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.
## Examples
### Update node to be the child value
Given a sample.yml file of:
```yaml
a:
b:
g: foof
```
then
### OR example
Running
```bash
yq eval '.a |= .b' sample.yml
yq eval --null-input 'true or false'
```
will output
```yaml
a:
g: foof
true
```
### Update node to be the sibling value
Given a sample.yml file of:
```yaml
a:
b: child
b: sibling
```
then
### AND example
Running
```bash
yq eval '.a = .b' sample.yml
yq eval --null-input 'true and false'
```
will output
```yaml
a: sibling
b: sibling
false
```
### Updated multiple paths
### Matching nodes with select, equals and or
Given a sample.yml file of:
```yaml
a: fieldA
b: fieldB
c: fieldC
- a: bird
b: dog
- a: frog
b: bird
- a: cat
b: fly
```
then
```bash
yq eval '(.a, .c) |= "potatoe"' sample.yml
yq eval '.[] | select(.a == "cat" or .b == "dog")' sample.yml
```
will output
```yaml
a: potatoe
b: fieldB
c: potatoe
```
### Update string value
Given a sample.yml file of:
```yaml
a:
b: apple
```
then
```bash
yq eval '.a.b = "frog"' sample.yml
```
will output
```yaml
a:
b: frog
```
### Update string value via |=
Note there is no difference between `=` and `|=` when the RHS is a scalar
Given a sample.yml file of:
```yaml
a:
b: apple
```
then
```bash
yq eval '.a.b |= "frog"' sample.yml
```
will output
```yaml
a:
b: frog
```
### Update selected results
Given a sample.yml file of:
```yaml
a:
b: apple
c: cactus
```
then
```bash
yq eval '.a[] | select(. == "apple") |= "frog"' sample.yml
```
will output
```yaml
a:
b: frog
c: cactus
```
### Update array values
Given a sample.yml file of:
```yaml
- candy
- apple
- sandy
```
then
```bash
yq eval '.[] | select(. == "*andy") |= "bogs"' sample.yml
```
will output
```yaml
- bogs
- apple
- bogs
```
### Update empty object
Given a sample.yml file of:
```yaml
'': null
```
then
```bash
yq eval '.a.b |= "bogs"' sample.yml
```
will output
```yaml
'': null
a:
b: bogs
```
### Update empty object and array
Given a sample.yml file of:
```yaml
'': null
```
then
```bash
yq eval '.a.b[0] |= "bogs"' sample.yml
```
will output
```yaml
'': null
a:
b:
- bogs
a: bird
b: dog
a: cat
b: fly
```

View File

@ -52,5 +52,5 @@ func TestBooleanOperatorScenarios(t *testing.T) {
for _, tt := range booleanOperatorScenarios {
testScenario(t, &tt)
}
documentScenarios(t, "Boolean Operators", assignOperatorScenarios)
documentScenarios(t, "Boolean Operators", booleanOperatorScenarios)
}