This repository has been archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
/
main.go
126 lines (105 loc) · 2.41 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package console
import (
"fmt"
"os"
"strconv"
"github.com/mgutz/ansi"
)
var (
Verbose = false
Color = true
)
var (
info = "[i] "
debug = "[d] "
issue = "[!] "
shell = "[>] "
colorInfo = white + "[" + blue + "i" + white + "]" + reset + " "
colorDebug = white + "[" + orange + "d" + white + "]" + reset + " "
colorIssue = white + "[" + red + "!" + white + "]" + reset + " "
colorShell = white + "[" + green + ">" + white + "]" + reset + " "
blue = ansi.ColorCode("blue+bh")
white = ansi.ColorCode("white+bh")
yellow = ansi.ColorCode("yellow+bh")
green = ansi.ColorCode("green+bh")
red = ansi.ColorCode("red+bh")
reset = ansi.ColorCode("reset")
orange = ansi.ColorCode("214+bh")
)
func LogLine(prefix, msg string, color int) {
if Color {
colorCode := strconv.Itoa(color)
fmt.Println(ansi.ColorCode(colorCode) + prefix + reset + " " + msg)
} else {
fmt.Println(prefix + " " + msg)
}
}
func KeyValue(key, value string, a ...interface{}) {
if Color {
fmt.Fprintf(os.Stdout, white+key+reset+": "+value, a...)
} else {
fmt.Fprintf(os.Stdout, key+": "+value, a...)
}
}
func Header(s string) {
fmt.Print("\n")
if Color {
fmt.Print(white + s + reset + "\n")
} else {
fmt.Println(s)
}
}
func Info(msg string, a ...interface{}) {
if Color {
fmt.Fprintf(os.Stdout, colorInfo+msg+reset+"\n", a...)
} else {
fmt.Fprintf(os.Stdout, info+msg+"\n", a...)
}
}
func Debug(msg string, a ...interface{}) {
if Verbose {
if Color {
fmt.Fprintf(os.Stdout, colorDebug+msg+reset+"\n", a...)
} else {
fmt.Fprintf(os.Stdout, debug+msg+"\n", a...)
}
}
}
func Shell(msg string, a ...interface{}) {
if Color {
fmt.Fprintf(os.Stdout, colorShell+green+msg+reset+"\n", a...)
} else {
fmt.Fprintf(os.Stdout, shell+msg+"\n", a...)
}
}
func Issue(msg string, a ...interface{}) {
if Color {
fmt.Fprintf(os.Stderr, colorIssue+red+msg+reset+"\n", a...)
} else {
fmt.Fprintf(os.Stderr, issue+msg+"\n", a...)
}
}
func Error(err error, msg string, a ...interface{}) {
Issue(msg, a...)
if err != nil {
os.Stderr.WriteString(err.Error() + "\n")
}
}
func InfoExit(msg string, a ...interface{}) {
Info(msg, a...)
os.Exit(0)
}
func ErrorExit(err error, msg string, a ...interface{}) {
Error(err, msg, a...)
os.Exit(1)
}
func IssueExit(msg string, a ...interface{}) {
Issue(msg, a...)
os.Exit(1)
}
func Exit(code int) {
os.Exit(code)
}
func SetVerbose(verbose bool) {
Verbose = verbose
}