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:
19
task.go
19
task.go
@@ -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`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user