Guard sigil
We have @ and - sigils which control linewise recipe execution. I thought that we could consider having a "guard" sigil which indicates that an error on a particular line should terminate the execution of the current recipe, but not the whole run.
For example, to make a recipe only execute if the environment variable FOO is set to yes:
foo:
?[[ $FOO == yes]]
# the rest of the recipe
This is backwards incompatible, so would need a setting to opt-in to the new behavior. (Although it's unlikely to break most justfile, ? at the beginning of the line is unlikely in sh and derivatives, and I think most scripting languages that people are likely to use.)
A further enhancement that would be nice is a way for the condition to be evaluated without invoking the shell e.g.:
foo:
?{{ assert(foo == 'yes') }}
# the rest of the recipe
@liquidaty There would have to be a different syntax for this, since I believe the pattern of having an interpolation first is common.
For example, if someone wanted to use Python to perform a test, they might do:
python := '/usr/bin/python3'
foo:
?{{ python }} …
There would have to be a different syntax for this
Got it. Any syntax would be fine by me, but as I'm a new just user, that doesn't count for much.
That said, if it can be done, then, it seems logical (to me at least) to allow {{ assert(...) }} inside the recipe (and if it wasn't allowed before, it wouldn't seem to cause any compatibility issues to allow it). Currently, I can do this outside of a recipe:
a := if b == c { ... } else { ... }
d := assert(...)
and I can do this inside a recipe:
{{ if b == c { ... } else { ... } }}
So it seemed logical to me that anything to the right of := outside a recipe, could also be put inside {{ }} inside a recipe, and that therefore this would also work inside a recipe:
{{ assert(...) }}
Though I guess maybe the issue is that assert raises an error or returns a different data type than a shell command's exit code.
it seemed logical to me that anything to the right of
:=outside a recipe, could also be put inside{{ }}inside a recipe
Correct.
and that therefore this would also work inside a recipe:
{{ assert(...) }}
Yes it does work. I have justfiles that use assert() like that.
Yes it does work. I have justfiles that use
assert()like that.
I was looking for something like an assert function...
Is it documented anywhere? I didn't find it here https://just.systems/man/en/functions.html or via the search feature