Variables provided via command line should override ones set in Taskfile.yaml #1006
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey @andreynering! There's an issue with command line variable precedence which has bothered me for a while. I think it has created some confusion in issues as well, and to this day the documentation doesn't really clarify it. So I think there is an opportunity for improvement/change here.
Namely, CLI tools usually operate in a way that command line arguments take precedence over configuration files, and values set in environment variables. This seems to be the "unix way" since early days.
The problem with task today is that if you have a variable defined on included file level, or on a task vars section, you have to jump through hoops to override them per execution.
In other words, my "expected behavior" only works, when the variable is defined on root task level. And it does not work, when I define the variable in included task level, or for a specific task. Some examples, all executed with
task YOU=cliWorks as expected, prints "Hello cli"
Works:
Does not work, prints "Hello World":
Doesn't work:
This works as a small demo, but I have a similar setup where it does not. I just haven't figured out yet where the conflict is:
etc..
To demo what I'm after I changed the evaluation order in the CompilerV3.getVariables. This is not a working fix as it breaks existing behavior regarding environment evaluation, highlighted by broken tests. But if you're willing to take this behavior in, I'll try to fix it properly.