geofffranks / spruce

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

Support expressions with `||` operator #295

Closed loksonarius closed 3 years ago

loksonarius commented 5 years ago

It seems like the || (failover, default) operator only works to change what parameter is passed in to an operator. This seems to be the intended behavior as described in this doc.

From initial view of the operator, I was hoping that the case would've been that it evaluates a whole new operator on failure of the left-hand expression. This is so that I could do something like this in my document:

---
meta:
  user: (( grab $USER ))
  # Try grabbing the $ENV var if set, otherwise prompt the user for the value
  environment: (( grab $ENV || param "What environment are we testing in?" ))

Is there any way we could make the || operator work on entire operator expressions instead of just parameters? That is change (or add a new operator) that accomplishes:

foo: (( operator1 "reference to operator1's parameter" || operator2 "whole other parameter for a different operator" ))

instead of

foo: (( operator1 "reference to operator1's parameter" || "alternative parameter for operator1" ))

I don't have time right now to work on a PR for this, but would be willing to give it a shot later if it's something that'd be wanted/accepted in the project.

geofffranks commented 5 years ago

Totally in favor of this!

Sent from my iPhone

On Aug 28, 2019, at 10:11 AM, Dan notifications@github.com wrote:

It seems like the || (failover, default) operator only works to change what parameter is passed in to an operator. This seems to be the intended behavior as described in this doc.

From initial view of the operator, I was hoping that the case would've been that it evaluates a whole new operator on failure of the left-hand expression. This is so that I could do something like this in my document:


meta: user: (( grab $USER ))

Try grabbing the $ENV var if set, otherwise prompt the user for the value

environment: (( grab $ENV || param "What environment are we testing in?" )) Is there any way we could make the || operator work on entire operator expressions instead of just parameters? That is change (or add a new operator) that accomplishes:

foo: (( operator1 "reference to operator1's parameter" || operator2 "whole other parameter for a different operator" )) instead of

foo: (( operator1 "reference to operator1's parameter" || "alternative parameter for operator1" )) I don't have time right now to work on a PR for this, but would be willing to give it a shot later if it's something that'd be wanted/accepted in the project.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

loksonarius commented 5 years ago

Sweet. I'll add a reminder to come back to this when I finish my current work. I'm still absolutely down for anyone passing by to implement it as well if they're willing. 🙏

geofffranks commented 3 years ago

closing as stale