Skip to content

Commit 0bce37c

Browse files
committedJan 5, 2020
Handle FQBNs provided via sketch.json files in upload/compile commands
1 parent 78c6480 commit 0bce37c

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed
 

‎cli/cli_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
313313
// Build sketch without FQBN
314314
exitCode, d = executeWithArgs("compile", sketchPath)
315315
require.NotZero(t, exitCode)
316-
require.Contains(t, string(d), "required flag(s) \"fqbn\" not set")
316+
require.Contains(t, string(d), "Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
317317

318318
// Build sketch for arduino:avr:uno
319319
exitCode, d = executeWithArgs("compile", "-b", "arduino:avr:uno", sketchPath)

‎cli/compile/compile.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"context"
2222
"os"
2323

24+
"github.com/arduino/arduino-cli/arduino/sketches"
25+
2426
"github.com/arduino/arduino-cli/cli/feedback"
2527

2628
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -80,8 +82,6 @@ func NewCommand() *cobra.Command {
8082
command.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
8183
command.Flags().StringVar(&vidPid, "vid-pid", "", "When specified, VID/PID specific build properties are used, if boards supports them.")
8284

83-
command.MarkFlagRequired("fqbn")
84-
8585
return command
8686
}
8787

@@ -98,6 +98,15 @@ func run(cmd *cobra.Command, args []string) {
9898
}
9999

100100
sketchPath := initSketchPath(path)
101+
sketch, err := sketches.NewSketchFromPath(sketchPath)
102+
if err != nil {
103+
feedback.Errorf("Error opening sketch: %v", err)
104+
os.Exit(errorcodes.ErrGeneric)
105+
}
106+
if fqbn == "" && sketch.Metadata.CPU.Fqbn == "" {
107+
feedback.Errorf("Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
108+
os.Exit(errorcodes.ErrGeneric)
109+
}
101110

102111
_, err = compile.Compile(context.Background(), &rpc.CompileReq{
103112
Instance: inst,

‎cli/upload/upload.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"context"
2222
"os"
2323

24+
"github.com/arduino/arduino-cli/arduino/sketches"
25+
2426
"github.com/arduino/arduino-cli/cli/errorcodes"
2527
"github.com/arduino/arduino-cli/cli/feedback"
2628
"github.com/arduino/arduino-cli/cli/instance"
@@ -56,7 +58,6 @@ func NewCommand() *cobra.Command {
5658
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
5759
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
5860

59-
uploadCommand.MarkFlagRequired("fqbn")
6061
uploadCommand.MarkFlagRequired("port")
6162

6263
return uploadCommand
@@ -74,8 +75,17 @@ func run(command *cobra.Command, args []string) {
7475
path = paths.New(args[0])
7576
}
7677
sketchPath := initSketchPath(path)
78+
sketch, err := sketches.NewSketchFromPath(sketchPath)
79+
if err != nil {
80+
feedback.Errorf("Error opening sketch: %v", err)
81+
os.Exit(errorcodes.ErrGeneric)
82+
}
83+
if fqbn == "" && sketch.Metadata.CPU.Fqbn == "" {
84+
feedback.Errorf("Error: no FQBN provided. Set --fqbn flag or attach board to sketch")
85+
os.Exit(errorcodes.ErrGeneric)
86+
}
7787

78-
if _, err := upload.Upload(context.Background(), &rpc.UploadReq{
88+
if _, err = upload.Upload(context.Background(), &rpc.UploadReq{
7989
Instance: instance,
8090
Fqbn: fqbn,
8191
SketchPath: sketchPath.String(),

0 commit comments

Comments
 (0)