From 0a6833e9d80d02376d4020f002894277f6d681ef Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Sat, 21 Aug 2021 07:20:33 -0400 Subject: [PATCH 1/3] Allow included Taskfiles to use ~/* paths --- taskfile/read/taskfile.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/taskfile/read/taskfile.go b/taskfile/read/taskfile.go index 780edd8e..8f3d2486 100644 --- a/taskfile/read/taskfile.go +++ b/taskfile/read/taskfile.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "gopkg.in/yaml.v3" @@ -51,6 +52,12 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) { if filepath.IsAbs(includedTask.Taskfile) { path = includedTask.Taskfile + } else if strings.HasPrefix(includedTask.Taskfile, "~") { + home, err := os.UserHomeDir() + if err != nil { + return err + } + path = strings.Replace(includedTask.Taskfile, "~", home, 1) } else { path = filepath.Join(dir, includedTask.Taskfile) } From c892d055ed01bae034c0f5a037b96b4db4111047 Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Sun, 5 Sep 2021 08:18:47 -0400 Subject: [PATCH 2/3] Use internal execext.Expand to expand ~ in includes --- taskfile/read/taskfile.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/taskfile/read/taskfile.go b/taskfile/read/taskfile.go index 8f3d2486..e932104a 100644 --- a/taskfile/read/taskfile.go +++ b/taskfile/read/taskfile.go @@ -10,6 +10,7 @@ import ( "gopkg.in/yaml.v3" + "github.com/go-task/task/v3/internal/execext" "github.com/go-task/task/v3/internal/templater" "github.com/go-task/task/v3/taskfile" ) @@ -53,7 +54,7 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) { if filepath.IsAbs(includedTask.Taskfile) { path = includedTask.Taskfile } else if strings.HasPrefix(includedTask.Taskfile, "~") { - home, err := os.UserHomeDir() + home, err := execext.Expand("~") if err != nil { return err } From 8d695bc8d79200289dc5530bf117e29bbbfc83b3 Mon Sep 17 00:00:00 2001 From: Alexander Mancevice Date: Sun, 5 Sep 2021 10:57:49 -0400 Subject: [PATCH 3/3] simplify logic to expand included paths --- taskfile/read/taskfile.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/taskfile/read/taskfile.go b/taskfile/read/taskfile.go index e932104a..9c765ee6 100644 --- a/taskfile/read/taskfile.go +++ b/taskfile/read/taskfile.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" "runtime" - "strings" "gopkg.in/yaml.v3" @@ -51,16 +50,13 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) { } } - if filepath.IsAbs(includedTask.Taskfile) { - path = includedTask.Taskfile - } else if strings.HasPrefix(includedTask.Taskfile, "~") { - home, err := execext.Expand("~") - if err != nil { - return err - } - path = strings.Replace(includedTask.Taskfile, "~", home, 1) - } else { - path = filepath.Join(dir, includedTask.Taskfile) + path, err := execext.Expand(includedTask.Taskfile) + if err != nil { + return err + } + + if ! filepath.IsAbs(path) { + path = filepath.Join(dir, path) } info, err := os.Stat(path)