Skip to content

add flag to allow board options to be specified seperately from fqbn #1688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions cli/arguments/fqbn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@

package arguments

import "github.com/spf13/cobra"
import (
"strings"

"github.com/spf13/cobra"
)

// Fqbn contains the fqbn flag data.
// This is useful so all flags used by commands that need
// this information are consistent with each other.
type Fqbn struct {
fqbn string
fqbn string
boardOptions []string // List of boards specific options separated by commas. Or can be used multiple times for multiple options.
}

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

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

Expand Down