mirror of
https://github.com/go-task/task.git
synced 2025-06-25 00:47:04 +02:00
Support Windows
If "sh" is available (Git bash) it is used. Otherwise "cmd" is used.
This commit is contained in:
31
task.go
31
task.go
@ -15,10 +15,21 @@ import (
|
|||||||
var (
|
var (
|
||||||
CurrentDirectory, _ = osext.ExecutableFolder()
|
CurrentDirectory, _ = osext.ExecutableFolder()
|
||||||
TaskFilePath = filepath.Join(CurrentDirectory, "Taskfile.yml")
|
TaskFilePath = filepath.Join(CurrentDirectory, "Taskfile.yml")
|
||||||
|
ShExists bool
|
||||||
|
ShPath string
|
||||||
|
|
||||||
Tasks = make(map[string]*Task)
|
Tasks = make(map[string]*Task)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
var err error
|
||||||
|
ShPath, err = exec.LookPath("sh")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ShExists = true
|
||||||
|
}
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Cmds []string
|
Cmds []string
|
||||||
Deps []string
|
Deps []string
|
||||||
@ -81,12 +92,24 @@ func RunTask(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range t.Cmds {
|
for _, c := range t.Cmds {
|
||||||
cmd := exec.Command("/bin/sh", "-c", c)
|
if err := runCommand(c); err != nil {
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
return &TaskRunError{name, err}
|
return &TaskRunError{name, err}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runCommand(c string) error {
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
if ShExists {
|
||||||
|
cmd = exec.Command(ShPath, "-c", c)
|
||||||
|
} else {
|
||||||
|
cmd = exec.Command("cmd", "/C", c)
|
||||||
|
}
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user