Skip to content

Commit 5bf689b

Browse files
committed
add flag to allow board options to be specified seperately from fqbn
1 parent 8b53b85 commit 5bf689b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cli/arguments/fqbn.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import "github.com/spf13/cobra"
2121
// This is useful so all flags used by commands that need
2222
// this information are consistent with each other.
2323
type Fqbn struct {
24-
fqbn string
24+
fqbn string
25+
boardOptions []string // List of boards specific options separated by commas. Or can be used multiple times for multiple options.
26+
2527
}
2628

2729
// AddToCommand adds the flags used to set fqbn to the specified Command
@@ -30,6 +32,8 @@ func (f *Fqbn) AddToCommand(cmd *cobra.Command) {
3032
cmd.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
3133
return GetInstalledBoards(), cobra.ShellCompDirectiveDefault
3234
})
35+
cmd.Flags().StringSliceVar(&f.boardOptions, "board-options", []string{},
36+
tr("List of board options separated by commas. Or can be used multiple times for multiple options."))
3337
}
3438

3539
// String returns the fqbn
@@ -41,3 +45,7 @@ func (f *Fqbn) String() string {
4145
func (f *Fqbn) Set(fqbn string) {
4246
f.fqbn = fqbn
4347
}
48+
49+
func (f *Fqbn) GetOptions() []string {
50+
return f.boardOptions
51+
}

cli/compile/compile.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
160160
}
161161

162162
detectedFqbn := fqbn.String()
163+
164+
// If boardOptions are passed with the "--board-options" flags then add them along with the fqbn
165+
// This way it's possible to use either the legacy way (appending board options directly to the fqbn),
166+
// or the new and more elegant way (using "--board-options"), even using multiple "--board-options" works.
167+
if detectedFqbn != "" && len(fqbn.GetOptions()) != 0 {
168+
detectedFqbn += ":" + strings.Join(fqbn.GetOptions(), ",")
169+
}
170+
163171
var sk *sketch.Sketch
164172
var discoveryPort *discovery.Port
165173
// If the user didn't provide an FQBN it might either mean

0 commit comments

Comments
 (0)