Skip to content

Commit 3af30e4

Browse files
committed
add flag to allow board options to be specified seperately from fqbn
1 parent c918d8b commit 3af30e4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

cli/arguments/fqbn.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@
1515

1616
package arguments
1717

18-
import "github.com/spf13/cobra"
18+
import (
19+
"strings"
20+
21+
"github.com/spf13/cobra"
22+
)
1923

2024
// Fqbn contains the fqbn flag data.
2125
// This is useful so all flags used by commands that need
2226
// this information are consistent with each other.
2327
type Fqbn struct {
24-
fqbn string
28+
fqbn string
29+
boardOptions []string // List of boards specific options separated by commas. Or can be used multiple times for multiple options.
30+
2531
}
2632

2733
// AddToCommand adds the flags used to set fqbn to the specified Command
@@ -30,10 +36,18 @@ func (f *Fqbn) AddToCommand(cmd *cobra.Command) {
3036
cmd.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
3137
return GetInstalledBoards(), cobra.ShellCompDirectiveDefault
3238
})
39+
cmd.Flags().StringSliceVar(&f.boardOptions, "board-options", []string{},
40+
tr("List of board options separated by commas. Or can be used multiple times for multiple options."))
3341
}
3442

35-
// String returns the fqbn
43+
// String returns the fqbn with the board options if there are any
3644
func (f *Fqbn) String() string {
45+
// If boardOptions are passed with the "--board-options" flags then add them along with the fqbn
46+
// This way it's possible to use either the legacy way (appending board options directly to the fqbn),
47+
// or the new and more elegant way (using "--board-options"), even using multiple "--board-options" works.
48+
if f.fqbn != "" && len(f.boardOptions) != 0 {
49+
return f.fqbn + ":" + strings.Join(f.boardOptions, ",")
50+
}
3751
return f.fqbn
3852
}
3953

0 commit comments

Comments
 (0)