1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00

Little refactor on command creation

This commit is contained in:
Andrey Nering
2017-03-12 17:18:59 -03:00
parent 678ea86350
commit 8c5e7e89cd
5 changed files with 62 additions and 28 deletions

23
task.go
View File

@@ -4,19 +4,16 @@ import (
"fmt"
"log"
"os"
"os/exec"
"strings"
"github.com/go-task/task/execext"
"github.com/spf13/pflag"
)
var (
// TaskFilePath is the default Taskfile
TaskFilePath = "Taskfile"
// ShExists is true if Bash was found
ShExists bool
// ShPath constains the Bash path if found
ShPath string
// Force (--force or -f flag) forces a task to run even when it's up-to-date
Force bool
@@ -27,15 +24,6 @@ var (
runnedTasks = make(map[string]struct{})
)
func init() {
var err error
ShPath, err = exec.LookPath("sh")
if err != nil {
return
}
ShExists = true
}
// Task represents a task
type Task struct {
Cmds []string
@@ -142,12 +130,7 @@ func (t *Task) runCommand(i int) error {
if err != nil {
return err
}
var cmd *exec.Cmd
if ShExists {
cmd = exec.Command(ShPath, "-c", c)
} else {
cmd = exec.Command("cmd", "/C", c)
}
cmd := execext.NewCommand(c)
if dir != "" {
cmd.Dir = dir
}