forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
43 lines (34 loc) · 870 Bytes
/
errors.go
File metadata and controls
43 lines (34 loc) · 870 Bytes
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
package cmdutil
import (
"errors"
"github.com/AlecAivazis/survey/v2/terminal"
)
// FlagError is the kind of error raised in flag processing
type FlagError struct {
Err error
}
func (fe FlagError) Error() string {
return fe.Err.Error()
}
func (fe FlagError) Unwrap() error {
return fe.Err
}
// SilentError is an error that triggers exit code 1 without any error messaging
var SilentError = errors.New("SilentError")
// CancelError signals user-initiated cancellation
var CancelError = errors.New("CancelError")
func IsUserCancellation(err error) bool {
return errors.Is(err, CancelError) || errors.Is(err, terminal.InterruptErr)
}
func MutuallyExclusive(message string, conditions ...bool) error {
numTrue := 0
for _, ok := range conditions {
if ok {
numTrue++
}
}
if numTrue > 1 {
return &FlagError{Err: errors.New(message)}
}
return nil
}