forked from src-d/proteus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
62 lines (47 loc) · 1.29 KB
/
report.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
package report // import "gopkg.in/davidp94/proteus.v1/report"
import (
"fmt"
"github.com/fatih/color"
)
var silent bool
var testing bool
var msgStack []string
func Silent() {
silent = true
}
func TestMode() {
testing = true
ResetTestModeStack()
}
func EndTestMode() {
testing = false
ResetTestModeStack()
}
func ResetTestModeStack() {
msgStack = make([]string, 0)
}
func MessageStack() []string {
return msgStack
}
type colorFunc func(string, ...interface{}) string
// Warn prints a formatted warn message to stdout.
func Warn(format string, args ...interface{}) {
report(color.YellowString, "WARN", format, args...)
}
// Error prints a formatted error message to stdout.
func Error(format string, args ...interface{}) {
report(color.RedString, "ERROR", format, args...)
}
// Info prints a formatted info message to stdout.
func Info(format string, args ...interface{}) {
report(color.GreenString, "INFO", format, args...)
}
func report(color colorFunc, lvl string, format string, args ...interface{}) {
fmt.Sprintf("%s: %s", color(lvl), fmt.Sprintf(format, args...))
if testing {
msgStack = append(msgStack, fmt.Sprintf("%s: %s", lvl, fmt.Sprintf(format, args...)))
}
if !silent || lvl == "ERROR" {
fmt.Println(fmt.Sprintf("%s: %s", color(lvl), fmt.Sprintf(format, args...)))
}
}