Skip to content

Commit fd39831

Browse files
committed
Make the upload port parameter mandatory only when really needed
1 parent d7fcbb9 commit fd39831

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

Diff for: commands/upload/upload.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ func runProgramAction(pm *packagemanager.PackageManager,
9292
port = deviceURI.Host + deviceURI.Path
9393
}
9494
}
95-
if port == "" {
96-
return fmt.Errorf("no upload port provided")
97-
}
9895
logrus.WithField("port", port).Tracef("Upload port")
9996

10097
if fqbnIn == "" && sketch != nil && sketch.Metadata != nil {
@@ -266,6 +263,10 @@ func runProgramAction(pm *packagemanager.PackageManager,
266263
if programmer == nil && !burnBootloader {
267264
// Perform reset via 1200bps touch if requested
268265
if uploadProperties.GetBoolean("upload.use_1200bps_touch") {
266+
if port == "" {
267+
return fmt.Errorf("no upload port provided")
268+
}
269+
269270
ports, err := serial.GetPortsList()
270271
if err != nil {
271272
return fmt.Errorf("cannot get serial port list: %s", err)
@@ -310,12 +311,14 @@ func runProgramAction(pm *packagemanager.PackageManager,
310311
}
311312
}
312313

313-
// Set serial port property
314-
uploadProperties.Set("serial.port", actualPort)
315-
if strings.HasPrefix(actualPort, "/dev/") {
316-
uploadProperties.Set("serial.port.file", actualPort[5:])
317-
} else {
318-
uploadProperties.Set("serial.port.file", actualPort)
314+
if port != "" {
315+
// Set serial port property
316+
uploadProperties.Set("serial.port", actualPort)
317+
if strings.HasPrefix(actualPort, "/dev/") {
318+
uploadProperties.Set("serial.port.file", actualPort[5:])
319+
} else {
320+
uploadProperties.Set("serial.port.file", actualPort)
321+
}
319322
}
320323

321324
// Build recipe for upload
@@ -348,6 +351,9 @@ func runTool(recipeID string, props *properties.Map, outStream, errStream io.Wri
348351
if strings.TrimSpace(recipe) == "" {
349352
return nil // Nothing to run
350353
}
354+
if props.IsProertyMissingInExpandPropsInString("serial.port", recipe) {
355+
return fmt.Errorf("no upload port provided")
356+
}
351357
cmdLine := props.ExpandPropsInString(recipe)
352358
cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false)
353359
if err != nil {

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
bou.ke/monkey v1.0.1
77
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
88
github.com/arduino/go-paths-helper v1.0.1
9-
github.com/arduino/go-properties-orderedmap v1.0.0
9+
github.com/arduino/go-properties-orderedmap v1.2.0
1010
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
1111
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
1212
github.com/cmaglie/pb v1.0.27

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c h1:agh2JT9
1010
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c/go.mod h1:HK7SpkEax/3P+0w78iRQx1sz1vCDYYw9RXwHjQTB5i8=
1111
github.com/arduino/go-paths-helper v1.0.1 h1:utYXLM2RfFlc9qp/MJTIYp3t6ux/xM6mWjeEb/WLK4Q=
1212
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
13-
github.com/arduino/go-properties-orderedmap v1.0.0 h1:caaM25TQZKkytoKQUsgqtOVbrM5i8Gb427JmW0KL05s=
14-
github.com/arduino/go-properties-orderedmap v1.0.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
13+
github.com/arduino/go-properties-orderedmap v1.2.0 h1:H7sub5hjAtFLZYd/NVWBOr6Jw7U1CnamYvNSM3dDdyE=
14+
github.com/arduino/go-properties-orderedmap v1.2.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
1515
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=
1616
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
1717
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=

0 commit comments

Comments
 (0)