-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.go
52 lines (45 loc) · 1.02 KB
/
exec.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
package qac
import (
"fmt"
"github.com/enr/runcmd"
)
type executionResult struct {
success bool
exitCode int
stdout string
stderr string
execution string
err error
}
// The actual command executor used from launcher.
type executor interface {
execute(c Command) executionResult
}
type runcmdExecutor struct {
}
func (e *runcmdExecutor) execute(c Command) executionResult {
command := e.toRuncmd(c)
res := command.Run()
return executionResult{
success: res.Success(),
exitCode: res.ExitStatus(),
stdout: res.Stdout().String(),
stderr: res.Stderr().String(),
err: res.Error(),
execution: command.FullCommand(),
}
}
func (e *runcmdExecutor) toRuncmd(command Command) *runcmd.Command {
exe := command.Exe
if command.Extension.isSet() {
exe = fmt.Sprintf(`%s%s`, command.Exe, command.Extension.get())
}
c := &runcmd.Command{
Exe: exe,
Args: command.Args,
CommandLine: command.Cli,
WorkingDir: command.WorkingDir,
Env: command.Env,
}
return c
}