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 ( ...@@ -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 {
cmd := &cobra.Command{ monitorCommand := &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 {
......
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