@@ -30,10 +30,12 @@ const (
3030 sudoParams = "--non-interactive"
3131)
3232
33+ // Runner runs commands.
3334type Runner interface {
3435 Run (string , ... bool ) (string , error )
3536}
3637
38+ // RunnerError represents a runner error.
3739type RunnerError struct {
3840 Msg string
3941 ExitStatus int
@@ -51,12 +53,10 @@ func NewRunnerError(command string, stderr string, e error) error {
5153 case (* exec.ExitError ):
5254 // SO: https://stackoverflow.com/questions/10385551/get-exit-code-go.
5355 // The program has exited with an exit code != 0
54-
5556 // This works on both Unix and Windows. Although package
5657 // syscall is generally platform dependent, WaitStatus is
5758 // defined for both Unix and Windows and in both cases has
5859 // an ExitStatus() method with the same signature.
59-
6060 if status , ok := err .Sys ().(syscall.WaitStatus ); ok {
6161 exitStatus = status .ExitStatus ()
6262 }
@@ -72,11 +72,12 @@ func NewRunnerError(command string, stderr string, e error) error {
7272 }
7373}
7474
75+ // Error returns runner error.
7576func (e RunnerError ) Error () string {
7677 return e .Msg
7778}
7879
79- // Local .
80+ // LocalRunner represents implementation of a local runner .
8081type LocalRunner struct {
8182 UseSudo bool
8283}
@@ -90,6 +91,7 @@ func NewLocalRunner(useSudo bool) *LocalRunner {
9091 return r
9192}
9293
94+ // Run executes command.
9395func (r * LocalRunner ) Run (command string , options ... bool ) (string , error ) {
9496 command = strings .Trim (command , " \n " )
9597 if len (command ) == 0 {
@@ -104,9 +106,6 @@ func (r *LocalRunner) Run(command string, options ...bool) (string, error) {
104106 log .Dbg (fmt .Sprintf (`Run(Local): "%s"` , logCommand ))
105107 }
106108
107- var out bytes.Buffer
108- var stderr bytes.Buffer
109-
110109 if runtime .GOOS == "windows" {
111110 return "" , errors .New ("Windows is not supported" )
112111 }
@@ -117,6 +116,11 @@ func (r *LocalRunner) Run(command string, options ...bool) (string, error) {
117116
118117 cmd := exec .Command ("/bin/bash" , "-c" , command )
119118
119+ var (
120+ out bytes.Buffer
121+ stderr bytes.Buffer
122+ )
123+
120124 cmd .Stdout = & out
121125 cmd .Stderr = & stderr
122126
0 commit comments