| 12 | type cmdRunHandler struct{} |
| 13 | |
| 14 | func (h *cmdRunHandler) Run(c *cli.Context) error { |
| 15 | if !c.Args().Present() { |
| 16 | utils.Fatal("Specify a command to run") |
| 17 | } |
| 18 | |
| 19 | command := c.Args()[0] |
| 20 | |
| 21 | var args []string |
| 22 | |
| 23 | if c.NArg() > 1 { |
| 24 | args = c.Args()[1:] |
| 25 | } else { |
| 26 | args = []string{} |
| 27 | } |
| 28 | |
| 29 | cmd := exec.Command(command, args...) |
| 30 | cmd.Stdout = os.Stdout |
| 31 | cmd.Stderr = os.Stderr |
| 32 | cmd.Stdin = os.Stdin |
| 33 | |
| 34 | err := cmd.Run() |
| 35 | |
| 36 | if err != nil { |
| 37 | if exitErr, ok := err.(*exec.ExitError); ok { |
| 38 | if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { |
| 39 | os.Exit(status.ExitStatus()) |
| 40 | } else { |
| 41 | os.Exit(1) |
| 42 | } |
| 43 | } else { |
| 44 | utils.Fatal(err) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return nil |
| 49 | } |