mirror of
https://github.com/go-task/task.git
synced 2025-03-19 21:17:46 +02:00
parent
d718527a1f
commit
7373639f57
@ -1,5 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
# Unreleased
|
||||
|
||||
- Expose `.TASK` variable in templates with the task name
|
||||
([#252](https://github.com/go-task/task/issues/252)).
|
||||
|
||||
# v3.0.0 - Preview 2
|
||||
|
||||
- Taskfiles in version 1 are not supported anymore
|
||||
|
@ -439,6 +439,8 @@ Example of sending parameters with environment variables:
|
||||
$ TASK_VARIABLE=a-value task do-something
|
||||
```
|
||||
|
||||
> TIP: A special variable `.TASK` is always available containg the task name.
|
||||
|
||||
Since some shells don't support above syntax to set environment variables
|
||||
(Windows) tasks also accepts a similar style when not in the beginning of
|
||||
the command. Variables given in this form are only visible to the task called
|
||||
|
@ -38,6 +38,7 @@ type CompilerV2 struct {
|
||||
// 5. Environment variables
|
||||
func (c *CompilerV2) GetVariables(t *taskfile.Task, call taskfile.Call) (taskfile.Vars, error) {
|
||||
vr := varResolver{c: c, vars: compiler.GetEnviron()}
|
||||
vr.vars["TASK"] = taskfile.Var{Static: t.Task}
|
||||
for _, vars := range []taskfile.Vars{c.Taskvars, c.TaskfileVars, call.Vars, t.Vars} {
|
||||
for i := 0; i < c.Expansions; i++ {
|
||||
vr.merge(vars)
|
||||
|
@ -98,6 +98,7 @@ func TestVarsV2(t *testing.T) {
|
||||
"nestedtmpl2_foo2.txt": "<no value>",
|
||||
"override.txt": "bar",
|
||||
"nested.txt": "Taskvars-TaskfileVars-TaskVars",
|
||||
"task_name.txt": "hello",
|
||||
},
|
||||
}
|
||||
tt.Run(t)
|
||||
|
1
testdata/vars/v2/Taskfile.yml
vendored
1
testdata/vars/v2/Taskfile.yml
vendored
@ -32,6 +32,7 @@ tasks:
|
||||
- echo '{{.NESTEDTMPL2_FOO2}}' > nestedtmpl2_foo2.txt
|
||||
- echo {{.OVERRIDE}} > override.txt
|
||||
- echo '{{.NESTED3}}' > nested.txt
|
||||
- echo '{{.TASK}}' > task_name.txt
|
||||
vars:
|
||||
FOO: foo
|
||||
BAR: $echo bar
|
||||
|
Loading…
x
Reference in New Issue
Block a user