-
Notifications
You must be signed in to change notification settings - Fork 528
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
Feature request: Enable setting Variables in a Recipe #1023
Comments
Though not likely, this could be a breaking change for some recipes. Maybe a special function you could call at the end of the recipe could give back the normal just exit code behavior? Might that be a possibility @casey ? |
I wouldn't do this as a breaking change, since that would be too disruptive, so this would have to have syntax that didn't conflict with normal shell syntax. Also, |
I realized that the exit on non-zero codes can be recovered with #!/bin/sh -e. With that realization, it's easy for work around not having this feature in my current use. This feature might still be nice, as I think setting variables within scripts, without needing to add the she-bang line, would be more intuitive for users seeing just for the first time. Specifically, I think it's surprising and somewhat counter-intuitive to have to change the execution context with a shebang line just to set variables. @runeimp What scenario would be a breaking change? As I mentioned above, if the syntax was Using the |
@kurtbuilds hm, I'd thought of one immediately as I was reading the suggestion originally. But now I'm drawing a blank. Like I said it would be rare. But on the off chance it comes up it would likely be a complete nightmare to debug. And could effect recipes already in use that may be part of a CI/CD process. If I think of an, or remember my, example I'll update this issue. Sorry, my brain is done for the day I think. 😇 |
Similar feature request was discussed in a previous issue. It would be more useful to set the value computed within the shell process. k := ""
demo:
v=$(program); just --rpc-client k := "$v";
$a="{{k}}"; if [ $a = "ok" ]; then just --rpc-client run-code-in-parent-just-process; \
else just --rpc-client issue-cmd-from-child-process; fi If this feature just sets a fixed value (defined at the time of writing the justfile) when running to the specific line, the usage scenario is limited.
The above can be written as |
A clean way to do this could be a recipe attribute with parameters that allows to declare environment variables should be passed on to subsequent recipes. Something like: [ env VAR1 VAR2 ]
recipe1:
#!/bin/sh
export VAR1="hello"
export VAR2="world"
recipe2: recipe1
#!/bin/sh
echo $VAR1 $VAR2 # will output "hello world" could work if I'm using a shebang in This could also make things like this work [env GREETING]
recipe:
export GREETING="hello"
echo "$GREETING world" |
There's already a great docs section that talks about Setting Variables in a Recipe.
This is a feature that I frequently miss, and sometimes I want to avoid the suggested solution of using a single shell for the recipe using the she-bang line. (Typically, this is when I want the exit-code behavior of just, as using a she-bang line changes that functionality.)
It seems like it could be achieved by mimicking a shell's
export
behavior; that is, if the recipe line starts withexport
then add the resulting variable to the just process environment.Since each line is within a shell, any current shell line with
export NAME=variable
is effectively a no-op, so this feature only extends, but does not modify, existing functionality.The text was updated successfully, but these errors were encountered: