-
Notifications
You must be signed in to change notification settings - Fork 1
/
seems.go
83 lines (75 loc) · 1.49 KB
/
seems.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
78
79
80
81
82
83
package printer
import (
"strconv"
"strings"
"github.com/SignorMercurio/limner/color"
)
// seemsNegative guesses if the status is something negative
func seemsNegative(status string) bool {
negativeKeywords := []string{
"fail",
"backoff",
"exceed",
"not",
"err",
"invalid",
"unable",
"unhealthy",
"unknown",
"unavailable",
"evict",
"bad",
"timeout",
"panic",
"fatal",
}
for _, v := range negativeKeywords {
if strings.Contains(status, v) {
return true
}
}
return false
}
// seemsWarning guesses if the status is something that's between negative and positive
func seemsWarning(status string) bool {
return strings.Contains(status, "ing")
}
// seemsPositive guesses if the status is something positive
func seemsPositive(status string) bool {
positiveKeywords := []string{
"ok",
"ted",
"led",
"ged",
"zed",
"success",
"succeed",
"ready",
"normal",
"healthy",
"running",
"done",
"available",
}
for _, v := range positiveKeywords {
if strings.Contains(status, v) {
return true
}
}
return false
}
// seemsReadyStatus checks if the status is in xx/yy format where xx and yy are numbers
func seemsReadyStatus(status string) (color.Color, bool) {
if strings.Count(status, "/") == 1 {
ready := strings.Split(status, "/")
if ready[0] == ready[1] {
return color.Green, true
}
_, e1 := strconv.Atoi(ready[0])
_, e2 := strconv.Atoi(ready[1])
if e1 == nil && e2 == nil {
return color.Yellow, true
}
}
return 0, false
}