From a4935915414494ed9ea8c07da46aa62dfcca4e90 Mon Sep 17 00:00:00 2001 From: Sascha Andres Date: Wed, 1 Mar 2017 13:35:00 +0100 Subject: [PATCH] Added support for chdir option in task --- task.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/task.go b/task.go index 48afd080..7a58de37 100644 --- a/task.go +++ b/task.go @@ -40,6 +40,7 @@ type Task struct { Deps []string Sources []string Generates []string + Chdir string } type taskNotFoundError struct { @@ -100,7 +101,7 @@ func RunTask(name string) error { } for _, c := range t.Cmds { - if err := runCommand(c); err != nil { + if err := runCommand(c, t.Chdir); err != nil { return &taskRunError{name, err} } } @@ -125,13 +126,16 @@ func isTaskUpToDate(t *Task) bool { return generatesMinTime.After(sourcesMaxTime) } -func runCommand(c string) error { +func runCommand(c, path string) error { var cmd *exec.Cmd if ShExists { cmd = exec.Command(ShPath, "-c", c) } else { cmd = exec.Command("cmd", "/C", c) } + if "" != path { + cmd.Dir = path + } cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil {