-
Notifications
You must be signed in to change notification settings - Fork 0
/
runcmd.go
51 lines (43 loc) · 889 Bytes
/
runcmd.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 core
import (
"bytes"
"github.com/enr/clui"
"github.com/enr/runcmd"
)
type runcmdWrapperRequest struct {
args []string
workingDir string
}
type runcmdWrapper interface {
exec(r runcmdWrapperRequest) runcmdResult
}
type runcmdResult interface {
Success() bool
Stderr() *bytes.Buffer
Stdout() *bytes.Buffer
ExitStatus() int
Error() error
}
func newGitExecutor(ui *clui.Clui) (runcmdWrapper, error) {
git, err := gitExecutablePath()
if err != nil {
return defaultGitWrapper{}, err
}
return defaultGitWrapper{
git: git,
ui: ui,
}, nil
}
type defaultGitWrapper struct {
git string
ui *clui.Clui
}
func (g defaultGitWrapper) exec(r runcmdWrapperRequest) runcmdResult {
command := &runcmd.Command{
Exe: g.git,
Args: r.args,
WorkingDir: r.workingDir,
}
g.ui.Confidentialf("Execute command %s", command)
return command.Run()
}