-
-
Notifications
You must be signed in to change notification settings - Fork 625
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
cannot override vars from console #850
Comments
Hello @AcLr If you want to override vars, you would be using go templates more like this version: '3'
tasks:
foo:
cmds:
- echo "{{.BAR | default "my-default-value"}}" or alternatively this version: '3'
tasks:
foo:
vars:
BAR: '{{.BAR | default "my-default-value"}}'
cmds:
- echo "{{.BAR}}" |
Thanks for your help, it is more clear now. BTW is it a good idea to make it possible to override variables in a way, introduced in my previous message? |
yea ofc, it is best to use them with default parameters tho, whole purpose of taskfiles is to shorten commands |
I mean in my previous message. Intuitively I want to define a variable with
|
@AcLr unless I'm misunderstanding your message, you can achieve exactly what you are asking using @mrwormhole's suggested method. The variables documentation describes this behaviour in the section: See example below: version: '3'
tasks:
example:
cmds:
- echo "{{.MYVAR | default "foo"}}" Run task normally (sets default value to "foo"):
Run task with variable overridden (sets value to "bar"):
If this does not fulfil your needs, please could you give an example of how you would expect this to work. I personally prefer that you need to explicitly describe how the default behaviour should work in the taskfile, rather than implicitly overriding variables. The latter could lead to unexpected behaviour in certain scenarios. |
I think that we really need command line options that would allow us to override vars, without any tricks. Vars have a lot of advantages over expansion of shell variables, which is not visible inside the console. Probably a syntax like |
@ssbarnea, why not use the existing way to set variables? Only thing missing would be to override stuff internally.
|
I feel that this issue is a too loosely defined. It is already possible to override vars, but you need to use Changing vars to override without that would be a backward incompatible change, so I'm closing this for now. Changes on this should be pushed to the (far in the future) next major release. |
This is what I ended up doing to give variables passed at runtime priority over dynamic global or task variables: vars:
DEFAULT_NAME:
sh: 'echo world'
NAME:
sh: 'echo {{ .NAME | default .DEFAULT_NAME }}'
tasks:
say_hello:
cmd: 'echo hello {{ .NAME }}' > task say_hello
hello world
> NAME=John task say_hello
hello John |
Example Taskfile showing the issue
I'm trying to override variable
BAR
:Is there any way to do it?
The text was updated successfully, but these errors were encountered: