1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

fix: taskfile directory (#1530)

* fix: taskfile directory

* tests: add tests for special vars when running from a subdirectory
This commit is contained in:
Pete Davison
2024-03-04 05:34:44 -06:00
committed by GitHub
parent 60d20c042e
commit 3c05c9c6e1
6 changed files with 55 additions and 43 deletions

View File

@@ -24,6 +24,7 @@ func NewRootNode(
entrypoint string,
insecure bool,
) (Node, error) {
dir = getDefaultDir(entrypoint, dir)
// Check if there is something to read on STDIN
stat, _ := os.Stdin.Stat()
if (stat.Mode()&os.ModeCharDevice) == 0 && stat.Size() > 0 {
@@ -68,3 +69,26 @@ func getScheme(uri string) string {
}
return ""
}
func getDefaultDir(entrypoint, dir string) string {
// If the entrypoint and dir are empty, we default the directory to the current working directory
if dir == "" {
if entrypoint == "" {
wd, err := os.Getwd()
if err != nil {
return ""
}
dir = wd
}
return dir
}
// If the directory is set, ensure it is an absolute path
var err error
dir, err = filepath.Abs(dir)
if err != nil {
return ""
}
return dir
}