forked from dynport/gossh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.go
35 lines (29 loc) · 761 Bytes
/
result.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
package gossh
import (
"fmt"
"time"
)
type Result struct {
StdoutBuffer, StderrBuffer *LogWriter
Runtime time.Duration
Error error
ExitStatus int
}
func (r *Result) Stdout() string {
return r.StdoutBuffer.String()
}
func (r *Result) Stderr() string {
return r.StderrBuffer.String()
}
func (r *Result) String() (out string) {
m := map[string]string{
"stdout": fmt.Sprintf("%d bytes", len(r.StdoutBuffer.String())),
"stderr": fmt.Sprintf("%d bytes", len(r.StderrBuffer.String())),
"runtime": fmt.Sprintf("%0.6f", r.Runtime.Seconds()),
"status": fmt.Sprintf("%d", r.ExitStatus),
}
return fmt.Sprintf("%+v", m)
}
func (self *Result) Success() bool {
return self.ExitStatus == 0
}