1
0
mirror of https://github.com/go-task/task.git synced 2025-01-26 05:27:15 +02:00

Expand environment variables on "dir", "sources" and "generates"

So a path like this works: $GOPATH/src/github.com/go-task/task

Allowing of "~" was also implemented. See #74 and baac067a1a0aa0d387b60a19977c901a3863fe97

Fixes #116
This commit is contained in:
Andrey Nering 2018-06-16 14:25:15 -03:00
parent a830dba5da
commit 102f8ab74e
4 changed files with 28 additions and 5 deletions

View File

@ -13,6 +13,7 @@ vars:
./internal/compiler/v2
./internal/execext
./internal/logger
./internal/osext
./internal/output
./internal/status
./internal/taskfile

22
internal/osext/osext.go Normal file
View File

@ -0,0 +1,22 @@
package osext
import (
"os"
"github.com/mitchellh/go-homedir"
)
// Expand is an improved version of os.ExpandEnv,
// that not only expand enrionment variable ($GOPATH/src/github.com/...)
// but also expands "~" as the home directory.
func Expand(s string) (string, error) {
s = os.ExpandEnv(s)
var err error
s, err = homedir.Expand(s)
if err != nil {
return "", err
}
return s, nil
}

View File

@ -4,8 +4,9 @@ import (
"path/filepath"
"sort"
"github.com/go-task/task/internal/osext"
"github.com/mattn/go-zglob"
"github.com/mitchellh/go-homedir"
)
func glob(dir string, globs []string) (files []string, err error) {
@ -13,7 +14,7 @@ func glob(dir string, globs []string) (files []string, err error) {
if !filepath.IsAbs(g) {
g = filepath.Join(dir, g)
}
g, err = homedir.Expand(g)
g, err = osext.Expand(g)
if err != nil {
return nil, err
}

View File

@ -3,10 +3,9 @@ package task
import (
"path/filepath"
"github.com/go-task/task/internal/osext"
"github.com/go-task/task/internal/taskfile"
"github.com/go-task/task/internal/templater"
"github.com/mitchellh/go-homedir"
)
var (
@ -41,7 +40,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
Method: r.Replace(origTask.Method),
Prefix: r.Replace(origTask.Prefix),
}
new.Dir, err = homedir.Expand(new.Dir)
new.Dir, err = osext.Expand(new.Dir)
if err != nil {
return nil, err
}