Skip to content

Multiply (merge) support appending arrays without creating duplicates #1702

Open
@mikkel3000

Description

@mikkel3000

Request
When merging yaml files containing arrays using the "+" flag, it will create duplicates if some of the arrays are equal in the two documents. I would like an additional flag("a" in the example) which appends lists without creating duplicates.

Example
If we have data1.yml like:

equalList:
  - a
  - b
changedList:
  - a
  - b

And data2.yml like:

equalList:
  - a
  - b
changedList:
  - c

And we run a command:

yq eval-all '. as $item ireduce ({}; . *+ $item)' data1.yml data2.yml

the current output is:

equalList:
  - a
  - b
  - a
  - b
changedList:
  - a
  - b
  - c

With a new flag ("a" in this example) the output should be:

yq eval-all '. as $item ireduce ({}; . *a $item)' data1.yml data2.yml
equalList:
  - a
  - b
changedList:
  - a
  - b
  - c

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions