Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aeb1528

Browse files
committed
refactor monitor command to be consistent with other commands
1 parent 0f25964 commit aeb1528

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

‎cli/monitor/monitor.go‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@ import (
3737
"github.com/spf13/cobra"
3838
)
3939

40-
var tr = i18n.Tr
41-
42-
var portArgs arguments.Port
43-
var describe bool
44-
var configs []string
45-
var quiet bool
46-
var fqbn string
40+
var (
41+
portArgs arguments.Port
42+
describe bool
43+
configs []string
44+
quiet bool
45+
fqbn arguments.Fqbn
46+
tr = i18n.Tr
47+
)
4748

4849
// NewCommand created a new `monitor` command
4950
func NewCommand() *cobra.Command {
50-
cmd := &cobra.Command{
51+
monitorCommand := &cobra.Command{
5152
Use: "monitor",
5253
Short: tr("Open a communication port with a board."),
5354
Long: tr("Open a communication port with a board."),
@@ -56,16 +57,13 @@ func NewCommand() *cobra.Command {
5657
" " + os.Args[0] + " monitor -p /dev/ttyACM0 --describe",
5758
Run: runMonitorCmd,
5859
}
59-
portArgs.AddToCommand(cmd)
60-
cmd.Flags().BoolVar(&describe, "describe", false, tr("Show all the settings of the communication port."))
61-
cmd.Flags().StringSliceVarP(&configs, "config", "c", []string{}, tr("Configuration of the port."))
62-
cmd.Flags().BoolVarP(&quiet, "quiet", "q", false, tr("Run in silent mode, show only monitor input and output."))
63-
cmd.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
64-
cmd.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
65-
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
66-
})
67-
cmd.MarkFlagRequired("port")
68-
return cmd
60+
portArgs.AddToCommand(monitorCommand)
61+
monitorCommand.Flags().BoolVar(&describe, "describe", false, tr("Show all the settings of the communication port."))
62+
monitorCommand.Flags().StringSliceVarP(&configs, "config", "c", []string{}, tr("Configuration of the port."))
63+
monitorCommand.Flags().BoolVarP(&quiet, "quiet", "q", false, tr("Run in silent mode, show only monitor input and output."))
64+
fqbn.AddToCommand(monitorCommand)
65+
monitorCommand.MarkFlagRequired("port")
66+
return monitorCommand
6967
}
7068

7169
func runMonitorCmd(cmd *cobra.Command, args []string) {
@@ -84,7 +82,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
8482
enumerateResp, err := monitor.EnumerateMonitorPortSettings(context.Background(), &rpc.EnumerateMonitorPortSettingsRequest{
8583
Instance: instance,
8684
PortProtocol: portProtocol,
87-
Fqbn: fqbn,
85+
Fqbn: fqbn.String(),
8886
})
8987
if err != nil {
9088
feedback.Error(tr("Error getting port settings details: %s", err))
@@ -148,7 +146,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
148146
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorRequest{
149147
Instance: instance,
150148
Port: &rpc.Port{Address: portAddress, Protocol: portProtocol},
151-
Fqbn: fqbn,
149+
Fqbn: fqbn.String(),
152150
PortConfiguration: configuration,
153151
})
154152
if err != nil {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /