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. 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 ## Examples
### Update node to be the child value ### OR example
Given a sample.yml file of: Running
```yaml
a:
b:
g: foof
```
then
```bash ```bash
yq eval '.a |= .b' sample.yml yq eval --null-input 'true or false'
``` ```
will output will output
```yaml ```yaml
a: true
g: foof
``` ```
### Update node to be the sibling value ### AND example
Given a sample.yml file of: Running
```yaml
a:
b: child
b: sibling
```
then
```bash ```bash
yq eval '.a = .b' sample.yml yq eval --null-input 'true and false'
``` ```
will output will output
```yaml ```yaml
a: sibling false
b: sibling
``` ```
### Updated multiple paths ### Matching nodes with select, equals and or
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml
a: fieldA - a: bird
b: fieldB b: dog
c: fieldC - a: frog
b: bird
- a: cat
b: fly
``` ```
then then
```bash ```bash
yq eval '(.a, .c) |= "potatoe"' sample.yml yq eval '.[] | select(.a == "cat" or .b == "dog")' sample.yml
``` ```
will output will output
```yaml ```yaml
a: potatoe a: bird
b: fieldB b: dog
c: potatoe a: cat
``` b: fly
### 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
``` ```

View File

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