forked from adikari/monorepo-diff-buildkite-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
39 lines (29 loc) · 653 Bytes
/
util.go
File metadata and controls
39 lines (29 loc) · 653 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 (
"bytes"
"fmt"
"os"
"os/exec"
log "github.com/sirupsen/logrus"
)
func executeCommand(command string, args []string) (string, error) {
cmd := exec.Command(command, args...)
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
log.Debugf(
"\ncommand = '%s', \nargs = '%s', \nerror = '%s'",
command, args, stderr.String(),
)
return "", fmt.Errorf("command `%s` failed: %v", command, err)
}
return out.String(), nil
}
func env(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}