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:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user