mirror of
https://github.com/go-task/task.git
synced 2026-06-30 08:04:28 +00:00
Little refactor on command creation
This commit is contained in:
22
execext/exec.go
Normal file
22
execext/exec.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package execext
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
var (
|
||||
// ShPath is path to "sh" command
|
||||
ShPath string
|
||||
// ShExists is true if "sh" command is available on the system
|
||||
ShExists bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
ShPath, err = exec.LookPath("sh")
|
||||
ShExists = err == nil
|
||||
}
|
||||
|
||||
func newShCommand(c string) *exec.Cmd {
|
||||
return exec.Command(ShPath, "-c", c)
|
||||
}
|
||||
13
execext/exec_other.go
Normal file
13
execext/exec_other.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// +build !windows
|
||||
|
||||
package execext
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// NewCommand returns a new command that runs on "sh" is available or on "cmd"
|
||||
// otherwise on Windows
|
||||
func NewCommand(c string) *exec.Cmd {
|
||||
return newShCommand(c)
|
||||
}
|
||||
20
execext/exec_win.go
Normal file
20
execext/exec_win.go
Normal file
@@ -0,0 +1,20 @@
|
||||
// +build windows
|
||||
|
||||
package execext
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// NewCommand returns a new command that runs on "sh" is available or on "cmd"
|
||||
// otherwise on Windows
|
||||
func NewCommand(c string) *exec.Cmd {
|
||||
if ShExists {
|
||||
return newShCommand(c)
|
||||
}
|
||||
return newCmdCommand(c)
|
||||
}
|
||||
|
||||
func newCmdCommand(c string) {
|
||||
return exec.Command("cmd", "/C", c)
|
||||
}
|
||||
Reference in New Issue
Block a user