geofffranks / spruce

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

Support negating booleans #342

Closed OddBloke closed 3 years ago

OddBloke commented 3 years ago

We're using spruce to merge a settings.yml into a Concourse pipeline.yml template (a la https://github.com/starkandwayne/pipeline-templates). I want to add a meta boolean flag to control a behaviour which requires setting boolean values in multiple places in the template. Of course, I'm using grab to handle this, but I've run into a problem: some of the values I want to set should match the flag value (i.e. my_bool is true => those settings are true), but some are negated (i.e. my_bool is true => those settings are false). AFAICT, I can only use grab to fill in the matching settings: I would also like to be able to fill in the negated settings.

(Apologies if I missed existing support for this!)

geofffranks commented 3 years ago

For a native way to do this, you could PR new operator (! or negate?) that works similar to grab, but only for booleans, and flips the value.

For a non-native way, you could move that boolean out of settings.yml, and set it as two environment variables, one for the setting, and one using logic in bash to negate it.