Skip to content

[pluggable monitor] add --silent and --config flags #1497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 78 additions & 4 deletions cli/monitor/monitor.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ package monitor
import (
"context"
"errors"
"fmt"
"io"
"os"
"sort"
@@ -28,6 +29,7 @@ import (
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/monitor"
"github.com/arduino/arduino-cli/configuration"
"github.com/arduino/arduino-cli/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/table"
@@ -39,6 +41,8 @@ var tr = i18n.Tr

var portArgs arguments.Port
var describe bool
var configs []string
var silent bool

// NewCommand created a new `monitor` command
func NewCommand() *cobra.Command {
@@ -53,13 +57,19 @@ func NewCommand() *cobra.Command {
}
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(&silent, "silent", "s", false, tr("Run in silent mode, show only monitor input and output."))
cmd.MarkFlagRequired("port")
return cmd
}

func runMonitorCmd(cmd *cobra.Command, args []string) {
instance := instance.CreateAndInit()

if !configuration.HasConsole {
silent = true
}

port, err := portArgs.GetPort(instance, nil)
if err != nil {
feedback.Error(err)
@@ -87,10 +97,63 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
}
defer tty.Close()

configuration := &rpc.MonitorPortConfiguration{}
if len(configs) > 0 {
resp, err := monitor.EnumerateMonitorPortSettings(context.Background(), &rpc.EnumerateMonitorPortSettingsRequest{
Instance: instance,
Port: port.ToRPC(),
Fqbn: "",
})
if err != nil {
feedback.Error(err)
os.Exit(errorcodes.ErrGeneric)
}
settings := resp.GetSettings()
for _, config := range configs {
split := strings.SplitN(config, "=", 2)
k := ""
v := config
if len(split) == 2 {
k = split[0]
v = split[1]
}

var setting *rpc.MonitorPortSettingDescriptor
for _, s := range settings {
if k == "" {
if contains(s.EnumValues, v) {
setting = s
break
}
} else {
if strings.EqualFold(s.SettingId, k) {
if !contains(s.EnumValues, v) {
feedback.Error(tr("invalid port configuration value for %s: %s", k, v))
os.Exit(errorcodes.ErrBadArgument)
}
setting = s
break
}
}
}
if setting == nil {
feedback.Error(tr("invalid port configuration: %s", config))
os.Exit(errorcodes.ErrBadArgument)
}
configuration.Settings = append(configuration.Settings, &rpc.MonitorPortSetting{
SettingId: setting.SettingId,
Value: v,
})
if !silent {
feedback.Print(fmt.Sprintf("Set %s to %s", setting.SettingId, v))
}
}
}
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorRequest{
Instance: instance,
Port: port.ToRPC(),
Fqbn: "",
Instance: instance,
Port: port.ToRPC(),
Fqbn: "",
PortConfiguration: configuration,
})
if err != nil {
feedback.Error(err)
@@ -114,7 +177,9 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
cancel()
}()

feedback.Print(tr("Connected to %s! Press CTRL-C to exit.", port.String()))
if !silent {
feedback.Print(tr("Connected to %s! Press CTRL-C to exit.", port.String()))
}

// Wait for port closed
<-ctx.Done()
@@ -141,3 +206,12 @@ func (r *detailsResult) String() string {
}
return t.Render()
}

func contains(s []string, searchterm string) bool {
for _, item := range s {
if strings.EqualFold(item, searchterm) {
return true
}
}
return false
}
38 changes: 27 additions & 11 deletions i18n/data/en.po
Original file line number Diff line number Diff line change
@@ -407,6 +407,10 @@ msgstr "Config file already exists, use --overwrite to discard the existing one.
msgid "Config file written to: %s"
msgstr "Config file written to: %s"

#: cli/monitor/monitor.go:60
msgid "Configuration of the port."
msgstr "Configuration of the port."

#: cli/debug/debug.go:153
msgid "Configuration options for %s"
msgstr "Configuration options for %s"
@@ -423,7 +427,7 @@ msgstr "Configuring platform."
msgid "Connected"
msgstr "Connected"

#: cli/monitor/monitor.go:117
#: cli/monitor/monitor.go:181
msgid "Connected to %s! Press CTRL-C to exit."
msgstr "Connected to %s! Press CTRL-C to exit."

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

#: cli/monitor/monitor.go:134
#: cli/monitor/monitor.go:199
msgid "Default"
msgstr "Default"

@@ -786,7 +790,7 @@ msgstr "Error getting information for library %s"
msgid "Error getting libraries info: %v"
msgstr "Error getting libraries info: %v"

#: cli/monitor/monitor.go:76
#: cli/monitor/monitor.go:86
msgid "Error getting port settings details: %s"
msgstr "Error getting port settings details: %s"

@@ -1134,7 +1138,7 @@ msgstr "Global variables use {0} bytes of dynamic memory."

#: cli/core/list.go:84
#: cli/core/search.go:114
#: cli/monitor/monitor.go:134
#: cli/monitor/monitor.go:199
#: cli/outdated/outdated.go:62
msgid "ID"
msgstr "ID"
@@ -1572,8 +1576,8 @@ msgstr "OS:"
msgid "Official Arduino board:"
msgstr "Official Arduino board:"

#: cli/monitor/monitor.go:47
#: cli/monitor/monitor.go:48
#: cli/monitor/monitor.go:51
#: cli/monitor/monitor.go:52
msgid "Open a communication port with a board."
msgstr "Open a communication port with a board."

@@ -1723,8 +1727,8 @@ msgstr "Platform size (bytes):"
msgid "Port"
msgstr "Port"

#: cli/monitor/monitor.go:105
#: cli/monitor/monitor.go:112
#: cli/monitor/monitor.go:168
#: cli/monitor/monitor.go:175
msgid "Port closed:"
msgstr "Port closed:"

@@ -1807,6 +1811,10 @@ msgstr "Required tool:"
msgid "Run as a daemon on port: %s"
msgstr "Run as a daemon on port: %s"

#: cli/monitor/monitor.go:61
msgid "Run in silent mode, show only monitor input and output."
msgstr "Run in silent mode, show only monitor input and output."

#: cli/daemon/daemon.go:51
msgid "Running as a daemon the initialization of cores and libraries is done only once."
msgstr "Running as a daemon the initialization of cores and libraries is done only once."
@@ -1861,7 +1869,7 @@ msgstr "Sets a setting value."
msgid "Sets where to save the configuration file."
msgstr "Sets where to save the configuration file."

#: cli/monitor/monitor.go:134
#: cli/monitor/monitor.go:199
msgid "Setting"
msgstr "Setting"

@@ -1878,7 +1886,7 @@ msgstr "Show all available core versions."
msgid "Show all build properties used instead of compiling."
msgstr "Show all build properties used instead of compiling."

#: cli/monitor/monitor.go:55
#: cli/monitor/monitor.go:59
msgid "Show all the settings of the communication port."
msgstr "Show all the settings of the communication port."

@@ -2336,7 +2344,7 @@ msgstr "VERSION"
msgid "VERSION_NUMBER"
msgstr "VERSION_NUMBER"

#: cli/monitor/monitor.go:134
#: cli/monitor/monitor.go:199
msgid "Values"
msgstr "Values"

@@ -2843,6 +2851,14 @@ msgstr "invalid platform archive size: %s"
msgid "invalid pluggable monitor reference: %s"
msgstr "invalid pluggable monitor reference: %s"

#: cli/monitor/monitor.go:131
msgid "invalid port configuration value for %s: %s"
msgstr "invalid port configuration value for %s: %s"

#: cli/monitor/monitor.go:140
msgid "invalid port configuration: %s"
msgstr "invalid port configuration: %s"

#: commands/upload/upload.go:483
msgid "invalid recipe '%[1]s': %[2]s"
msgstr "invalid recipe '%[1]s': %[2]s"
8 changes: 4 additions & 4 deletions i18n/rice-box.go

Large diffs are not rendered by default.