@@ -28,6 +28,7 @@ import (
28
28
"github.com/arduino/arduino-cli/commands/upload"
29
29
"github.com/arduino/arduino-cli/i18n"
30
30
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
31
+ "github.com/arduino/go-paths-helper"
31
32
"github.com/spf13/cobra"
32
33
)
33
34
@@ -81,27 +82,40 @@ func run(command *cobra.Command, args []string) {
81
82
if len (args ) > 0 {
82
83
path = args [0 ]
83
84
}
84
- sketchPath := arguments .InitSketchPath (path )
85
+ var sketchPath * paths.Path
86
+ var sk * sketch.Sketch = nil
87
+ // If the user explicitly specified a directory that contains binaries to upload
88
+ // use those, we don't really need a valid Sketch to upload in this case
89
+ if importDir == "" && importFile == "" {
90
+ sketchPath = arguments .InitSketchPath (path )
85
91
86
- // .pde files are still supported but deprecated, this warning urges the user to rename them
87
- if files := sketch .CheckForPdeFiles (sketchPath ); len (files ) > 0 {
88
- feedback .Error (tr ("Sketches with .pde extension are deprecated, please rename the following files to .ino:" ))
89
- for _ , f := range files {
90
- feedback .Error (f )
92
+ // .pde files are still supported but deprecated, this warning urges the user to rename them
93
+ if files := sketch .CheckForPdeFiles (sketchPath ); len (files ) > 0 {
94
+ feedback .Error (tr ("Sketches with .pde extension are deprecated, please rename the following files to .ino:" ))
95
+ for _ , f := range files {
96
+ feedback .Error (f )
97
+ }
91
98
}
92
- }
93
99
94
- sk , err := sketch .New (sketchPath )
95
- if err != nil {
96
- feedback .Errorf (tr ("Error during Upload: %v" ), err )
97
- os .Exit (errorcodes .ErrGeneric )
100
+ var err error
101
+ sk , err = sketch .New (sketchPath )
102
+ if err != nil {
103
+ feedback .Errorf (tr ("Error during Upload: %v" ), err )
104
+ os .Exit (errorcodes .ErrGeneric )
105
+ }
98
106
}
99
107
discoveryPort , err := port .GetPort (instance , sk )
100
108
if err != nil {
101
109
feedback .Errorf (tr ("Error during Upload: %v" ), err )
102
110
os .Exit (errorcodes .ErrGeneric )
103
111
}
104
112
113
+ if fqbn == "" && sk != nil && sk .Metadata != nil {
114
+ // If the user didn't specify an FQBN and a sketch.json file is present
115
+ // read it from there.
116
+ fqbn = sk .Metadata .CPU .Fqbn
117
+ }
118
+
105
119
userFieldRes , err := upload .SupportedUserFields (context .Background (), & rpc.SupportedUserFieldsRequest {
106
120
Instance : instance ,
107
121
Fqbn : fqbn ,
@@ -118,10 +132,14 @@ func run(command *cobra.Command, args []string) {
118
132
fields = arguments .AskForUserFields (userFieldRes .UserFields )
119
133
}
120
134
135
+ if sketchPath != nil {
136
+ path = sketchPath .String ()
137
+ }
138
+
121
139
if _ , err := upload .Upload (context .Background (), & rpc.UploadRequest {
122
140
Instance : instance ,
123
141
Fqbn : fqbn ,
124
- SketchPath : sketchPath . String () ,
142
+ SketchPath : path ,
125
143
Port : discoveryPort .ToRPC (),
126
144
Verbose : verbose ,
127
145
Verify : verify ,
0 commit comments