Inconsistent behavior when passing vars from CLI in different ways #483
Labels
area: env
Changes related to environment variables.
breaking change
Changes that are not backward compatible.
v3.4.2 (h1:DRATD5qavWC5FqpopJ/JcCelOMakFtGS7CubdZ/FiQY=)
Linux ... 5.4.0-70-generic #78-Ubuntu SMP ... x86_64 x86_64 x86_64 GNU/Linux
The issue description
The documentation implies that passing variables into
task
as env vars and as arguments has the same effect:However, this is not true. See the example and explanation below.
Example Taskfile showing the issue
The example
Running without args:
This shows the first issue:
env
is not expanded when used asvar
({{.EV}}
).Running with env vars:
The
var
was re-defined inenv
when executed asvar
({{.EV}}
) but it has the original value forV
itself. The documentation says, env vars have the lowest priority, so the latter is expected.Running with arguments:
Here, using
env
asvar
is not expanded as it was in the default execution. However, the explicitly passed value ofvar
is successfully re-defined and substituted when executing the var.The fix
First of all, executing env vars (
env
) as regular variables (vars
) gives unexpected results. I think it should either match to the value they produce when called as env vars (so$EV
and{{.EV}}
is always the same), or using them asvars
should be explicitly forbidden (since it's not documented anyway).Secondly, there is a mismatch between passing the
var
as env var and as a CLI argument. I think the easiest fix is to document the behavior, adding "Variables passed as CLI arguments" before "Global variables" in the list "Task will look for the below".Another solution for the latter is to prefer "Environment variables" over "Global variables". In that case, the behavior should match. I think it would make more sense since global variables are usually the defaults for the tasks, so explicitly specified variables from the CLI should re-define it. This one is breaking change, though.
The text was updated successfully, but these errors were encountered: