15
15
16
16
package arguments
17
17
18
- import "github.com/spf13/cobra"
18
+ import (
19
+ "strings"
20
+
21
+ "github.com/spf13/cobra"
22
+ )
19
23
20
24
// Fqbn contains the fqbn flag data.
21
25
// This is useful so all flags used by commands that need
22
26
// this information are consistent with each other.
23
27
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.
25
30
}
26
31
27
32
// AddToCommand adds the flags used to set fqbn to the specified Command
@@ -30,10 +35,18 @@ func (f *Fqbn) AddToCommand(cmd *cobra.Command) {
30
35
cmd .RegisterFlagCompletionFunc ("fqbn" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
31
36
return GetInstalledBoards (), cobra .ShellCompDirectiveDefault
32
37
})
38
+ cmd .Flags ().StringSliceVar (& f .boardOptions , "board-options" , []string {},
39
+ tr ("List of board options separated by commas. Or can be used multiple times for multiple options." ))
33
40
}
34
41
35
- // String returns the fqbn
42
+ // String returns the fqbn with the board options if there are any
36
43
func (f * Fqbn ) String () string {
44
+ // If boardOptions are passed with the "--board-options" flags then add them along with the fqbn
45
+ // This way it's possible to use either the legacy way (appending board options directly to the fqbn),
46
+ // or the new and more elegant way (using "--board-options"), even using multiple "--board-options" works.
47
+ if f .fqbn != "" && len (f .boardOptions ) != 0 {
48
+ return f .fqbn + ":" + strings .Join (f .boardOptions , "," )
49
+ }
37
50
return f .fqbn
38
51
}
39
52
0 commit comments