Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard sigil #2544

Open
casey opened this issue Dec 22, 2024 · 4 comments · May be fixed by #2547
Open

Guard sigil #2544

casey opened this issue Dec 22, 2024 · 4 comments · May be fixed by #2547

Comments

@casey
Copy link
Owner

casey commented Dec 22, 2024

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.)

@liquidaty
Copy link

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

@casey
Copy link
Owner Author

casey commented Dec 24, 2024

@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 }} …

@liquidaty
Copy link

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.

@laniakea64
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants