1
0
mirror of https://github.com/go-task/task.git synced 2025-06-17 00:17:51 +02:00

Add ROOT_DIR and TASKFILE_DIR special variables

Closes #215
This commit is contained in:
Andrey Nering
2022-09-03 18:14:54 -03:00
parent 1a0cc1d64d
commit f45dd11e53
9 changed files with 128 additions and 8 deletions

View File

@ -44,7 +44,13 @@ func (c *CompilerV3) FastGetVariables(t *taskfile.Task, call taskfile.Call) (*ta
func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluateShVars bool) (*taskfile.Vars, error) {
result := compiler.GetEnviron()
if t != nil {
result.Set("TASK", taskfile.Var{Static: t.Task})
specialVars, err := c.getSpecialVars(t)
if err != nil {
return nil, err
}
for k, v := range specialVars {
result.Set(k, taskfile.Var{Static: v})
}
}
getRangeFunc := func(dir string) func(k string, v taskfile.Var) error {
@ -165,3 +171,23 @@ func (c *CompilerV3) ResetCache() {
c.dynamicCache = nil
}
func (c *CompilerV3) getSpecialVars(t *taskfile.Task) (map[string]string, error) {
taskfileDir, err := c.getTaskfileDir(t)
if err != nil {
return nil, err
}
return map[string]string{
"TASK": t.Task,
"ROOT_DIR": c.Dir,
"TASKFILE_DIR": taskfileDir,
}, nil
}
func (c *CompilerV3) getTaskfileDir(t *taskfile.Task) (string, error) {
if t.IncludedTaskfile != nil {
return t.IncludedTaskfile.FullDirPath()
}
return c.Dir, nil
}