Conditional recipe triggering
- Dominant language
- Rust
- Stars
- 35.8k
- Forks
- 846
- Avg merge
- 27m
- Merged PRs (30d)
- 3
Description
### Feature
Would it be possible to expand recipe execution logic with some boolean operations?
```just
# Some flag to toggle stuff
flag := true
# Run bar if flag is set to true, otherwise baz.
foo: (flag ? bar : baz)
echo "foo done"
# Forward arg to quux if flag is set, otherwise baz.
qux arg="": (flag ? (quux arg) : baz)
echo "qux done"
# barsay
bar:
echo "bar"
# bazsay
baz:
echo "baz"
# customsay
quux arg="":
echo {{arg}}
```
Regarding the flag value and whether or not that should be a boolean type: I don't know for sure, but the alternative could be checking whether a variable holds any value or is empty (checking for `flag != ""` internally, as an alternative to `true`)
### Current workaround
The current alternative would be some form of a private recipe with interpolation I think
```just
# Some flag to toggle stuff
flag := "true"
# Run bar if flag is set to true, otherwise baz.
foo: _foo
echo "foo done"
# Inner foo
_foo:
{{ if flag != "" { "just bar" } else { "just baz" } }}
# Forward arg to quux if flag is set, otherwise baz.
qux arg="": (_qux arg)
echo "qux done"
# Inner qux
_qux arg="":
{{ if flag != "" { "just quux \"" + arg + "\"" } else { "just baz" } }}
# barsay
bar:
echo "bar"
# bazsay
baz:
echo "baz"
# customsay
quux arg="":
echo {{arg}}
```
Which does not account for some intricalities like justfiles with different filenames and execution order when these toggled recipes are in-between recipes that could be triggered regularly in the main recipe line.
### Alternative ideas
I think the current `if {} else {}`` conditionals might get a bit too wordy in the forwarding line and create confusion with their interpolated invocations. At least I think this looks not as great:
```just
foo: (if flag { bar } else { baz })
```
Especially since this does not work when pasted into a `{{ }}` interpolation in the body, which could cause confusion.
Contributor guide
Assessment
This issue has not been assessed yet.