forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
73 lines (62 loc) · 1.15 KB
/
level.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
package checker
import (
"fmt"
"github.com/TwiN/go-color"
)
type Level int
const (
ERR Level = 3
WARN Level = 2
INFO Level = 1
)
func NewLevel(level string) (Level, error) {
switch level {
case "ERR":
return ERR, nil
case "WARN":
return WARN, nil
case "INFO":
return INFO, nil
}
return INFO, fmt.Errorf("invalid level %s", level)
}
func (level Level) StringCond(colorMode ColorMode) string {
if isColorEnabled(colorMode) {
return level.PrettyString()
}
return level.String()
}
func (level Level) String() string {
switch level {
case ERR:
return "error"
case WARN:
return "warning"
case INFO:
return "info"
default:
return "issue"
}
}
func (level Level) PrettyString() string {
levelName := level.String()
switch level {
case ERR:
return color.InRed(levelName)
case WARN:
return color.InPurple(levelName)
case INFO:
return color.InCyan(levelName)
default:
return color.InGray(levelName)
}
}
func (level Level) IsBreaking() bool {
return level == ERR || level == WARN
}
func conditionalError(isConditionSatisfied bool, defaultLevel Level) Level {
if isConditionSatisfied {
return ERR
}
return defaultLevel
}