From 57a01aa6ff5cdd020f9db60da63359dceeb7ffb1 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Mon, 24 Dec 2018 15:19:53 -0200 Subject: [PATCH] Fix failing test There was some breaking changes described at https://github.com/mvdan/sh/issues/335#issuecomment-447605295 --- internal/execext/exec.go | 14 ++++++++++++++ internal/status/glob.go | 5 +++-- variables.go | 5 ++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/execext/exec.go b/internal/execext/exec.go index 35d617cf..f62fd6a4 100644 --- a/internal/execext/exec.go +++ b/internal/execext/exec.go @@ -9,6 +9,7 @@ import ( "mvdan.cc/sh/expand" "mvdan.cc/sh/interp" + "mvdan.cc/sh/shell" "mvdan.cc/sh/syntax" ) @@ -67,3 +68,16 @@ func IsExitError(err error) bool { return false } } + +// Expand is a helper to mvdan.cc/shell.Fields that returns the first field +// if available. +func Expand(s string) (string, error) { + fields, err := shell.Fields(s, nil) + if err != nil { + return "", err + } + if len(fields) > 0 { + return fields[0], nil + } + return "", nil +} diff --git a/internal/status/glob.go b/internal/status/glob.go index f0b5dbe6..305e0f9b 100644 --- a/internal/status/glob.go +++ b/internal/status/glob.go @@ -4,8 +4,9 @@ import ( "path/filepath" "sort" + "github.com/go-task/task/v2/internal/execext" + "github.com/mattn/go-zglob" - "mvdan.cc/sh/shell" ) 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 = shell.Expand(g, nil) + g, err = execext.Expand(g) if err != nil { return nil, err } diff --git a/variables.go b/variables.go index 8e8e6947..bdbf52e5 100644 --- a/variables.go +++ b/variables.go @@ -3,10 +3,9 @@ package task import ( "path/filepath" + "github.com/go-task/task/v2/internal/execext" "github.com/go-task/task/v2/internal/taskfile" "github.com/go-task/task/v2/internal/templater" - - "mvdan.cc/sh/shell" ) // CompiledTask returns a copy of a task, but replacing variables in almost all @@ -37,7 +36,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) { Prefix: r.Replace(origTask.Prefix), IgnoreError: origTask.IgnoreError, } - new.Dir, err = shell.Expand(new.Dir, nil) + new.Dir, err = execext.Expand(new.Dir) if err != nil { return nil, err }