1515
1616package 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.
2327type 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
3644func (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