-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
72 lines (63 loc) · 1.3 KB
/
util.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
package main
import (
"fmt"
"log"
"math/rand"
"os/exec"
"regexp"
"runtime"
"strings"
"time"
)
func todo(params ...string) {
if len(params) == 0 {
log.Println("todo!")
} else {
log.Printf("todo! %s", strings.Join(params, ", "))
}
}
func logi(format string, v ...interface{}) {
if !environment.DEBUG {
return
}
_, file, line, ok := runtime.Caller(1)
fileInfo := strings.Split(file, "/")
fileName := fileInfo[len(fileInfo)-1]
if ok {
log.Printf("[%s:%d] %s", fileName, line, fmt.Sprintf(format, v...))
}
}
func randGoodbyeMessage() string {
rand.Seed(time.Now().UnixNano())
messages := []string{
"Bye!",
"Peace out!",
"See ya!",
"Ciao!",
"Adios!",
"Later!",
"Have a nice day!",
"Have a good one!",
}
return messages[rand.Intn(len(messages))]
}
func gitDiff() (string, error) {
out, err := exec.Command("git", "diff", "--cached").Output()
if err != nil {
log.Fatal(err)
return "", err
}
return string(out), nil
}
func cleanLines(str string) []string {
lines := strings.Split(str, "\n")
re := regexp.MustCompile(`^(\d+\.|-|\*)\s+`)
for i, line := range lines {
lines[i] = strings.TrimSpace(re.ReplaceAllString(line, ""))
}
return lines
}
func userInGitRepo() bool {
_, err := exec.Command("git", "rev-parse", "--is-inside-work-tree").Output()
return err == nil
}