Commit 1a94fdff authored by Umberto Baldi's avatar Umberto Baldi

uniform the usage of vars in board sub-commands

parent e72f6839
......@@ -30,6 +30,8 @@ import (
"github.com/spf13/cobra"
)
var searchTimeout string // Expressed in a parsable duration, is the timeout for the list and attach commands.
func initAttachCommand() *cobra.Command {
attachCommand := &cobra.Command{
Use: fmt.Sprintf("attach <%s>|<%s> [%s]", tr("port"), tr("FQBN"), tr("sketchPath")),
......@@ -41,15 +43,11 @@ func initAttachCommand() *cobra.Command {
Args: cobra.RangeArgs(1, 2),
Run: runAttachCommand,
}
attachCommand.Flags().StringVar(&attachFlags.searchTimeout, "timeout", "5s",
attachCommand.Flags().StringVar(&searchTimeout, "timeout", "5s",
tr("The connected devices search timeout, raise it if your board doesn't show up (e.g. to %s).", "10s"))
return attachCommand
}
var attachFlags struct {
searchTimeout string // Expressed in a parsable duration, is the timeout for the list and attach commands.
}
func runAttachCommand(cmd *cobra.Command, args []string) {
instance := instance.CreateAndInit()
......@@ -63,7 +61,7 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
Instance: instance,
BoardUri: args[0],
SketchPath: sketchPath.String(),
SearchTimeout: attachFlags.searchTimeout,
SearchTimeout: searchTimeout,
}, output.TaskProgress()); err != nil {
feedback.Errorf(tr("Attach board error: %v"), err)
os.Exit(errorcodes.ErrGeneric)
......
......@@ -18,9 +18,12 @@ package board
import (
"os"
"github.com/arduino/arduino-cli/i18n"
"github.com/spf13/cobra"
)
var tr = i18n.Tr
// NewCommand created a new `board` command
func NewCommand() *cobra.Command {
boardCommand := &cobra.Command{
......
......@@ -25,17 +25,17 @@ import (
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/table"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
var tr = i18n.Tr
var showFullDetails bool
var fqbn string
var listProgrammers bool
var (
showFullDetails bool
fqbn string
listProgrammers bool
)
func initDetailsCommand() *cobra.Command {
var detailsCommand = &cobra.Command{
......
......@@ -31,6 +31,11 @@ import (
"github.com/spf13/cobra"
)
var (
timeout time.Duration
watch bool
)
func initListCommand() *cobra.Command {
listCommand := &cobra.Command{
Use: "list",
......@@ -41,22 +46,17 @@ func initListCommand() *cobra.Command {
Run: runListCommand,
}
listCommand.Flags().DurationVar(&listFlags.timeout, "timeout", time.Second,
listCommand.Flags().DurationVar(&timeout, "timeout", time.Second,
tr("The connected devices search timeout, raise it if your board doesn't show up e.g.: 10s"))
listCommand.Flags().BoolVarP(&listFlags.watch, "watch", "w", false,
listCommand.Flags().BoolVarP(&watch, "watch", "w", false,
tr("Command keeps running and prints list of connected boards whenever there is a change."))
return listCommand
}
var listFlags struct {
timeout time.Duration
watch bool
}
// runListCommand detects and lists the connected arduino boards
func runListCommand(cmd *cobra.Command, args []string) {
if listFlags.watch {
if watch {
inst := instance.CreateAndInit()
watchList(cmd, inst)
os.Exit(0)
......@@ -65,7 +65,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
inst := instance.CreateAndInit()
ports, err := board.List(&rpc.BoardListRequest{
Instance: inst,
Timeout: listFlags.timeout.Milliseconds(),
Timeout: timeout.Milliseconds(),
})
if err != nil {
feedback.Errorf(tr("Error detecting boards: %v"), err)
......
......@@ -30,6 +30,8 @@ import (
"github.com/spf13/cobra"
)
var showHiddenBoard bool
func initListAllCommand() *cobra.Command {
var listAllCommand = &cobra.Command{
Use: fmt.Sprintf("listall [%s]", tr("boardname")),
......@@ -46,8 +48,6 @@ for a specific board if you specify the board name`),
return listAllCommand
}
var showHiddenBoard bool
// runListAllCommand list all installed boards
func runListAllCommand(cmd *cobra.Command, args []string) {
inst := instance.CreateAndInit()
......
......@@ -43,21 +43,17 @@ for a specific board if you specify the board name`),
Args: cobra.ArbitraryArgs,
Run: runSearchCommand,
}
searchCommand.Flags().BoolVarP(&searchFlags.showHiddenBoard, "show-hidden", "a", false, tr("Show also boards marked as 'hidden' in the platform"))
searchCommand.Flags().BoolVarP(&showHiddenBoard, "show-hidden", "a", false, tr("Show also boards marked as 'hidden' in the platform"))
return searchCommand
}
var searchFlags struct {
showHiddenBoard bool
}
func runSearchCommand(cmd *cobra.Command, args []string) {
inst := instance.CreateAndInit()
res, err := board.Search(context.Background(), &rpc.BoardSearchRequest{
Instance: inst,
SearchArgs: strings.Join(args, " "),
IncludeHiddenBoards: searchFlags.showHiddenBoard,
IncludeHiddenBoards: showHiddenBoard,
})
if err != nil {
feedback.Errorf(tr("Error searching boards: %v"), err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment