mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-05 00:54:51 +08:00
Multiply, substract with custom types
This commit is contained in:
@@ -7,6 +7,8 @@ Add behaves differently according to the type of the LHS:
|
||||
|
||||
Use `+=` as append assign for things like increment. Note that `.a += .x` is equivalent to running `.a = .a + .x`.
|
||||
|
||||
Add is not (yet) supported for maps - however you can use merge `*` which will have a similar effect...
|
||||
|
||||
## Concatenate and assign arrays
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
@@ -266,7 +268,7 @@ cat
|
||||
```
|
||||
|
||||
## Custom types: that are really strings
|
||||
when custom tags are encountered, yq will try to decode the underlying type.
|
||||
When custom tags are encountered, yq will try to decode the underlying type.
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
@@ -284,7 +286,7 @@ b: !goat _meow
|
||||
```
|
||||
|
||||
## Custom types: that are really numbers
|
||||
when custom tags are encountered, yq will try to decode the underlying type.
|
||||
When custom tags are encountered, yq will try to decode the underlying type.
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
|
||||
@@ -6,3 +6,5 @@ Add behaves differently according to the type of the LHS:
|
||||
* string scalars: concatenate
|
||||
|
||||
Use `+=` as append assign for things like increment. Note that `.a += .x` is equivalent to running `.a = .a + .x`.
|
||||
|
||||
Add is not (yet) supported for maps - however you can use merge `*` which will have a similar effect...
|
||||
|
||||
@@ -410,3 +410,44 @@ thing: foobar_thing
|
||||
b: foobarList_b
|
||||
```
|
||||
|
||||
## Custom types: that are really numbers
|
||||
When custom tags are encountered, yq will try to decode the underlying type.
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: !horse 2
|
||||
b: !goat 3
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a = .a * .b' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
a: !horse 6
|
||||
b: !goat 3
|
||||
```
|
||||
|
||||
## Custom types: that are really maps
|
||||
Custom tags will be maintained.
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: !horse
|
||||
cat: meow
|
||||
b: !goat
|
||||
dog: woof
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a = .a * .b' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
a: !horse
|
||||
cat: meow
|
||||
dog: woof
|
||||
b: !goat
|
||||
dog: woof
|
||||
```
|
||||
|
||||
|
||||
@@ -111,3 +111,21 @@ a: 2
|
||||
b: 4
|
||||
```
|
||||
|
||||
## Custom types: that are really numbers
|
||||
When custom tags are encountered, yq will try to decode the underlying type.
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: !horse 2
|
||||
b: !goat 1
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a -= .b' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
a: !horse 1
|
||||
b: !goat 1
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user