Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
aeb15287
Commit
aeb15287
authored
Nov 18, 2021
by
Umberto Baldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor monitor command to be consistent with other commands
parent
0f259643
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
20 deletions
+18
-20
cli/monitor/monitor.go
cli/monitor/monitor.go
+18
-20
No files found.
cli/monitor/monitor.go
View file @
aeb15287
...
@@ -37,17 +37,18 @@ import (
...
@@ -37,17 +37,18 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
var
tr
=
i18n
.
Tr
var
(
portArgs
arguments
.
Port
var
portArgs
arguments
.
Port
describe
bool
var
describe
bool
configs
[]
string
var
configs
[]
string
quiet
bool
var
quiet
bool
fqbn
arguments
.
Fqbn
var
fqbn
string
tr
=
i18n
.
Tr
)
// NewCommand created a new `monitor` command
// NewCommand created a new `monitor` command
func
NewCommand
()
*
cobra
.
Command
{
func
NewCommand
()
*
cobra
.
Command
{
cm
d
:=
&
cobra
.
Command
{
monitorComman
d
:=
&
cobra
.
Command
{
Use
:
"monitor"
,
Use
:
"monitor"
,
Short
:
tr
(
"Open a communication port with a board."
),
Short
:
tr
(
"Open a communication port with a board."
),
Long
:
tr
(
"Open a communication port with a board."
),
Long
:
tr
(
"Open a communication port with a board."
),
...
@@ -56,16 +57,13 @@ func NewCommand() *cobra.Command {
...
@@ -56,16 +57,13 @@ func NewCommand() *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" monitor -p /dev/ttyACM0 --describe"
,
" "
+
os
.
Args
[
0
]
+
" monitor -p /dev/ttyACM0 --describe"
,
Run
:
runMonitorCmd
,
Run
:
runMonitorCmd
,
}
}
portArgs
.
AddToCommand
(
cmd
)
portArgs
.
AddToCommand
(
monitorCommand
)
cmd
.
Flags
()
.
BoolVar
(
&
describe
,
"describe"
,
false
,
tr
(
"Show all the settings of the communication port."
))
monitorCommand
.
Flags
()
.
BoolVar
(
&
describe
,
"describe"
,
false
,
tr
(
"Show all the settings of the communication port."
))
cmd
.
Flags
()
.
StringSliceVarP
(
&
configs
,
"config"
,
"c"
,
[]
string
{},
tr
(
"Configuration of the port."
))
monitorCommand
.
Flags
()
.
StringSliceVarP
(
&
configs
,
"config"
,
"c"
,
[]
string
{},
tr
(
"Configuration of the port."
))
cmd
.
Flags
()
.
BoolVarP
(
&
quiet
,
"quiet"
,
"q"
,
false
,
tr
(
"Run in silent mode, show only monitor input and output."
))
monitorCommand
.
Flags
()
.
BoolVarP
(
&
quiet
,
"quiet"
,
"q"
,
false
,
tr
(
"Run in silent mode, show only monitor input and output."
))
cmd
.
Flags
()
.
StringVarP
(
&
fqbn
,
"fqbn"
,
"b"
,
""
,
tr
(
"Fully Qualified Board Name, e.g.: arduino:avr:uno"
))
fqbn
.
AddToCommand
(
monitorCommand
)
cmd
.
RegisterFlagCompletionFunc
(
"fqbn"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
monitorCommand
.
MarkFlagRequired
(
"port"
)
return
arguments
.
GetInstalledBoards
(),
cobra
.
ShellCompDirectiveDefault
return
monitorCommand
})
cmd
.
MarkFlagRequired
(
"port"
)
return
cmd
}
}
func
runMonitorCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
runMonitorCmd
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
@@ -84,7 +82,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
...
@@ -84,7 +82,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
enumerateResp
,
err
:=
monitor
.
EnumerateMonitorPortSettings
(
context
.
Background
(),
&
rpc
.
EnumerateMonitorPortSettingsRequest
{
enumerateResp
,
err
:=
monitor
.
EnumerateMonitorPortSettings
(
context
.
Background
(),
&
rpc
.
EnumerateMonitorPortSettingsRequest
{
Instance
:
instance
,
Instance
:
instance
,
PortProtocol
:
portProtocol
,
PortProtocol
:
portProtocol
,
Fqbn
:
fqbn
,
Fqbn
:
fqbn
.
String
()
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
feedback
.
Error
(
tr
(
"Error getting port settings details: %s"
,
err
))
feedback
.
Error
(
tr
(
"Error getting port settings details: %s"
,
err
))
...
@@ -148,7 +146,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
...
@@ -148,7 +146,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
portProxy
,
_
,
err
:=
monitor
.
Monitor
(
context
.
Background
(),
&
rpc
.
MonitorRequest
{
portProxy
,
_
,
err
:=
monitor
.
Monitor
(
context
.
Background
(),
&
rpc
.
MonitorRequest
{
Instance
:
instance
,
Instance
:
instance
,
Port
:
&
rpc
.
Port
{
Address
:
portAddress
,
Protocol
:
portProtocol
},
Port
:
&
rpc
.
Port
{
Address
:
portAddress
,
Protocol
:
portProtocol
},
Fqbn
:
fqbn
,
Fqbn
:
fqbn
.
String
()
,
PortConfiguration
:
configuration
,
PortConfiguration
:
configuration
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment