fix: cli variables should take priority over aaskfile defaults (#2589)

When using `task FOO=bar` with a Taskfile containing
`FOO: '{{.FOO | default "foo"}}'`, the CLI value was being
overwritten by the Taskfile default.

Split the variable merging into two steps:
1. Merge CLI variables (FOO=bar) first so they override Taskfile vars
2. ReverseMerge special variables (CLI_ARGS, CLI_FORCE, etc.) so
   they're available for templating in Taskfile vars

Fixes regression introduced in #2403.

Co-authored-by: Timothy Rule <timothy.rule@gmail.com>
This commit is contained in:
Valentin Maerten
2025-12-18 21:50:00 +01:00
committed by GitHub
parent 28fee2c356
commit 9b95e758f4
5 changed files with 39 additions and 8 deletions

View File

@@ -49,3 +49,10 @@ tasks:
- echo "{{.MESSAGE}}"
from-dot-env: echo '{{.DOT_ENV_VAR}}'
# Test that CLI variables take priority over Taskfile defaults
cli-var-priority:
vars:
CLI_VAR: '{{.CLI_VAR | default "default_value"}}'
cmds:
- echo '{{.CLI_VAR}}'

View File

@@ -0,0 +1 @@
default_value

View File

@@ -0,0 +1 @@
from_cli