geofffranks / spruce

A BOSH template merge tool
MIT License
433 stars 78 forks source link

Allow ((load)) operator to work on references #331

Closed dennisjbell closed 4 years ago

dennisjbell commented 4 years ago

This change allows the load operator to work on references, as well as fixes a bug that breaks on absolute paths.

This allows loads that build the path using environment variables, which is my use case, or using paths based on components supplied in other merged files.

Fixes #284

Validation:

~/code/src/github.com/geofffranks/spruce ∴ cat > users.yml
- name: bob
  color: green

- name: fred
  color: red
^D

~/code/src/github.com/geofffranks/spruce ∴ cat > main.yml
meta:
  path: (( concat $PWD "/users.yml" ))

params:
  users: (( load meta.path ))
^D

~/code/src/github.com/geofffranks/spruce ∴ /usr/local/bin/spruce merge main.yml
1 error(s) detected:
 - $.params.users: load operator only expects one literal argument (quoted string)

~/code/src/github.com/geofffranks/spruce ∴ ./spruce merge main.yml
meta:
  path: /Users/dbell/code/src/github.com/geofffranks/spruce/users.yml
params:
  users:
  - color: green
    name: bob
  - color: red
    name: fred

~/code/src/github.com/geofffranks/spruce ∴ cat > fail.yml
params:
  users: (( load "/Users/dbell/code/src/github.com/geofffranks/spruce/users.yml" ))
^D

~/code/src/github.com/geofffranks/spruce ∴ /usr/local/bin/spruce merge fail.yml
1 error(s) detected:
 - $.params.users: Get /Users/dbell/code/src/github.com/geofffranks/spruce/users.yml: unsupported protocol scheme ""

~/code/src/github.com/geofffranks/spruce ∴ ./spruce merge fail.yml
params:
  users:
  - color: green
    name: bob
  - color: red
    name: fred
geofffranks commented 4 years ago

Can you turn your validation into tests for cmd/spruce/main_test.go?

dennisjbell commented 4 years ago

Tests added