@@ -10,22 +10,22 @@ import (
10
10
"golang.org/x/xerrors"
11
11
)
12
12
13
- // RichCLIMessage provides a human-readable message for CLI errors and messages.
14
- type RichCLIMessage struct {
13
+ // CLIMessage provides a human-readable message for CLI errors and messages.
14
+ type CLIMessage struct {
15
15
Level string
16
16
Color color.Attribute
17
17
Header string
18
18
Lines []string
19
19
}
20
20
21
- // RichCLIError wraps a RichCLIMessage a allows consumers to treat it as a normal error.
22
- type RichCLIError struct {
23
- RichCLIMessage
21
+ // CLIError wraps a RichCLIMessage a allows consumers to treat it as a normal error.
22
+ type CLIError struct {
23
+ CLIMessage
24
24
error
25
25
}
26
26
27
27
// Error formats the CLI message for consumption by a human as an error.
28
- func (r RichCLIMessage ) String () string {
28
+ func (r CLIMessage ) String () string {
29
29
var str strings.Builder
30
30
str .WriteString (fmt .Sprintf ("%s: %s\n " ,
31
31
color .New (r .Color ).Sprint (r .Level ),
@@ -41,7 +41,7 @@ func (r RichCLIMessage) String() string {
41
41
// If the error is a RichCLIError, the plain error chain is ignored and the rich error
42
42
// is logged on its own.
43
43
func Log (err error ) {
44
- var cliErr RichCLIError
44
+ var cliErr CLIError
45
45
if ! xerrors .As (err , & cliErr ) {
46
46
cliErr = Fatal (err .Error ())
47
47
}
@@ -50,7 +50,7 @@ func Log(err error) {
50
50
51
51
// LogInfo prints the given info message to stderr.
52
52
func LogInfo (header string , lines ... string ) {
53
- fmt .Fprintln (os .Stderr , RichCLIMessage {
53
+ fmt .Fprintln (os .Stderr , CLIMessage {
54
54
Level : "info" ,
55
55
Color : color .FgBlue ,
56
56
Header : header ,
@@ -65,7 +65,7 @@ func F(format string, a ...interface{}) string {
65
65
66
66
// LogSuccess prints the given info message to stderr.
67
67
func LogSuccess (header string , lines ... string ) {
68
- fmt .Fprintln (os .Stderr , RichCLIMessage {
68
+ fmt .Fprintln (os .Stderr , CLIMessage {
69
69
Level : "success" ,
70
70
Color : color .FgGreen ,
71
71
Header : header ,
@@ -74,9 +74,9 @@ func LogSuccess(header string, lines ...string) {
74
74
}
75
75
76
76
// Warn creates an error with the level "warning".
77
- func Warn (header string , lines ... string ) RichCLIError {
78
- return RichCLIError {
79
- RichCLIMessage : RichCLIMessage {
77
+ func Warn (header string , lines ... string ) CLIError {
78
+ return CLIError {
79
+ RichCLIMessage : CLIMessage {
80
80
Color : color .FgYellow ,
81
81
Level : "warning" ,
82
82
Header : header ,
@@ -87,9 +87,9 @@ func Warn(header string, lines ...string) RichCLIError {
87
87
}
88
88
89
89
// Error creates an error with the level "error".
90
- func Error (header string , lines ... string ) RichCLIError {
91
- return RichCLIError {
92
- RichCLIMessage : RichCLIMessage {
90
+ func Error (header string , lines ... string ) CLIError {
91
+ return CLIError {
92
+ RichCLIMessage : CLIMessage {
93
93
Color : color .FgRed ,
94
94
Level : "error" ,
95
95
Header : header ,
@@ -100,9 +100,9 @@ func Error(header string, lines ...string) RichCLIError {
100
100
}
101
101
102
102
// Fatal creates an error with the level "fatal".
103
- func Fatal (header string , lines ... string ) RichCLIError {
104
- return RichCLIError {
105
- RichCLIMessage : RichCLIMessage {
103
+ func Fatal (header string , lines ... string ) CLIError {
104
+ return CLIError {
105
+ RichCLIMessage : CLIMessage {
106
106
Color : color .FgRed ,
107
107
Level : "fatal" ,
108
108
Header : header ,
0 commit comments