1
0
mirror of https://github.com/go-task/task.git synced 2025-01-08 04:04:08 +02:00

refactor: minor improvements to setCurrentDir

This commit is contained in:
Pete Davison 2023-09-14 22:15:54 +00:00 committed by Andrey Nering
parent ba299aa71f
commit d1d312f396
2 changed files with 11 additions and 15 deletions

View File

@ -55,6 +55,11 @@ func (e *Executor) Setup() error {
}
func (e *Executor) setCurrentDir() error {
// If the entrypoint is already set, we don't need to do anything
if e.Entrypoint != "" {
return nil
}
// Default the directory to the current working directory
if e.Dir == "" {
wd, err := os.Getwd()
@ -64,22 +69,13 @@ func (e *Executor) setCurrentDir() error {
e.Dir = wd
}
// Ensure we have an absolute path
abs, err := filepath.Abs(e.Dir)
// Search for a taskfile
root, err := read.ExistsWalk(e.Dir)
if err != nil {
return err
}
e.Dir = abs
// If no entrypoint is specified, we need to search for a taskfile
if e.Entrypoint == "" {
root, err := read.ExistsWalk(e.Dir)
if err != nil {
return err
}
e.Dir = filepath.Dir(root)
e.Entrypoint = filepath.Base(root)
}
e.Dir = filepath.Dir(root)
e.Entrypoint = filepath.Base(root)
return nil
}

View File

@ -311,13 +311,13 @@ func Exists(path string) (string, error) {
return "", err
}
if fi.Mode().IsRegular() {
return path, nil
return filepath.Abs(path)
}
for _, n := range defaultTaskfiles {
fpath := filepathext.SmartJoin(path, n)
if _, err := os.Stat(fpath); err == nil {
return fpath, nil
return filepath.Abs(fpath)
}
}