mirror of
https://github.com/go-task/task.git
synced 2025-06-15 00:15:10 +02:00
feat: add ALIAS
special var (#1764)
This commit is contained in:
@ -46,7 +46,7 @@ func (c *Compiler) FastGetVariables(t *ast.Task, call *ast.Call) (*ast.Vars, err
|
|||||||
func (c *Compiler) getVariables(t *ast.Task, call *ast.Call, evaluateShVars bool) (*ast.Vars, error) {
|
func (c *Compiler) getVariables(t *ast.Task, call *ast.Call, evaluateShVars bool) (*ast.Vars, error) {
|
||||||
result := GetEnviron()
|
result := GetEnviron()
|
||||||
if t != nil {
|
if t != nil {
|
||||||
specialVars, err := c.getSpecialVars(t)
|
specialVars, err := c.getSpecialVars(t, call)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -179,9 +179,10 @@ func (c *Compiler) ResetCache() {
|
|||||||
c.dynamicCache = nil
|
c.dynamicCache = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Compiler) getSpecialVars(t *ast.Task) (map[string]string, error) {
|
func (c *Compiler) getSpecialVars(t *ast.Task, call *ast.Call) (map[string]string, error) {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"TASK": t.Task,
|
"TASK": t.Task,
|
||||||
|
"ALIAS": call.Task,
|
||||||
"TASK_EXE": filepath.ToSlash(os.Args[0]),
|
"TASK_EXE": filepath.ToSlash(os.Args[0]),
|
||||||
"ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint),
|
"ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint),
|
||||||
"ROOT_DIR": c.Dir,
|
"ROOT_DIR": c.Dir,
|
||||||
|
10
testdata/special_vars/Taskfile.yml
vendored
10
testdata/special_vars/Taskfile.yml
vendored
@ -6,8 +6,16 @@ includes:
|
|||||||
dir: ./included
|
dir: ./included
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
print-task: echo {{.TASK}}
|
print-task:
|
||||||
|
aliases: [echo-task]
|
||||||
|
cmds:
|
||||||
|
- echo {{.TASK}}
|
||||||
print-root-dir: echo {{.ROOT_DIR}}
|
print-root-dir: echo {{.ROOT_DIR}}
|
||||||
print-taskfile: echo {{.TASKFILE}}
|
print-taskfile: echo {{.TASKFILE}}
|
||||||
print-taskfile-dir: echo {{.TASKFILE_DIR}}
|
print-taskfile-dir: echo {{.TASKFILE_DIR}}
|
||||||
print-task-version: echo {{.TASK_VERSION}}
|
print-task-version: echo {{.TASK_VERSION}}
|
||||||
|
print-task-alias:
|
||||||
|
aliases: [echo-task-alias]
|
||||||
|
cmds:
|
||||||
|
- echo "{{.ALIAS}}"
|
||||||
|
print-task-alias-default: echo "{{.ALIAS}}"
|
||||||
|
10
testdata/special_vars/included/Taskfile.yml
vendored
10
testdata/special_vars/included/Taskfile.yml
vendored
@ -1,8 +1,16 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
print-task: echo {{.TASK}}
|
print-task:
|
||||||
|
aliases: [echo-task]
|
||||||
|
cmds:
|
||||||
|
- echo {{.TASK}}
|
||||||
print-root-dir: echo {{.ROOT_DIR}}
|
print-root-dir: echo {{.ROOT_DIR}}
|
||||||
print-taskfile: echo {{.TASKFILE}}
|
print-taskfile: echo {{.TASKFILE}}
|
||||||
print-taskfile-dir: echo {{.TASKFILE_DIR}}
|
print-taskfile-dir: echo {{.TASKFILE_DIR}}
|
||||||
print-task-version: echo {{.TASK_VERSION}}
|
print-task-version: echo {{.TASK_VERSION}}
|
||||||
|
print-task-alias:
|
||||||
|
aliases: [echo-task-alias]
|
||||||
|
cmds:
|
||||||
|
- echo "{{.ALIAS}}"
|
||||||
|
print-task-alias-default: echo "{{.ALIAS}}"
|
||||||
|
@ -107,6 +107,7 @@ special variable will be overridden.
|
|||||||
| `CLI_SILENT` | A boolean containing whether the `--silent` flag was set. |
|
| `CLI_SILENT` | A boolean containing whether the `--silent` flag was set. |
|
||||||
| `CLI_VERBOSE` | A boolean containing whether the `--verbose` flag was set. |
|
| `CLI_VERBOSE` | A boolean containing whether the `--verbose` flag was set. |
|
||||||
| `TASK` | The name of the current task. |
|
| `TASK` | The name of the current task. |
|
||||||
|
| `ALIAS` | The alias used for the current task, otherwise matches `TASK` |
|
||||||
| `TASK_EXE` | The Task executable name or path. |
|
| `TASK_EXE` | The Task executable name or path. |
|
||||||
| `ROOT_TASKFILE` | The absolute path of the root Taskfile. |
|
| `ROOT_TASKFILE` | The absolute path of the root Taskfile. |
|
||||||
| `ROOT_DIR` | The absolute path of the root Taskfile directory. |
|
| `ROOT_DIR` | The absolute path of the root Taskfile directory. |
|
||||||
|
Reference in New Issue
Block a user