Skip to content

Commit 1a94fdf

Browse files
committed
uniform the usage of vars in board sub-commands
1 parent e72f683 commit 1a94fdf

File tree

6 files changed

+25
-28
lines changed

6 files changed

+25
-28
lines changed

cli/board/attach.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"github.com/spf13/cobra"
3131
)
3232

33+
var searchTimeout string // Expressed in a parsable duration, is the timeout for the list and attach commands.
34+
3335
func initAttachCommand() *cobra.Command {
3436
attachCommand := &cobra.Command{
3537
Use: fmt.Sprintf("attach <%s>|<%s> [%s]", tr("port"), tr("FQBN"), tr("sketchPath")),
@@ -41,15 +43,11 @@ func initAttachCommand() *cobra.Command {
4143
Args: cobra.RangeArgs(1, 2),
4244
Run: runAttachCommand,
4345
}
44-
attachCommand.Flags().StringVar(&attachFlags.searchTimeout, "timeout", "5s",
46+
attachCommand.Flags().StringVar(&searchTimeout, "timeout", "5s",
4547
tr("The connected devices search timeout, raise it if your board doesn't show up (e.g. to %s).", "10s"))
4648
return attachCommand
4749
}
4850

49-
var attachFlags struct {
50-
searchTimeout string // Expressed in a parsable duration, is the timeout for the list and attach commands.
51-
}
52-
5351
func runAttachCommand(cmd *cobra.Command, args []string) {
5452
instance := instance.CreateAndInit()
5553

@@ -63,7 +61,7 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
6361
Instance: instance,
6462
BoardUri: args[0],
6563
SketchPath: sketchPath.String(),
66-
SearchTimeout: attachFlags.searchTimeout,
64+
SearchTimeout: searchTimeout,
6765
}, output.TaskProgress()); err != nil {
6866
feedback.Errorf(tr("Attach board error: %v"), err)
6967
os.Exit(errorcodes.ErrGeneric)

cli/board/board.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ package board
1818
import (
1919
"os"
2020

21+
"github.com/arduino/arduino-cli/i18n"
2122
"github.com/spf13/cobra"
2223
)
2324

25+
var tr = i18n.Tr
26+
2427
// NewCommand created a new `board` command
2528
func NewCommand() *cobra.Command {
2629
boardCommand := &cobra.Command{

cli/board/details.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ import (
2525
"github.com/arduino/arduino-cli/cli/feedback"
2626
"github.com/arduino/arduino-cli/cli/instance"
2727
"github.com/arduino/arduino-cli/commands/board"
28-
"github.com/arduino/arduino-cli/i18n"
2928
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3029
"github.com/arduino/arduino-cli/table"
3130
"github.com/fatih/color"
3231
"github.com/spf13/cobra"
3332
)
3433

35-
var tr = i18n.Tr
36-
var showFullDetails bool
37-
var fqbn string
38-
var listProgrammers bool
34+
var (
35+
showFullDetails bool
36+
fqbn string
37+
listProgrammers bool
38+
)
3939

4040
func initDetailsCommand() *cobra.Command {
4141
var detailsCommand = &cobra.Command{

cli/board/list.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ import (
3131
"github.com/spf13/cobra"
3232
)
3333

34+
var (
35+
timeout time.Duration
36+
watch bool
37+
)
38+
3439
func initListCommand() *cobra.Command {
3540
listCommand := &cobra.Command{
3641
Use: "list",
@@ -41,22 +46,17 @@ func initListCommand() *cobra.Command {
4146
Run: runListCommand,
4247
}
4348

44-
listCommand.Flags().DurationVar(&listFlags.timeout, "timeout", time.Second,
49+
listCommand.Flags().DurationVar(&timeout, "timeout", time.Second,
4550
tr("The connected devices search timeout, raise it if your board doesn't show up e.g.: 10s"))
46-
listCommand.Flags().BoolVarP(&listFlags.watch, "watch", "w", false,
51+
listCommand.Flags().BoolVarP(&watch, "watch", "w", false,
4752
tr("Command keeps running and prints list of connected boards whenever there is a change."))
4853

4954
return listCommand
5055
}
5156

52-
var listFlags struct {
53-
timeout time.Duration
54-
watch bool
55-
}
56-
5757
// runListCommand detects and lists the connected arduino boards
5858
func runListCommand(cmd *cobra.Command, args []string) {
59-
if listFlags.watch {
59+
if watch {
6060
inst := instance.CreateAndInit()
6161
watchList(cmd, inst)
6262
os.Exit(0)
@@ -65,7 +65,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
6565
inst := instance.CreateAndInit()
6666
ports, err := board.List(&rpc.BoardListRequest{
6767
Instance: inst,
68-
Timeout: listFlags.timeout.Milliseconds(),
68+
Timeout: timeout.Milliseconds(),
6969
})
7070
if err != nil {
7171
feedback.Errorf(tr("Error detecting boards: %v"), err)

cli/board/listall.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"github.com/spf13/cobra"
3131
)
3232

33+
var showHiddenBoard bool
34+
3335
func initListAllCommand() *cobra.Command {
3436
var listAllCommand = &cobra.Command{
3537
Use: fmt.Sprintf("listall [%s]", tr("boardname")),
@@ -46,8 +48,6 @@ for a specific board if you specify the board name`),
4648
return listAllCommand
4749
}
4850

49-
var showHiddenBoard bool
50-
5151
// runListAllCommand list all installed boards
5252
func runListAllCommand(cmd *cobra.Command, args []string) {
5353
inst := instance.CreateAndInit()

cli/board/search.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,17 @@ for a specific board if you specify the board name`),
4343
Args: cobra.ArbitraryArgs,
4444
Run: runSearchCommand,
4545
}
46-
searchCommand.Flags().BoolVarP(&searchFlags.showHiddenBoard, "show-hidden", "a", false, tr("Show also boards marked as 'hidden' in the platform"))
46+
searchCommand.Flags().BoolVarP(&showHiddenBoard, "show-hidden", "a", false, tr("Show also boards marked as 'hidden' in the platform"))
4747
return searchCommand
4848
}
4949

50-
var searchFlags struct {
51-
showHiddenBoard bool
52-
}
53-
5450
func runSearchCommand(cmd *cobra.Command, args []string) {
5551
inst := instance.CreateAndInit()
5652

5753
res, err := board.Search(context.Background(), &rpc.BoardSearchRequest{
5854
Instance: inst,
5955
SearchArgs: strings.Join(args, " "),
60-
IncludeHiddenBoards: searchFlags.showHiddenBoard,
56+
IncludeHiddenBoards: showHiddenBoard,
6157
})
6258
if err != nil {
6359
feedback.Errorf(tr("Error searching boards: %v"), err)

0 commit comments

Comments
 (0)