Commit aeb15287 authored by Umberto Baldi's avatar Umberto Baldi

refactor monitor command to be consistent with other commands

parent 0f259643
......@@ -37,17 +37,18 @@ import (
"github.com/spf13/cobra"
)
var tr = i18n.Tr
var portArgs arguments.Port
var describe bool
var configs []string
var quiet bool
var fqbn string
var (
portArgs arguments.Port
describe bool
configs []string
quiet bool
fqbn arguments.Fqbn
tr = i18n.Tr
)
// NewCommand created a new `monitor` command
func NewCommand() *cobra.Command {
cmd := &cobra.Command{
monitorCommand := &cobra.Command{
Use: "monitor",
Short: 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 {
" " + os.Args[0] + " monitor -p /dev/ttyACM0 --describe",
Run: runMonitorCmd,
}
portArgs.AddToCommand(cmd)
cmd.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."))
cmd.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"))
cmd.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
})
cmd.MarkFlagRequired("port")
return cmd
portArgs.AddToCommand(monitorCommand)
monitorCommand.Flags().BoolVar(&describe, "describe", false, tr("Show all the settings of the communication port."))
monitorCommand.Flags().StringSliceVarP(&configs, "config", "c", []string{}, tr("Configuration of the port."))
monitorCommand.Flags().BoolVarP(&quiet, "quiet", "q", false, tr("Run in silent mode, show only monitor input and output."))
fqbn.AddToCommand(monitorCommand)
monitorCommand.MarkFlagRequired("port")
return monitorCommand
}
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{
Instance: instance,
PortProtocol: portProtocol,
Fqbn: fqbn,
Fqbn: fqbn.String(),
})
if err != nil {
feedback.Error(tr("Error getting port settings details: %s", err))
......@@ -148,7 +146,7 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorRequest{
Instance: instance,
Port: &rpc.Port{Address: portAddress, Protocol: portProtocol},
Fqbn: fqbn,
Fqbn: fqbn.String(),
PortConfiguration: configuration,
})
if err != nil {
......
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