-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
77 lines (63 loc) · 1.39 KB
/
utils.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"bytes"
"html/template"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/fatih/color"
)
func findRunfiles() (runfiles []Runfile) {
tests := []string{}
dir, _ := filepath.Split(filename)
parts := strings.Split(dir, string(filepath.Separator))
for i := len(parts) - 1; i > 0; i-- {
for _, extension := range []string{"yml", "yaml"} {
p := append(parts[:i], "Runfile."+extension)
tests = append(tests, string(filepath.Separator)+filepath.Join(p...))
}
}
for _, test := range tests {
if _, err := os.Stat(test); err == nil {
runfiles = append(runfiles, RunfileConstructor(test))
}
}
return
}
func execute(command string) error {
tmpl, err := template.New("test").Parse(command)
if err != nil {
log.Fatal(err)
}
var result bytes.Buffer
err = tmpl.Execute(&result, context)
if err != nil {
log.Fatal(err)
}
color.Green("#! %s\n", result.String())
parts := cmdRe.FindAllString(result.String(), -1)
cmd := exec.Command(parts[0], parts[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func debugPrintln(a ...interface{}) {
c := color.New(color.Faint)
if debug {
c.Println(a...)
}
}
func debugPrint(a ...interface{}) {
c := color.New(color.Faint)
if debug {
c.Print(a...)
}
}
func debugPrintf(format string, a ...interface{}) {
c := color.New(color.Faint)
if debug {
c.Printf(format, a...)
}
}