Skip to content

Commit 81634e2

Browse files
matteosuppofacchinm
authored andcommitted
Refactor in order to isolate the package
1 parent 31f26dd commit 81634e2

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

programmer/programmer.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12-
"github.com/arduino/arduino-create-agent/tools"
12+
"github.com/arduino/arduino-create-agent/utilities"
1313
"github.com/facchinm/go-serial"
1414
"github.com/pkg/errors"
1515
)
@@ -198,6 +198,8 @@ func waitReset(beforeReset []string, l logger) string {
198198
return port
199199
}
200200

201+
// program spawns the given binary with the given args, logging the sdtout and stderr
202+
// through the logger
201203
func program(binary string, args []string, l logger) error {
202204
// remove quotes form binary command and args
203205
binary = strings.Replace(binary, "\"", "", -1)
@@ -214,16 +216,16 @@ func program(binary string, args []string, l logger) error {
214216

215217
oscmd := exec.Command(binary, args...)
216218

217-
tools.TellCommandNotToSpawnShell(oscmd)
219+
utilities.TellCommandNotToSpawnShell(oscmd)
218220

219221
stdout, err := oscmd.StdoutPipe()
220222
if err != nil {
221-
return err
223+
return errors.Wrapf(err, "Retrieve output")
222224
}
223225

224226
stderr, err := oscmd.StderrPipe()
225227
if err != nil {
226-
return err
228+
return errors.Wrapf(err, "Retrieve output")
227229
}
228230

229231
info(l, "Flashing with command:"+binary+extension+" "+strings.Join(args, " "))
@@ -250,5 +252,5 @@ func program(binary string, args []string, l logger) error {
250252

251253
err = oscmd.Wait()
252254

253-
return err
255+
return errors.Wrapf(err, "Executing command")
254256
}

utilities/utilities_darwin.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package utilities
2+
3+
import "os/exec"
4+
5+
func TellCommandNotToSpawnShell(_ *exec.Cmd) {
6+
}

utilities/utilities_linux.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package utilities
2+
3+
import "os/exec"
4+
5+
func TellCommandNotToSpawnShell(_ *exec.Cmd) {
6+
}

utilities/utilities_windows.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package utilities
2+
3+
import (
4+
"os/exec"
5+
"syscall"
6+
)
7+
8+
func TellCommandNotToSpawnShell(oscmd *exec.Cmd) {
9+
oscmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
10+
}

0 commit comments

Comments
 (0)