1
0
mirror of https://github.com/go-task/task.git synced 2025-11-27 22:38:20 +02:00

feat: taskfile special variable (#1523)

This commit is contained in:
Pete Davison
2024-03-03 16:45:23 -06:00
committed by GitHub
parent d30539c17e
commit aff1f5316d
4 changed files with 4 additions and 16 deletions

View File

@@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"path/filepath"
"strings"
"sync"
@@ -208,24 +209,13 @@ func (c *Compiler) ResetCache() {
}
func (c *Compiler) getSpecialVars(t *ast.Task) (map[string]string, error) {
taskfileDir, err := c.getTaskfileDir(t)
if err != nil {
return nil, err
}
return map[string]string{
"TASK": t.Task,
"ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint),
"ROOT_DIR": c.Dir,
"TASKFILE_DIR": taskfileDir,
"TASKFILE": t.Location.Taskfile,
"TASKFILE_DIR": filepath.Dir(t.Location.Taskfile),
"USER_WORKING_DIR": c.UserWorkingDir,
"TASK_VERSION": version.GetVersion(),
}, nil
}
func (c *Compiler) getTaskfileDir(t *ast.Task) (string, error) {
if t.IncludedTaskfile != nil {
return t.IncludedTaskfile.FullDirPath()
}
return c.Dir, nil
}