@@ -26,6 +26,7 @@ import (
26
26
"github.com/arduino/arduino-cli/cli/errorcodes"
27
27
"github.com/arduino/arduino-cli/cli/instance"
28
28
"github.com/arduino/arduino-cli/commands/compile"
29
+ "github.com/arduino/arduino-cli/commands/upload"
29
30
"github.com/arduino/arduino-cli/common/formatter"
30
31
rpc "github.com/arduino/arduino-cli/rpc/commands"
31
32
"github.com/arduino/go-paths-helper"
@@ -34,17 +35,20 @@ import (
34
35
)
35
36
36
37
var (
37
- fqbn string // Fully Qualified Board Name, e.g.: arduino:avr:uno.
38
- showProperties bool // Show all build preferences used instead of compiling.
39
- preprocess bool // Print preprocessed code to stdout.
40
- buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
41
- buildPath string // Path where to save compiled files.
42
- buildProperties []string // List of custom build properties separated by commas. Or can be used multiple times for multiple properties.
43
- warnings string // Used to tell gcc which warning level to use.
44
- verbose bool // Turns on verbose mode.
45
- quiet bool // Suppresses almost every output.
46
- vidPid string // VID/PID specific build properties.
47
- exportFile string // The compiled binary is written to this file
38
+ fqbn string // Fully Qualified Board Name, e.g.: arduino:avr:uno.
39
+ showProperties bool // Show all build preferences used instead of compiling.
40
+ preprocess bool // Print preprocessed code to stdout.
41
+ buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
42
+ buildPath string // Path where to save compiled files.
43
+ buildProperties []string // List of custom build properties separated by commas. Or can be used multiple times for multiple properties.
44
+ warnings string // Used to tell gcc which warning level to use.
45
+ verbose bool // Turns on verbose mode.
46
+ quiet bool // Suppresses almost every output.
47
+ vidPid string // VID/PID specific build properties.
48
+ uploadAfterCompile bool // Upload the binary after the compilation.
49
+ port string // Upload port, e.g.: COM10 or /dev/ttyACM0.
50
+ verify bool // Upload, verify uploaded binary after the upload.
51
+ exportFile string // The compiled binary is written to this file
48
52
)
49
53
50
54
// NewCommand created a new `compile` command
@@ -71,6 +75,9 @@ func NewCommand() *cobra.Command {
71
75
`Optional, can be "none", "default", "more" and "all". Defaults to "none". Used to tell gcc which warning level to use (-W flag).` )
72
76
command .Flags ().BoolVarP (& verbose , "verbose" , "v" , false , "Optional, turns on verbose mode." )
73
77
command .Flags ().BoolVar (& quiet , "quiet" , false , "Optional, supresses almost every output." )
78
+ command .Flags ().BoolVarP (& uploadAfterCompile , "upload" , "u" , false , "Upload the binary after the compilation." )
79
+ command .Flags ().StringVarP (& port , "port" , "p" , "" , "Upload port, e.g.: COM10 or /dev/ttyACM0" )
80
+ command .Flags ().BoolVarP (& verify , "verify" , "t" , false , "Verify uploaded binary after the upload." )
74
81
command .Flags ().StringVar (& vidPid , "vid-pid" , "" , "When specified, VID/PID specific build properties are used, if boards supports them." )
75
82
76
83
return command
@@ -106,6 +113,23 @@ func run(cmd *cobra.Command, args []string) {
106
113
formatter .PrintError (err , "Error during build" )
107
114
os .Exit (errorcodes .ErrGeneric )
108
115
}
116
+
117
+ if uploadAfterCompile {
118
+ _ , err := upload .Upload (context .Background (), & rpc.UploadReq {
119
+ Instance : instance ,
120
+ Fqbn : fqbn ,
121
+ SketchPath : sketchPath .String (),
122
+ Port : port ,
123
+ Verbose : verbose ,
124
+ Verify : verify ,
125
+ ImportFile : exportFile ,
126
+ }, os .Stdout , os .Stderr )
127
+
128
+ if err != nil {
129
+ formatter .PrintError (err , "Error during Upload" )
130
+ os .Exit (errorcodes .ErrGeneric )
131
+ }
132
+ }
109
133
}
110
134
111
135
// initSketchPath returns the current working directory
0 commit comments