-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult.go
More file actions
53 lines (47 loc) · 1.04 KB
/
result.go
File metadata and controls
53 lines (47 loc) · 1.04 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
package execx
import (
"os"
"time"
)
// Result captures the outcome of a command execution.
type Result struct {
Stdout string
Stderr string
ExitCode int
Err error
Duration time.Duration
signal os.Signal
}
// OK reports whether the command exited cleanly without errors.
// @group Results
//
// Example: ok
//
// res, _ := execx.Command("go", "env", "GOOS").Run()
// fmt.Println(res.OK())
// // #bool true
func (r Result) OK() bool {
return r.Err == nil && r.ExitCode == 0
}
// IsExitCode reports whether the exit code matches.
// @group Results
//
// Example: exit code
//
// res, _ := execx.Command("go", "env", "GOOS").Run()
// fmt.Println(res.IsExitCode(0))
// // #bool true
func (r Result) IsExitCode(code int) bool {
return r.ExitCode == code
}
// IsSignal reports whether the command terminated due to a signal.
// @group Results
//
// Example: signal
//
// res, _ := execx.Command("go", "env", "GOOS").Run()
// fmt.Println(res.IsSignal(os.Interrupt))
// // false
func (r Result) IsSignal(sig os.Signal) bool {
return r.signal == sig
}