/
helpers.go
64 lines (54 loc) · 1.21 KB
/
helpers.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
package main
import (
"fmt"
"os"
"os/exec"
"github.com/fatih/color"
)
func runCommand(cmd *exec.Cmd, showOutput bool, inProject bool, exitOnError bool) {
s.Start()
if inProject {
cmd.Dir = "./" + ProjectName
}
color.White("Running: " + cmd.String())
if showOutput {
out, err := cmd.Output()
if err != nil {
s.Stop()
if exitOnError {
color.Red("× Error Running: " + cmd.String())
color.Red("× " + err.Error())
os.Exit(commandCount)
} else {
color.Yellow("× Error Running: " + cmd.String())
color.Yellow("× " + err.Error())
}
}
fmt.Println(string(out))
} else {
err := cmd.Run()
if err != nil {
s.Stop()
if exitOnError {
color.Red("× Error Running: " + cmd.String())
color.Red("× " + err.Error())
color.White("Tip: Run the above command separately for more info to find out what went wrong")
os.Exit(commandCount)
} else {
color.Yellow("× Error Running: " + cmd.String())
color.Yellow(err.Error())
}
} else {
s.Stop()
color.Green("✓ Completed: " + cmd.String())
}
}
commandCount++
}
func fileExists(fileName string) bool {
if _, err := os.Stat(fileName); err == nil {
return true
} else {
return false
}
}