Chromium Code Reviews| Index: go/src/infra/tools/drover/util.go |
| diff --git a/go/src/infra/tools/drover/util.go b/go/src/infra/tools/drover/util.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..63b6a1057613fc89e16ecf0b7df378efcb078df2 |
| --- /dev/null |
| +++ b/go/src/infra/tools/drover/util.go |
| @@ -0,0 +1,35 @@ |
| +package main |
| + |
| +import "fmt" |
| +import "os" |
| +import "os/exec" |
| +import "strings" |
| + |
| +func failIf(err error) { |
| + if err != nil { |
| + fmt.Println("fatal:", err) |
| + os.Exit(1) |
|
M-A Ruel
2014/10/18 00:47:06
That's a bit severe and hard to test.
|
| + } |
| +} |
| + |
| +func SplitLines(data string) []string { |
| + return strings.Split(strings.TrimRight(data, "\n"), "\n") |
| +} |
| + |
| +func Shell(dir string) bool { |
| + shell := os.Getenv("SHELL") |
| + if shell == "" { |
| + shell = DefaultShell |
| + } |
| + shell, err := exec.LookPath(shell) |
| + failIf(err) |
| + p, err := os.StartProcess(shell, []string{shell}, &os.ProcAttr{ |
| + Dir: dir, |
| + Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}, |
| + }) |
| + failIf(err) |
| + s, err := p.Wait() |
| + failIf(err) |
| + |
| + return s.Success() |
| +} |