-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep.go
62 lines (54 loc) · 1.02 KB
/
step.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
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"os/exec"
"strings"
)
type Runner interface {
Run() (string, error)
}
type Step struct {
Name string
Bin string
Args []string
successful bool
log string
wd string
}
// TODO
// type CloneStep struct {
// Step
// }
// type PullStep struct {
// Step
// }
// type DeployStep struct {
// Step
// }
// type NotifyStep struct {
// Step
// }
// Run executes the step and returns corresponding output. Satisfies the Runner
// interface.
func (s *Step) Run() (string, error) {
cmdStr := s.Bin + " " + strings.Join(s.Args, " ")
cmd := exec.Command(s.Bin, s.Args...)
cmd.Dir = s.wd
out, err := cmd.CombinedOutput()
if err != nil {
return cmdStr + "\n" + string(out), &StepError{
name: s.Name,
message: "step failed to execute",
err: err,
}
}
return cmdStr + "\n" + string(out), nil
}
type StepError struct {
name string
message string
err error
}
func (s *StepError) Error() string {
return fmt.Sprintf("%s: %q", s.message, s.err)
}