Skip to content

Commit 79891ff

Browse files
committed
refactor monitor command to be consistent with other commands
1 parent f6760b3 commit 79891ff

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

cli/monitor/monitor.go

+18-20
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.GetFQBN(),
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.GetFQBN(),
152150
PortConfiguration: configuration,
153151
})
154152
if err != nil {

i18n/data/en.po

+16-17
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ msgstr "Config file already exists, use --overwrite to discard the existing one.
411411
msgid "Config file written to: %s"
412412
msgstr "Config file written to: %s"
413413

414-
#: cli/monitor/monitor.go:61
414+
#: cli/monitor/monitor.go:63
415415
msgid "Configuration of the port."
416416
msgstr "Configuration of the port."
417417

@@ -431,7 +431,7 @@ msgstr "Configuring platform."
431431
msgid "Connected"
432432
msgstr "Connected"
433433

434-
#: cli/monitor/monitor.go:177
434+
#: cli/monitor/monitor.go:176
435435
msgid "Connected to %s! Press CTRL-C to exit."
436436
msgstr "Connected to %s! Press CTRL-C to exit."
437437

@@ -504,7 +504,7 @@ msgstr "Debugging not supported for board %s"
504504
msgid "Debugging supported:"
505505
msgstr "Debugging supported:"
506506

507-
#: cli/monitor/monitor.go:195
507+
#: cli/monitor/monitor.go:194
508508
msgid "Default"
509509
msgstr "Default"
510510

@@ -787,7 +787,7 @@ msgstr "Error getting information for library %s"
787787
msgid "Error getting libraries info: %v"
788788
msgstr "Error getting libraries info: %v"
789789

790-
#: cli/monitor/monitor.go:90
790+
#: cli/monitor/monitor.go:89
791791
msgid "Error getting port settings details: %s"
792792
msgstr "Error getting port settings details: %s"
793793

@@ -1083,7 +1083,6 @@ msgid "Force skip of post-install scripts (if the CLI is running interactively).
10831083
msgstr "Force skip of post-install scripts (if the CLI is running interactively)."
10841084

10851085
#: cli/arguments/port.go:80
1086-
#: cli/monitor/monitor.go:63
10871086
msgid "Fully Qualified Board Name, e.g.: arduino:avr:uno"
10881087
msgstr "Fully Qualified Board Name, e.g.: arduino:avr:uno"
10891088

@@ -1130,7 +1129,7 @@ msgstr "Global variables use {0} bytes of dynamic memory."
11301129

11311130
#: cli/core/list.go:84
11321131
#: cli/core/search.go:114
1133-
#: cli/monitor/monitor.go:195
1132+
#: cli/monitor/monitor.go:194
11341133
#: cli/outdated/outdated.go:62
11351134
msgid "ID"
11361135
msgstr "ID"
@@ -1471,7 +1470,7 @@ msgstr "Missing sketch path"
14711470
msgid "Monitor '%s' not found"
14721471
msgstr "Monitor '%s' not found"
14731472

1474-
#: cli/monitor/monitor.go:143
1473+
#: cli/monitor/monitor.go:142
14751474
msgid "Monitor port settings:"
14761475
msgstr "Monitor port settings:"
14771476

@@ -1576,8 +1575,8 @@ msgstr "OS:"
15761575
msgid "Official Arduino board:"
15771576
msgstr "Official Arduino board:"
15781577

1579-
#: cli/monitor/monitor.go:52
1580-
#: cli/monitor/monitor.go:53
1578+
#: cli/monitor/monitor.go:54
1579+
#: cli/monitor/monitor.go:55
15811580
msgid "Open a communication port with a board."
15821581
msgstr "Open a communication port with a board."
15831582

@@ -1722,8 +1721,8 @@ msgstr "Platform size (bytes):"
17221721
msgid "Port"
17231722
msgstr "Port"
17241723

1725-
#: cli/monitor/monitor.go:164
1726-
#: cli/monitor/monitor.go:171
1724+
#: cli/monitor/monitor.go:163
1725+
#: cli/monitor/monitor.go:170
17271726
msgid "Port closed:"
17281727
msgstr "Port closed:"
17291728

@@ -1802,7 +1801,7 @@ msgstr "Required tool:"
18021801
msgid "Run as a daemon on port: %s"
18031802
msgstr "Run as a daemon on port: %s"
18041803

1805-
#: cli/monitor/monitor.go:62
1804+
#: cli/monitor/monitor.go:64
18061805
msgid "Run in silent mode, show only monitor input and output."
18071806
msgstr "Run in silent mode, show only monitor input and output."
18081807

@@ -1860,7 +1859,7 @@ msgstr "Sets a setting value."
18601859
msgid "Sets where to save the configuration file."
18611860
msgstr "Sets where to save the configuration file."
18621861

1863-
#: cli/monitor/monitor.go:195
1862+
#: cli/monitor/monitor.go:194
18641863
msgid "Setting"
18651864
msgstr "Setting"
18661865

@@ -1877,7 +1876,7 @@ msgstr "Show all available core versions."
18771876
msgid "Show all build properties used instead of compiling."
18781877
msgstr "Show all build properties used instead of compiling."
18791878

1880-
#: cli/monitor/monitor.go:60
1879+
#: cli/monitor/monitor.go:62
18811880
msgid "Show all the settings of the communication port."
18821881
msgstr "Show all the settings of the communication port."
18831882

@@ -2324,7 +2323,7 @@ msgstr "VERSION"
23242323
msgid "VERSION_NUMBER"
23252324
msgstr "VERSION_NUMBER"
23262325

2327-
#: cli/monitor/monitor.go:195
2326+
#: cli/monitor/monitor.go:194
23282327
msgid "Values"
23292328
msgstr "Values"
23302329

@@ -2827,11 +2826,11 @@ msgstr "invalid platform archive size: %s"
28272826
msgid "invalid pluggable monitor reference: %s"
28282827
msgstr "invalid pluggable monitor reference: %s"
28292828

2830-
#: cli/monitor/monitor.go:126
2829+
#: cli/monitor/monitor.go:125
28312830
msgid "invalid port configuration value for %s: %s"
28322831
msgstr "invalid port configuration value for %s: %s"
28332832

2834-
#: cli/monitor/monitor.go:135
2833+
#: cli/monitor/monitor.go:134
28352834
msgid "invalid port configuration: %s"
28362835
msgstr "invalid port configuration: %s"
28372836

0 commit comments

Comments
 (0)