Skip to content

Commit de958b1

Browse files
use arduino-cli executils
1 parent 8da2419 commit de958b1

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/arduino/uno-r4-wifi-fwuploader-plugin
33
go 1.20
44

55
require (
6+
github.com/arduino/arduino-cli v0.0.0-20230630155703-fe6d7499eb5e
67
github.com/arduino/fwuploader-plugin-helper v0.0.0-20230626132535-2effbfcc7853
78
github.com/arduino/go-paths-helper v1.9.1
89
github.com/sstallion/go-hid v0.14.0
@@ -11,6 +12,7 @@ require (
1112

1213
require (
1314
github.com/inconshreveable/mousetrap v1.1.0 // indirect
15+
github.com/leonelquinteros/gotext v1.4.0 // indirect
1416
github.com/pkg/errors v0.9.1 // indirect
1517
github.com/spf13/cobra v1.7.0 // indirect
1618
github.com/spf13/pflag v1.0.5 // indirect

go.sum

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/arduino/arduino-cli v0.0.0-20230630155703-fe6d7499eb5e h1:gmlrLhRuuIY/hw9EvvLCUvMDXMFZBtIVW29tMYGchkw=
2+
github.com/arduino/arduino-cli v0.0.0-20230630155703-fe6d7499eb5e/go.mod h1:2E4tNTNWuf4CtG/pF/Y+fRO6JXxVEcbDDStjZYtMK2c=
13
github.com/arduino/fwuploader-plugin-helper v0.0.0-20230626132535-2effbfcc7853 h1:SEWDw4xcN+qNReANPPlnlGn/R4uP2QHdZyYI4DEYwNs=
24
github.com/arduino/fwuploader-plugin-helper v0.0.0-20230626132535-2effbfcc7853/go.mod h1:y7Vo30dco4xAb39pQ2CRaCvayADjhOBAMrlfji4AYuM=
35
github.com/arduino/go-paths-helper v1.9.1 h1:qpK+zMMjsklSBQa09/P5FZ/uf3LyjVmJK3DLeyiGjCc=
@@ -7,6 +9,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
79
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
810
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
911
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
12+
github.com/leonelquinteros/gotext v1.4.0 h1:2NHPCto5IoMXbrT0bldPrxj0qM5asOCwtb1aUQZ1tys=
13+
github.com/leonelquinteros/gotext v1.4.0/go.mod h1:yZGXREmoGTtBvZHNcc+Yfug49G/2spuF/i/Qlsvz1Us=
1014
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1115
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1216
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -20,7 +24,7 @@ github.com/sstallion/go-hid v0.14.0 h1:bSCzyw5E9lGrdQb1NXgRYfmf/z+B+DfSftDlmjOMb
2024
github.com/sstallion/go-hid v0.14.0/go.mod h1:UaqSxWjbdX9mId5JiqsMAnVtZymx/GSvQMgnzHMks2M=
2125
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2226
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
23-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
27+
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
2428
go.bug.st/relaxed-semver v0.10.2 h1:d/ATAG3MByySZgg7rFj+Wj0fhvP4zfx9Z8Dn/NSCoFg=
2529
go.bug.st/relaxed-semver v0.10.2/go.mod h1:lPVGdtzbQ9/2fv6iXqIXWHOj6cMTUJ/l/Lu1w+sgdio=
2630
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=

main.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package main
22

33
import (
44
"fmt"
5-
"os"
6-
"os/exec"
75
"time"
86

7+
"github.com/arduino/arduino-cli/executils"
98
helper "github.com/arduino/fwuploader-plugin-helper"
109
"github.com/arduino/go-paths-helper"
1110
"github.com/sstallion/go-hid"
@@ -60,10 +59,12 @@ func (p *unoR4WifiPlugin) UploadFirmware(portAddress string, firmwarePath *paths
6059
// Wait a bit before flashing the firmware to allow the board to become available again.
6160
time.Sleep(3 * time.Second)
6261

63-
cmd := exec.Command("espflash", "flash", firmwarePath.String(), "-p", portAddress)
64-
cmd.Stdout = feedback.Out()
65-
cmd.Stderr = feedback.Err()
66-
cmd.Env = append(cmd.Env, os.Environ()...)
62+
cmd, err := executils.NewProcess([]string{}, "espflash", "flash", firmwarePath.String(), "-p", portAddress)
63+
if err != nil {
64+
return err
65+
}
66+
cmd.RedirectStderrTo(feedback.Err())
67+
cmd.RedirectStdoutTo(feedback.Out())
6768
if err := cmd.Run(); err != nil {
6869
return err
6970
}
@@ -101,10 +102,12 @@ func (p *unoR4WifiPlugin) UploadCertificate(portAddress string, certificatePath
101102
// Wait a bit before flashing the certificate to allow the board to become available again.
102103
time.Sleep(3 * time.Second)
103104

104-
cmd := exec.Command("espflash", "write-bin", "-p", portAddress, "-b", "921600", "0x3C0000", certificatePath.String())
105-
cmd.Stdout = feedback.Out()
106-
cmd.Stderr = feedback.Err()
107-
cmd.Env = append(cmd.Env, os.Environ()...)
105+
cmd, err := executils.NewProcess([]string{}, "espflash", "write-bin", "-p", portAddress, "-b", "921600", "0x3C0000", certificatePath.String())
106+
if err != nil {
107+
return err
108+
}
109+
cmd.RedirectStderrTo(feedback.Err())
110+
cmd.RedirectStdoutTo(feedback.Out())
108111
if err := cmd.Run(); err != nil {
109112
return err
110113
}

0 commit comments

Comments
 (0)