-
Notifications
You must be signed in to change notification settings - Fork 4
/
exitstatus.go
51 lines (43 loc) · 1.03 KB
/
exitstatus.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
package timeout
// ExitStatus stores exit information of the command
type ExitStatus struct {
Code int
Signaled bool
typ exitType
killed bool
}
// IsTimedOut returns the command timed out or not
func (ex *ExitStatus) IsTimedOut() bool {
return ex.typ == exitTypeTimedOut || ex.typ == exitTypeKilled
}
// IsCanceled return if the command canceled by context or not
func (ex *ExitStatus) IsCanceled() bool {
return ex.typ == exitTypeCanceled
}
// IsKilled returns the command is killed or not
func (ex *ExitStatus) IsKilled() bool {
return ex.killed
}
// GetExitCode gets the exit code for command line tools
func (ex *ExitStatus) GetExitCode() int {
switch {
case ex.IsKilled():
return exitKilled
case ex.IsTimedOut():
return exitTimedOut
default:
return ex.Code
}
}
// GetChildExitCode gets the exit code of the Cmd itself
func (ex *ExitStatus) GetChildExitCode() int {
return ex.Code
}
type exitType int
// exit types
const (
exitTypeNormal exitType = iota
exitTypeTimedOut
exitTypeKilled
exitTypeCanceled
)