@@ -26,6 +26,7 @@ import (
2626 "github.com/arduino/arduino-cli/cli/errorcodes"
2727 "github.com/arduino/arduino-cli/cli/instance"
2828 "github.com/arduino/arduino-cli/commands/compile"
29+ "github.com/arduino/arduino-cli/commands/upload"
2930 "github.com/arduino/arduino-cli/common/formatter"
3031 rpc "github.com/arduino/arduino-cli/rpc/commands"
3132 "github.com/arduino/go-paths-helper"
@@ -34,17 +35,20 @@ import (
3435)
3536
3637var (
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
4852)
4953
5054// NewCommand created a new `compile` command
@@ -71,6 +75,9 @@ func NewCommand() *cobra.Command {
7175 `Optional, can be "none", "default", "more" and "all". Defaults to "none". Used to tell gcc which warning level to use (-W flag).`)
7276 command.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
7377 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.")
7481 command.Flags().StringVar(&vidPid, "vid-pid", "", "When specified, VID/PID specific build properties are used, if boards supports them.")
7582
7683 return command
@@ -106,6 +113,23 @@ func run(cmd *cobra.Command, args []string) {
106113 formatter.PrintError(err, "Error during build")
107114 os.Exit(errorcodes.ErrGeneric)
108115 }
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+ }
109133}
110134
111135// initSketchPath returns the current working directory
0 commit comments