forked from vdemeester/kobw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
50 lines (45 loc) · 1002 Bytes
/
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
50
package main
import (
"errors"
"fmt"
"os"
"os/exec"
"syscall"
"github.com/spf13/cobra"
)
type runOption struct {
name string
}
func validateRunOpts(opt runOption) error {
if opt.name == "" {
return errors.New("name is empty")
}
return nil
}
func runCommand() *cobra.Command {
var opt runOption
cmd := &cobra.Command{
Use: "run",
Short: "run the build and show logs",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Run build:", opt.name)
c := exec.Command("oc", "start-build", opt.name, "--follow")
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if err := c.Start(); err != nil {
return err
}
if err := c.Wait(); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
fmt.Println("ExitStatus:", status.ExitStatus())
}
}
return err
}
return nil
},
}
cmd.Flags().StringVar(&opt.name, "name", "", "build configuration name")
return cmd
}