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:
23
task.go
23
task.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user