1
0
mirror of https://github.com/go-task/task.git synced 2025-11-29 22:48:03 +02:00

Refactor: Add SmartJoin to handle IsAbs automatically

This commit is contained in:
Andrey Nering
2022-08-06 18:19:07 -03:00
parent c20842e7cd
commit c4e10ef0aa
12 changed files with 76 additions and 71 deletions

View File

@@ -12,6 +12,7 @@ import (
compilerv2 "github.com/go-task/task/v3/internal/compiler/v2"
compilerv3 "github.com/go-task/task/v3/internal/compiler/v3"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/internal/logger"
"github.com/go-task/task/v3/internal/output"
"github.com/go-task/task/v3/taskfile"
@@ -69,7 +70,7 @@ func (e *Executor) setupTempDir() error {
}
if os.Getenv("TASK_TEMP_DIR") == "" {
e.TempDir = filepath.Join(e.Dir, ".task")
e.TempDir = filepathext.SmartJoin(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 {
@@ -77,9 +78,9 @@ func (e *Executor) setupTempDir() error {
}
projectDir, _ := filepath.Abs(e.Dir)
projectName := filepath.Base(projectDir)
e.TempDir = filepath.Join(tempDir, projectName)
e.TempDir = filepathext.SmartJoin(tempDir, projectName)
} else {
e.TempDir = filepath.Join(e.Dir, os.Getenv("TASK_TEMP_DIR"))
e.TempDir = filepathext.SmartJoin(e.Dir, os.Getenv("TASK_TEMP_DIR"))
}
return nil