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.
30
+
25
31
}
26
32
27
33
// AddToCommand adds the flags used to set fqbn to the specified Command
@@ -30,10 +36,18 @@ func (f *Fqbn) AddToCommand(cmd *cobra.Command) {
30
36
cmd .RegisterFlagCompletionFunc ("fqbn" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
31
37
return GetInstalledBoards (), cobra .ShellCompDirectiveDefault
32
38
})
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." ))
33
41
}
34
42
35
- // String returns the fqbn
43
+ // String returns the fqbn with the board options if there are any
36
44
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
+ }
37
51
return f .fqbn
38
52
}
39
53
0 commit comments