From 05ee3403ca14ef248c39872d78e7b533024a2226 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 29 Aug 2022 18:31:50 +1000 Subject: [PATCH] v4.27.3 updates --- operators/assign-update.md | 39 +++++++++++++++++++++++++++++++++++ operators/multiply-merge.md | 24 +++++++++++++++++++++ operators/string-operators.md | 20 ++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/operators/assign-update.md b/operators/assign-update.md index ef97571d..af2d80c3 100644 --- a/operators/assign-update.md +++ b/operators/assign-update.md @@ -7,6 +7,11 @@ Which will assign the LHS node values to the RHS node values. The RHS expression ### relative form: `|=` This will do a similar thing to the plain form, however, the RHS expression is run against _the LHS nodes_. This is useful for updating values based on old values, e.g. increment. + + +### Flags +- `c` clobber custom tags + {% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified. @@ -235,3 +240,37 @@ a: - bogs ``` +## Custom types are maintained by default +Given a sample.yml file of: +```yaml +a: !cat meow +b: !dog woof +``` +then +```bash +yq '.a = .b' sample.yml +``` +will output +```yaml +a: !cat woof +b: !dog woof +``` + +## Custom types: clovver +Use the `c` option to clobber custom tags + +Given a sample.yml file of: +```yaml +a: !cat meow +b: !dog woof +``` +then +```bash +yq '.a =c .b' sample.yml +``` +will output +```yaml +a: !dog woof +b: !dog woof +``` + diff --git a/operators/multiply-merge.md b/operators/multiply-merge.md index 9f04daed..c203e357 100644 --- a/operators/multiply-merge.md +++ b/operators/multiply-merge.md @@ -14,6 +14,7 @@ You can control how objects are merged by using one or more of the following fla - `d` deeply merge arrays - `?` only merge _existing_ fields - `n` only merge _new_ fields +- `c` clobber custom tags ### Merge two files together @@ -481,3 +482,26 @@ b: !goat dog: woof ``` +## Custom types: clobber tags +Use the `c` option to clobber custom tags. Note that the second tag is now used + +Given a sample.yml file of: +```yaml +a: !horse + cat: meow +b: !goat + dog: woof +``` +then +```bash +yq '.a *=c .b' sample.yml +``` +will output +```yaml +a: !goat + cat: meow + dog: woof +b: !goat + dog: woof +``` + diff --git a/operators/string-operators.md b/operators/string-operators.md index 9f0f3227..3882a67a 100644 --- a/operators/string-operators.md +++ b/operators/string-operators.md @@ -112,6 +112,26 @@ will output cat; meow; 1; ; true ``` +## Trim strings +Given a sample.yml file of: +```yaml +- ' cat' +- 'dog ' +- ' cow cow ' +- horse +``` +then +```bash +yq '.[] | trim' sample.yml +``` +will output +```yaml +cat +dog +cow cow +horse +``` + ## Match string Given a sample.yml file of: ```yaml