forked from nytimes/drone-gae
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.go
More file actions
39 lines (34 loc) · 803 Bytes
/
Copy pathexec.go
File metadata and controls
39 lines (34 loc) · 803 Bytes
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
package main
import (
"fmt"
"io"
"os/exec"
"regexp"
"strings"
)
var reRedact = regexp.MustCompile(`(?:^|\s+)(-E\s+\S+:|--oauth2_access_token\s+)\S+`)
type Environ struct {
dir string
env []string
stdout io.Writer
stderr io.Writer
}
func NewEnviron(dir string, env []string, stdout, stderr io.Writer) *Environ {
return &Environ{
dir: dir,
env: env,
stdout: stdout,
stderr: stderr,
}
}
// Run executes the given program.
func (e *Environ) Run(name string, arg ...string) error {
displayArg := reRedact.ReplaceAllString(strings.Trim(fmt.Sprint(arg), "[]"), " $1 [redacted] ")
fmt.Printf("Running Command: %s %s\n", name, displayArg)
cmd := exec.Command(name, arg...)
cmd.Dir = e.dir
cmd.Env = e.env
cmd.Stdout = e.stdout
cmd.Stderr = e.stderr
return cmd.Run()
}