Skip to content

Commit

Permalink
Improve merge docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Feb 9, 2024
1 parent 1d06d8b commit b55f52f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ NAME=mike yq -i '.a.b[0].c = strenv(NAME)' file.yaml

Merge multiple files
```bash
# merge two files
yq -n 'load("file1.yaml") * load("file2.yaml")'

# merge using globs:
# note the use of `ea` to evaluate all the files at once
# instead of in sequence
yq ea '. as $item ireduce ({}; . * $item )' path/to/*.yml
Expand Down
5 changes: 4 additions & 1 deletion pkg/yqlib/doc/operators/headers/multiply-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Like the multiple operator in jq, depending on the operands, this multiply operator will do different things. Currently numbers, arrays and objects are supported.

## Objects and arrays - merging
Objects are merged deeply matching on matching keys. By default, array values override and are not deeply merged.
Objects are merged _deeply_ matching on matching keys. By default, array values override and are not deeply merged.

You can use the add operator `+`, to shallow merge objects, see more info [here](https://mikefarah.gitbook.io/yq/operators/add).

Note that when merging objects, this operator returns the merged object (not the parent). This will be clearer in the examples below.

Expand All @@ -16,6 +18,7 @@ You can control how objects are merged by using one or more of the following fla
- `n` only merge _new_ fields
- `c` clobber custom tags

To perform a shallow merge only, use the add operator `+`, see more info [here](https://mikefarah.gitbook.io/yq/operators/add).

### Merge two files together
This uses the load operator to merge file2 into file1.
Expand Down
5 changes: 4 additions & 1 deletion pkg/yqlib/doc/operators/multiply-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Like the multiple operator in jq, depending on the operands, this multiply operator will do different things. Currently numbers, arrays and objects are supported.

## Objects and arrays - merging
Objects are merged deeply matching on matching keys. By default, array values override and are not deeply merged.
Objects are merged _deeply_ matching on matching keys. By default, array values override and are not deeply merged.

You can use the add operator `+`, to shallow merge objects, see more info [here](https://mikefarah.gitbook.io/yq/operators/add).

Note that when merging objects, this operator returns the merged object (not the parent). This will be clearer in the examples below.

Expand All @@ -16,6 +18,7 @@ You can control how objects are merged by using one or more of the following fla
- `n` only merge _new_ fields
- `c` clobber custom tags

To perform a shallow merge only, use the add operator `+`, see more info [here](https://mikefarah.gitbook.io/yq/operators/add).

### Merge two files together
This uses the load operator to merge file2 into file1.
Expand Down

0 comments on commit b55f52f

Please sign in to comment.