forked from nytimes/drone-gke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.go
45 lines (38 loc) · 738 Bytes
/
exec.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
package main
import (
"fmt"
"io"
"os/exec"
"strings"
)
type Runner interface {
Run(name string, arg ...string) error
}
type BasicRunner struct {
Runner
dir string
env []string
stdout io.Writer
stderr io.Writer
}
func NewBasicRunner(dir string, env []string, stdout, stderr io.Writer) *BasicRunner {
return &BasicRunner{
dir: dir,
env: env,
stdout: stdout,
stderr: stderr,
}
}
// Run executes the given program.
func (e *BasicRunner) Run(name string, arg ...string) error {
cmd := exec.Command(name, arg...)
cmd.Dir = e.dir
cmd.Env = e.env
cmd.Stdout = e.stdout
cmd.Stderr = e.stderr
// TODO: Extract this
fmt.Println()
fmt.Println("$", strings.Join(cmd.Args, " "))
//--
return cmd.Run()
}