Skip to content

Commit 60ff290

Browse files
committed
refactor debug command and use code from arguments, remove useless vars
1 parent 0e8bd9e commit 60ff290

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

cli/debug/debug.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ import (
3535
)
3636

3737
var (
38-
fqbn string
38+
fqbn arguments.Fqbn
3939
port arguments.Port
40-
verbose bool
41-
verify bool
4240
interpreter string
4341
importDir string
4442
printInfo bool
45-
programmer string
43+
programmer arguments.Programmer
4644
tr = i18n.Tr
4745
)
4846

@@ -54,26 +52,20 @@ func NewCommand() *cobra.Command {
5452
Long: tr("Debug Arduino sketches. (this command opens an interactive gdb session)"),
5553
Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch",
5654
Args: cobra.MaximumNArgs(1),
57-
Run: run,
55+
Run: runDebugCommand,
5856
}
5957

60-
debugCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
61-
debugCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
62-
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
63-
})
58+
fqbn.AddToCommand(debugCommand)
6459
port.AddToCommand(debugCommand)
65-
debugCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Programmer to use for debugging"))
66-
debugCommand.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
67-
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
68-
})
60+
programmer.AddToCommand(debugCommand)
6961
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
7062
debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries for debug."))
7163
debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, tr("Show metadata about the debug session instead of starting the debugger."))
7264

7365
return debugCommand
7466
}
7567

76-
func run(command *cobra.Command, args []string) {
68+
func runDebugCommand(command *cobra.Command, args []string) {
7769
instance := instance.CreateAndInit()
7870

7971
path := ""
@@ -83,12 +75,12 @@ func run(command *cobra.Command, args []string) {
8375
sketchPath, _, discoveryPort := arguments.SketchPathCalculation(path, port, instance, false)
8476
debugConfigRequested := &dbg.DebugConfigRequest{
8577
Instance: instance,
86-
Fqbn: fqbn,
78+
Fqbn: fqbn.GetFQBN(),
8779
SketchPath: sketchPath.String(),
8880
Port: discoveryPort.ToRPC(),
8981
Interpreter: interpreter,
9082
ImportDir: importDir,
91-
Programmer: programmer,
83+
Programmer: programmer.GetProgrammer(),
9284
}
9385

9486
if printInfo {

i18n/data/en.po

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ msgstr "Config file written to: %s"
415415
msgid "Configuration of the port."
416416
msgstr "Configuration of the port."
417417

418-
#: cli/debug/debug.go:148
418+
#: cli/debug/debug.go:140
419419
msgid "Configuration options for %s"
420420
msgstr "Configuration options for %s"
421421

@@ -484,15 +484,15 @@ msgstr "Creates or updates the configuration file in the data directory or custo
484484
msgid "DEPRECATED"
485485
msgstr "DEPRECATED"
486486

487-
#: cli/debug/debug.go:53
487+
#: cli/debug/debug.go:51
488488
msgid "Debug Arduino sketches."
489489
msgstr "Debug Arduino sketches."
490490

491-
#: cli/debug/debug.go:54
491+
#: cli/debug/debug.go:52
492492
msgid "Debug Arduino sketches. (this command opens an interactive gdb session)"
493493
msgstr "Debug Arduino sketches. (this command opens an interactive gdb session)"
494494

495-
#: cli/debug/debug.go:69
495+
#: cli/debug/debug.go:61
496496
msgid "Debug interpreter e.g.: %s"
497497
msgstr "Debug interpreter e.g.: %s"
498498

@@ -541,7 +541,7 @@ msgstr "Detecting libraries used..."
541541
msgid "Detects and displays a list of boards connected to the current computer."
542542
msgstr "Detects and displays a list of boards connected to the current computer."
543543

544-
#: cli/debug/debug.go:70
544+
#: cli/debug/debug.go:62
545545
msgid "Directory containing binaries for debug."
546546
msgstr "Directory containing binaries for debug."
547547

@@ -715,7 +715,7 @@ msgstr "Error downloading platform %s"
715715
msgid "Error downloading tool %s"
716716
msgstr "Error downloading tool %s"
717717

718-
#: cli/debug/debug.go:110
718+
#: cli/debug/debug.go:102
719719
msgid "Error during Debug: %v"
720720
msgstr "Error during Debug: %v"
721721

@@ -756,7 +756,7 @@ msgstr "Error extracting library_index.json.gz"
756756
msgid "Error finding build artifacts"
757757
msgstr "Error finding build artifacts"
758758

759-
#: cli/debug/debug.go:97
759+
#: cli/debug/debug.go:89
760760
msgid "Error getting Debug info: %v"
761761
msgstr "Error getting Debug info: %v"
762762

@@ -1000,7 +1000,7 @@ msgstr "Examples for library %s"
10001000
msgid "Examples:"
10011001
msgstr "Examples:"
10021002

1003-
#: cli/debug/debug.go:129
1003+
#: cli/debug/debug.go:121
10041004
msgid "Executable to debug"
10051005
msgstr "Executable to debug"
10061006

@@ -1087,16 +1087,15 @@ msgid "Force skip of post-install scripts (if the CLI is running interactively).
10871087
msgstr "Force skip of post-install scripts (if the CLI is running interactively)."
10881088

10891089
#: cli/arguments/port.go:80
1090-
#: cli/debug/debug.go:60
10911090
#: cli/monitor/monitor.go:63
10921091
msgid "Fully Qualified Board Name, e.g.: arduino:avr:uno"
10931092
msgstr "Fully Qualified Board Name, e.g.: arduino:avr:uno"
10941093

1095-
#: cli/debug/debug.go:143
1094+
#: cli/debug/debug.go:135
10961095
msgid "GDB Server path"
10971096
msgstr "GDB Server path"
10981097

1099-
#: cli/debug/debug.go:142
1098+
#: cli/debug/debug.go:134
11001099
msgid "GDB Server type"
11011100
msgstr "GDB Server type"
11021101

@@ -1769,10 +1768,6 @@ msgstr "Programmer '%s' not found"
17691768
msgid "Programmer name"
17701769
msgstr "Programmer name"
17711770

1772-
#: cli/debug/debug.go:65
1773-
msgid "Programmer to use for debugging"
1774-
msgstr "Programmer to use for debugging"
1775-
17761771
#: cli/board/details.go:195
17771772
msgid "Programmers:"
17781773
msgstr "Programmers:"
@@ -1916,7 +1911,7 @@ msgstr "Show library names only."
19161911
msgid "Show list of available programmers"
19171912
msgstr "Show list of available programmers"
19181913

1919-
#: cli/debug/debug.go:71
1914+
#: cli/debug/debug.go:63
19201915
msgid "Show metadata about the debug session instead of starting the debugger."
19211916
msgstr "Show metadata about the debug session instead of starting the debugger."
19221917

@@ -2082,19 +2077,19 @@ msgstr "Tool %s uninstalled"
20822077
msgid "Toolchain '%s' is not supported"
20832078
msgstr "Toolchain '%s' is not supported"
20842079

2085-
#: cli/debug/debug.go:137
2080+
#: cli/debug/debug.go:129
20862081
msgid "Toolchain custom configurations"
20872082
msgstr "Toolchain custom configurations"
20882083

2089-
#: cli/debug/debug.go:131
2084+
#: cli/debug/debug.go:123
20902085
msgid "Toolchain path"
20912086
msgstr "Toolchain path"
20922087

2093-
#: cli/debug/debug.go:132
2088+
#: cli/debug/debug.go:124
20942089
msgid "Toolchain prefix"
20952090
msgstr "Toolchain prefix"
20962091

2097-
#: cli/debug/debug.go:130
2092+
#: cli/debug/debug.go:122
20982093
msgid "Toolchain type"
20992094
msgstr "Toolchain type"
21002095

0 commit comments

Comments
 (0)