-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
54 lines (44 loc) · 1.34 KB
/
error.go
File metadata and controls
54 lines (44 loc) · 1.34 KB
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
package cli
// ShowHelpError is an interface that allows commands to signal whether
// the help message should be displayed along with the error.
type ShowHelpError interface {
error
ShowHelp() bool
}
// NewErrorWithHelp creates a new error that implements the ShowHelpError
// interface, indicating that the help message should be shown.
func NewErrorWithHelp(err error) error {
return &showHelpError{err: err}
}
type showHelpError struct{ err error }
func (showHelpError) ShowHelp() bool { return true }
func (e showHelpError) Unwrap() error { return e.err }
func (e showHelpError) Error() string {
if e.err != nil {
return e.err.Error()
}
return ""
}
// ExitStatusError allows commands to specify a custom exit
// status code for the CLI application.
type ExitStatusError interface {
error
ExitStatus() uint8
}
// NewErrorWithExitStatus creates a new error that implements the
// ExitStatusError interface, allowing a custom exit status to be set.
func NewErrorWithExitStatus(err error, status uint8) error {
return &exitStatusError{err: err, status: status}
}
type exitStatusError struct {
err error
status uint8
}
func (e exitStatusError) ExitStatus() uint8 { return e.status }
func (e exitStatusError) Unwrap() error { return e.err }
func (e exitStatusError) Error() string {
if e.err != nil {
return e.err.Error()
}
return ""
}