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

Merge pull request #4 from sascha-andres/master

Added chdir to task
This commit is contained in:
Andrey Nering 2017-03-01 19:45:42 -03:00 committed by GitHub
commit 847f206043

View File

@ -40,6 +40,7 @@ type Task struct {
Deps []string
Sources []string
Generates []string
Dir 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.Dir); 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 {