Skip to content

Commit

Permalink
refactor debug command and use code from arguments, remove useless vars
Browse files Browse the repository at this point in the history
  • Loading branch information
umbynos committed Nov 19, 2021
1 parent 8394280 commit 06e96b9
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ import (
)

var (
fqbn string
fqbn arguments.Fqbn
port arguments.Port
verbose bool
verify bool
interpreter string
importDir string
printInfo bool
programmer string
programmer arguments.Programmer
tr = i18n.Tr
)

Expand All @@ -54,26 +52,20 @@ func NewCommand() *cobra.Command {
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",
Args: cobra.MaximumNArgs(1),
Run: run,
Run: runDebugCommand,
}

debugCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
debugCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
})
fqbn.AddToCommand(debugCommand)
port.AddToCommand(debugCommand)
debugCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Programmer to use for debugging"))
debugCommand.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
})
programmer.AddToCommand(debugCommand)
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().BoolVarP(&printInfo, "info", "I", false, tr("Show metadata about the debug session instead of starting the debugger."))

return debugCommand
}

func run(command *cobra.Command, args []string) {
func runDebugCommand(command *cobra.Command, args []string) {
instance := instance.CreateAndInit()

path := ""
Expand All @@ -87,12 +79,12 @@ func run(command *cobra.Command, args []string) {

debugConfigRequested := &dbg.DebugConfigRequest{
Instance: instance,
Fqbn: fqbn,
Fqbn: fqbn.String(),
SketchPath: sketchPath.String(),
Port: discoveryPort.ToRPC(),
Interpreter: interpreter,
ImportDir: importDir,
Programmer: programmer,
Programmer: programmer.String(),
}

if printInfo {
Expand Down

0 comments on commit 06e96b9

Please sign in to comment.