geofffranks / spruce

A BOSH template merge tool
MIT License
427 stars 77 forks source link

Allow maps within an array to not contain the identifier key #307

Closed mattdodge closed 2 years ago

mattdodge commented 4 years ago

The feature of being able to insert/merge into an array of maps based on a key is super slick. It also requires that every map within the array contain said key though. It'd be nice if it would fail silently and ignore maps that didn't contain the key.

Example

Since many use this repo with Concourse pipelines, I'll use a pipeline-like example

pipeline.yml

jobs:
  - name: first
    plan:
      - get: resource
      - task: do stuff
      - task: other stuff
      - put: another

settings.yml

jobs:
  - name: first
    plan:
      - (( insert after task "do stuff" ))
      - task: more stuff

In this example I'm trying to add a task "more stuff" between the "do stuff" and "other stuff" tasks in the plan. Merging these two files yields an error though.

$ spruce merge pipeline.yml settings.yml
1 error(s) detected:
 - $.jobs.first.plan.0: original object does not contain the key 'task' - cannot merge by key

Ideally, this would be the result, it would ignore the maps that don't contain the task key in them.

jobs:
  - name: first
    plan:
      - get: resource
      - task: do stuff
      - task: more stuff
      - task: other stuff
      - put: another
doublespaces commented 3 years ago

I've found the insert operator to be useless for concourse because of this.

geofffranks commented 2 years ago

closing as stale