Skip to content

Commit

Permalink
remove sketch flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Oct 18, 2023
1 parent 41c4c56 commit c0704e7
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions internal/cli/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ var tr = i18n.Tr
// NewCommand created a new `monitor` command
func NewCommand() *cobra.Command {
var (
raw bool
portArgs arguments.Port
describe bool
configs []string
quiet bool
timestamp bool
fqbn arguments.Fqbn
sketchPath string
raw bool
portArgs arguments.Port
describe bool
configs []string
quiet bool
timestamp bool
fqbn arguments.Fqbn
)
monitorCommand := &cobra.Command{
Use: "monitor",
Expand All @@ -63,7 +62,11 @@ func NewCommand() *cobra.Command {
" " + os.Args[0] + " monitor -p /dev/ttyACM0\n" +
" " + os.Args[0] + " monitor -p /dev/ttyACM0 --describe",
Run: func(cmd *cobra.Command, args []string) {
runMonitorCmd(&portArgs, &fqbn, configs, describe, timestamp, quiet, raw, sketchPath)
var portProvidedFromFlag bool
if p := cmd.Flags().Lookup("port"); p != nil && p.Changed {
portProvidedFromFlag = true
}
runMonitorCmd(&portArgs, &fqbn, configs, describe, timestamp, quiet, raw, portProvidedFromFlag)
},
}
portArgs.AddToCommand(monitorCommand)
Expand All @@ -72,34 +75,33 @@ func NewCommand() *cobra.Command {
monitorCommand.Flags().StringSliceVarP(&configs, "config", "c", []string{}, tr("Configure communication port settings. The format is <ID>=<value>[,<ID>=<value>]..."))
monitorCommand.Flags().BoolVarP(&quiet, "quiet", "q", false, tr("Run in silent mode, show only monitor input and output."))
monitorCommand.Flags().BoolVar(&timestamp, "timestamp", false, tr("Timestamp each incoming line."))
monitorCommand.Flags().StringVarP(&sketchPath, "sketch", "s", "", tr("Path to the sketch"))
fqbn.AddToCommand(monitorCommand)
return monitorCommand
}

func runMonitorCmd(portArgs *arguments.Port, fqbn *arguments.Fqbn, configs []string, describe, timestamp, quiet, raw bool, sketchPath string) {
func runMonitorCmd(portArgs *arguments.Port, fqbn *arguments.Fqbn, configs []string, describe, timestamp, quiet, raw, portProvidedFromFlag bool) {
instance := instance.CreateAndInit()
logrus.Info("Executing `arduino-cli monitor`")

if !configuration.HasConsole {
quiet = true
}

addressDefault := ""
protocolDefault := ""
if sketchPath != "" {
sketch, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath})
var defaultPortAddress, defaultPortProtocol string
if !portProvidedFromFlag {
sketchReponse, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{
SketchPath: arguments.InitSketchPath("").String(),
})
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
feedback.Fatal(tr("Error getting default port from `sketch.yaml`. Check if you're in the correct sketch folder or provide the --port flag: %s", err), feedback.ErrGeneric)
}
addressDefault = sketch.GetDefaultPort()
protocolDefault = sketch.GetDefaultProtocol()
defaultPortAddress, defaultPortProtocol = sketchReponse.GetDefaultPort(), sketchReponse.GetDefaultProtocol()
}
portAddress, portProtocol, err := portArgs.GetPortAddressAndProtocol(instance, addressDefault, protocolDefault)

portAddress, portProtocol, err := portArgs.GetPortAddressAndProtocol(instance, defaultPortAddress, defaultPortProtocol)
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
}

enumerateResp, err := monitor.EnumerateMonitorPortSettings(context.Background(), &rpc.EnumerateMonitorPortSettingsRequest{
Instance: instance,
PortProtocol: portProtocol,
Expand Down

0 comments on commit c0704e7

Please sign in to comment.