1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00

Allow override the .task dir location with the TASK_TEMP_DIR env

This commit is contained in:
Andrey Nering
2022-07-08 14:40:10 -03:00
parent f54fef7e7b
commit fedb68cde7
6 changed files with 61 additions and 17 deletions

19
task.go
View File

@@ -6,6 +6,8 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"sync"
"sync/atomic"
@@ -34,6 +36,7 @@ type Executor struct {
Taskfile *taskfile.Taskfile
Dir string
TempDir string
Entrypoint string
Force bool
Watch bool
@@ -151,6 +154,22 @@ func (e *Executor) Setup() error {
Color: e.Color,
}
if e.TempDir == "" {
if os.Getenv("TASK_TEMP_DIR") == "" {
e.TempDir = filepath.Join(e.Dir, ".task")
} else if filepath.IsAbs(os.Getenv("TASK_TEMP_DIR")) || strings.HasPrefix(os.Getenv("TASK_TEMP_DIR"), "~") {
tempDir, err := execext.Expand(os.Getenv("TASK_TEMP_DIR"))
if err != nil {
return err
}
projectDir, _ := filepath.Abs(e.Dir)
projectName := filepath.Base(projectDir)
e.TempDir = filepath.Join(tempDir, projectName)
} else {
e.TempDir = filepath.Join(e.Dir, os.Getenv("TASK_TEMP_DIR"))
}
}
if v < 2 {
return fmt.Errorf(`task: Taskfile versions prior to v2 are not supported anymore`)
}