-
Notifications
You must be signed in to change notification settings - Fork 29
/
output.go
133 lines (120 loc) Β· 3.32 KB
/
output.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
127
128
129
130
131
132
133
package main
import (
"fmt"
"os"
"strings"
"github.com/fatih/color"
)
// confirm will prompt the user with the given toPrint string, and
// exit the program if N or n is input.
func confirm(p ...interface{}) {
if yesEnabled {
return
}
toPrint := fmt.Sprint(p...)
toPrint = printer(color.FgYellow, "CONF", toPrint)
fmt.Print(toPrint + " [Y/n]: ")
var resp string
fmt.Scanln(&resp)
if strings.ToLower(strings.TrimSpace(resp)) == "n" {
os.Exit(1)
}
}
// ask will prompt the user with the given toPrint string, and
// return a boolean.
func ask(p ...interface{}) bool {
if yesEnabled {
return true
}
toPrint := fmt.Sprint(p...)
toPrint = printer(color.FgBlue, "CONF", toPrint)
fmt.Print(toPrint + " [Y/n]: ")
var resp string
fmt.Scanln(&resp)
if strings.ToLower(strings.TrimSpace(resp)) == "n" {
return false
}
return true
}
func pass(p ...interface{}) {
toPrint := fmt.Sprintln(p...)
var printStr string
if checkCount != 0 {
printStr = printer(color.FgGreen, fmt.Sprintf("%s:%d", "PASS", checkCount), toPrint)
} else {
printStr = printer(color.FgGreen, "PASS", toPrint)
}
fmt.Print(printStr)
}
func fail(p ...interface{}) {
toPrint := fmt.Sprintln(p...)
var printStr string
if checkCount != 0 {
printStr = printer(color.FgRed, fmt.Sprintf("%s:%d", "FAIL", checkCount), toPrint)
} else {
printStr = printer(color.FgRed, "FAIL", toPrint)
}
fmt.Print(printStr)
}
func warn(p ...interface{}) {
toPrint := fmt.Sprintln(p...)
var printStr string
if checkCount != 0 {
printStr = printer(color.FgYellow, fmt.Sprintf("%s:%d", "WARN", checkCount), toPrint)
} else {
printStr = printer(color.FgYellow, "WARN", toPrint)
}
fmt.Print(printStr)
}
func debug(p ...interface{}) {
// Function inlining and dead code elimination means that debug calls
// (and their strings) will be optimized out on phocus builds, with any
// recent Go compiler.
//
// So, we can make as many debug calls as we want, and it won't make a
// specific version of phocus easier to reverse. (Easier than it already
// is, since source code is available.) This really only benefits those
// with custom builds.
if DEBUG_BUILD && debugEnabled {
toPrint := fmt.Sprintln(p...)
var printStr string
if checkCount != 0 {
printStr = printer(color.FgMagenta, fmt.Sprintf("%s:%d", "DBUG", checkCount), toPrint)
} else {
printStr = printer(color.FgMagenta, "DBUG", toPrint)
}
fmt.Print(printStr)
}
}
func info(p ...interface{}) {
if verboseEnabled {
toPrint := fmt.Sprintln(p...)
var printStr string
if checkCount != 0 {
printStr = printer(color.FgCyan, fmt.Sprintf("%s:%d", "INFO", checkCount), toPrint)
} else {
printStr = printer(color.FgCyan, "INFO", toPrint)
}
fmt.Print(printStr)
}
}
func blue(head string, p ...interface{}) {
toPrint := fmt.Sprintln(p...)
printStr := printer(color.FgCyan, head, toPrint)
fmt.Print(printStr)
}
func red(head string, p ...interface{}) {
toPrint := fmt.Sprintln(p...)
fmt.Print(printer(color.FgRed, head, toPrint))
}
func green(head string, p ...interface{}) {
toPrint := fmt.Sprintln(p...)
fmt.Print(printer(color.FgGreen, head, toPrint))
}
func printer(colorChosen color.Attribute, messageType, toPrint string) string {
printer := color.New(colorChosen, color.Bold)
printStr := "["
printStr += printer.Sprintf(messageType)
printStr += fmt.Sprintf("] %s", toPrint)
return printStr
}