forked from DarthSim/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_run.go
49 lines (38 loc) · 767 Bytes
/
cmd_run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"os"
"os/exec"
"syscall"
"github.com/DarthSim/overmind/v2/utils"
"github.com/urfave/cli"
)
type cmdRunHandler struct{}
func (h *cmdRunHandler) Run(c *cli.Context) error {
if !c.Args().Present() {
utils.Fatal("Specify a command to run")
}
command := c.Args()[0]
var args []string
if c.NArg() > 1 {
args = c.Args()[1:]
} else {
args = []string{}
}
cmd := exec.Command(command, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err := cmd.Run()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
os.Exit(status.ExitStatus())
} else {
os.Exit(1)
}
} else {
utils.Fatal(err)
}
}
return nil
}