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

Added support for chdir option in task

This commit is contained in:
Sascha Andres 2017-03-01 13:35:00 +01:00
parent c7154d4102
commit a493591541

View File

@ -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 {