Skip to content

Commit b6bdf64

Browse files
author
Luca Bianconi
committed
fix: remove board options flag
1 parent 8988783 commit b6bdf64

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

Diff for: commands/board/list.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartError
205205
}
206206
defer release()
207207

208-
var requestedFqbn *cores.FQBN
208+
var fqbnFilter *cores.FQBN
209209
if f := req.GetFqbn(); f != "" {
210210
var err error
211-
requestedFqbn, err = cores.ParseFQBN(f)
211+
fqbnFilter, err = cores.ParseFQBN(f)
212212
if err != nil {
213213
return nil, nil, &arduino.InvalidFQBNError{Cause: err}
214214
}
@@ -232,7 +232,7 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartError
232232
MatchingBoards: boards,
233233
}
234234

235-
if requestedFqbn == nil || hasMatchingBoard(b, requestedFqbn) {
235+
if fqbnFilter == nil || hasMatchingBoard(b, fqbnFilter) {
236236
retVal = append(retVal, b)
237237
}
238238
}

Diff for: internal/cli/arguments/fqbn.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,27 @@ type Fqbn struct {
3333
boardOptions []string // List of boards specific options separated by commas. Or can be used multiple times for multiple options.
3434
}
3535

36-
// AddToCommand adds the flags used to set fqbn to the specified Command
36+
// AddToCommand adds the flags used to set fqbn and the board options to the specified Command
3737
func (f *Fqbn) AddToCommand(cmd *cobra.Command) {
38+
f.addToCommand(cmd, true)
39+
}
40+
41+
// AddToCommand adds the flags used to set fqbn to the specified Command, board options flag is not provided
42+
func (f *Fqbn) AddToCommandWithoutBoardOptions(cmd *cobra.Command) {
43+
f.addToCommand(cmd, false)
44+
}
45+
46+
func (f *Fqbn) addToCommand(cmd *cobra.Command, enableBoardOptions bool) bool {
3847
cmd.Flags().StringVarP(&f.fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
3948
cmd.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
4049
return GetInstalledBoards(), cobra.ShellCompDirectiveDefault
4150
})
42-
cmd.Flags().StringSliceVar(&f.boardOptions, "board-options", []string{},
43-
tr("List of board options separated by commas. Or can be used multiple times for multiple options."))
51+
52+
if enableBoardOptions {
53+
cmd.Flags().StringSliceVar(&f.boardOptions, "board-options", []string{},
54+
tr("List of board options separated by commas. Or can be used multiple times for multiple options."))
55+
}
56+
return false
4457
}
4558

4659
// String returns the fqbn with the board options if there are any

Diff for: internal/cli/board/list.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"os"
2121
"sort"
2222

23+
"github.com/arduino/arduino-cli/arduino"
2324
"github.com/arduino/arduino-cli/arduino/cores"
2425
"github.com/arduino/arduino-cli/commands/board"
2526
"github.com/arduino/arduino-cli/internal/cli/arguments"
@@ -47,7 +48,7 @@ func initListCommand() *cobra.Command {
4748
}
4849

4950
timeoutArg.AddToCommand(listCommand)
50-
fqbn.AddToCommand(listCommand)
51+
fqbn.AddToCommandWithoutBoardOptions(listCommand)
5152
listCommand.Flags().BoolVarP(&watch, "watch", "w", false, tr("Command keeps running and prints list of connected boards whenever there is a change."))
5253

5354
return listCommand
@@ -70,6 +71,9 @@ func runListCommand(cmd *cobra.Command, args []string) {
7071
Fqbn: fqbn.String(),
7172
})
7273
if err != nil {
74+
if _, isFqbnError := err.(*arduino.InvalidFQBNError); isFqbnError {
75+
feedback.Fatal(tr(err.Error()), feedback.ErrBadArgument)
76+
}
7377
feedback.Warning(tr("Error detecting boards: %v", err))
7478
}
7579
for _, err := range discvoeryErrors {

Diff for: internal/integrationtest/board/board_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,39 @@ func TestBoardList(t *testing.T) {
9191
MustBeEmpty()
9292
}
9393

94+
func TestBoardListWithFqbnFilter(t *testing.T) {
95+
if os.Getenv("CI") != "" {
96+
t.Skip("VMs have no serial ports")
97+
}
98+
99+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
100+
defer env.CleanUp()
101+
102+
_, _, err := cli.Run("core", "update-index")
103+
require.NoError(t, err)
104+
stdout, _, err := cli.Run("board", "list", "-b", "arduino:avr:uno", "--format", "json")
105+
require.NoError(t, err)
106+
// this is a bit of a passpartout test, it actually filters the "bluetooth boards" locally
107+
// but it would succeed even if the filtering wasn't working properly
108+
// TODO: find a way to simulate connected boards or create a unit test which
109+
// mocks or initializes multiple components
110+
requirejson.Parse(t, stdout).
111+
MustBeEmpty()
112+
}
113+
114+
func TestBoardListWithFqbnFilterInvalid(t *testing.T) {
115+
if os.Getenv("CI") != "" {
116+
t.Skip("VMs have no serial ports")
117+
}
118+
119+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
120+
defer env.CleanUp()
121+
122+
_, stderr, err := cli.Run("board", "list", "-b", "yadayada", "--format", "json")
123+
require.Error(t, err)
124+
requirejson.Query(t, stderr, ".error", `"Invalid FQBN: not an FQBN: yadayada"`)
125+
}
126+
94127
func TestBoardListWithInvalidDiscovery(t *testing.T) {
95128
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
96129
defer env.CleanUp()

0 commit comments

Comments
 (0)