-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathyolo.go
More file actions
77 lines (65 loc) · 1.83 KB
/
yolo.go
File metadata and controls
77 lines (65 loc) · 1.83 KB
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 "os"
import "os/exec"
import "strings"
import "fmt"
import("github.com/common-nighthawk/go-figure")
import("github.com/fatih/color")
func main() {
mavenAdditions := []string {
"-Dspotbugs.skip=true",
"-Dcheckstyle.skip=true",
"-Dasciidoctor.skip=true",
"-Ddocker.skip=true",
"-Dinvoker.skip=true",
"-Djacoco.skip=true",
"-Djapicmp.skip=true",
"-Djgassistant.skip=true",
"-Dlicense.skip=true",
"-Dmaven.javadoc.skip=true",
"-Dpmd.skip=true",
"-Dmaven.test.skip=true",
}
gradleAdditions := []string {
"-x",
"check",
}
myFigure := figure.NewColorFigure("YOLO", "", "cyan", true)
myFigure.Print()
fmt.Println("")
color.Blue("================================")
fmt.Println("")
args := os.Args[1:]
command := args[0]
if isGitPush(args) {
run("git", "add", ".")
run("git", "commit", "-m", "yolo! 🤪")
} else {
if startsWithAnyOf(command, []string { "mvn", "./mvnw", "mvnd" }) {
args = append(args, mavenAdditions...)
} else if startsWithAnyOf(command, []string { "gradle", "./gradlew" }) {
args = append(args, gradleAdditions...)
}
}
run(args...)
}
func run(args... string) {
cyan := color.New(color.FgCyan).SprintFunc()
println(fmt.Sprintf("Running %s\n", cyan(strings.Join(args," "))))
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
_ = cmd.Run()
}
func isGitPush(args []string) bool {
return len(args) > 1 && args[0] == "git" && args[1] == "push"
}
func startsWithAnyOf(command string, prefixes []string) bool {
for i := range prefixes {
if strings.HasPrefix(command, prefixes[i]) {
return true
}
}
return false
}