Commit 06e96b9a authored by Umberto Baldi's avatar Umberto Baldi

refactor debug command and use code from arguments, remove useless vars

parent 83942801
...@@ -35,14 +35,12 @@ import ( ...@@ -35,14 +35,12 @@ import (
) )
var ( var (
fqbn string fqbn arguments.Fqbn
port arguments.Port port arguments.Port
verbose bool
verify bool
interpreter string interpreter string
importDir string importDir string
printInfo bool printInfo bool
programmer string programmer arguments.Programmer
tr = i18n.Tr tr = i18n.Tr
) )
...@@ -54,18 +52,12 @@ func NewCommand() *cobra.Command { ...@@ -54,18 +52,12 @@ func NewCommand() *cobra.Command {
Long: tr("Debug Arduino sketches. (this command opens an interactive gdb session)"), Long: tr("Debug Arduino sketches. (this command opens an interactive gdb session)"),
Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch", Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch",
Args: cobra.MaximumNArgs(1), Args: cobra.MaximumNArgs(1),
Run: run, Run: runDebugCommand,
} }
debugCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno")) fqbn.AddToCommand(debugCommand)
debugCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
})
port.AddToCommand(debugCommand) port.AddToCommand(debugCommand)
debugCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Programmer to use for debugging")) programmer.AddToCommand(debugCommand)
debugCommand.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
})
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3")) debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries for debug.")) debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries for debug."))
debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, tr("Show metadata about the debug session instead of starting the debugger.")) debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, tr("Show metadata about the debug session instead of starting the debugger."))
...@@ -73,7 +65,7 @@ func NewCommand() *cobra.Command { ...@@ -73,7 +65,7 @@ func NewCommand() *cobra.Command {
return debugCommand return debugCommand
} }
func run(command *cobra.Command, args []string) { func runDebugCommand(command *cobra.Command, args []string) {
instance := instance.CreateAndInit() instance := instance.CreateAndInit()
path := "" path := ""
...@@ -87,12 +79,12 @@ func run(command *cobra.Command, args []string) { ...@@ -87,12 +79,12 @@ func run(command *cobra.Command, args []string) {
debugConfigRequested := &dbg.DebugConfigRequest{ debugConfigRequested := &dbg.DebugConfigRequest{
Instance: instance, Instance: instance,
Fqbn: fqbn, Fqbn: fqbn.String(),
SketchPath: sketchPath.String(), SketchPath: sketchPath.String(),
Port: discoveryPort.ToRPC(), Port: discoveryPort.ToRPC(),
Interpreter: interpreter, Interpreter: interpreter,
ImportDir: importDir, ImportDir: importDir,
Programmer: programmer, Programmer: programmer.String(),
} }
if printInfo { if printInfo {
......
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