Skip to content

Commit 867e6c9

Browse files
committed
Made debug flags var non-global
1 parent b57d91b commit 867e6c9

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

internal/cli/debug/debug.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,28 @@ import (
3636
"github.com/spf13/cobra"
3737
)
3838

39-
var (
40-
fqbnArg arguments.Fqbn
41-
portArgs arguments.Port
42-
interpreter string
43-
importDir string
44-
printInfo bool
45-
programmer arguments.Programmer
46-
tr = i18n.Tr
47-
)
39+
var tr = i18n.Tr
4840

4941
// NewCommand created a new `upload` command
5042
func NewCommand() *cobra.Command {
43+
var (
44+
fqbnArg arguments.Fqbn
45+
portArgs arguments.Port
46+
interpreter string
47+
importDir string
48+
printInfo bool
49+
programmer arguments.Programmer
50+
)
51+
5152
debugCommand := &cobra.Command{
5253
Use: "debug",
5354
Short: tr("Debug Arduino sketches."),
5455
Long: tr("Debug Arduino sketches. (this command opens an interactive gdb session)"),
5556
Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch",
5657
Args: cobra.MaximumNArgs(1),
57-
Run: runDebugCommand,
58+
Run: func(cmd *cobra.Command, args []string) {
59+
runDebugCommand(args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo)
60+
},
5861
}
5962

6063
fqbnArg.AddToCommand(debugCommand)
@@ -67,7 +70,8 @@ func NewCommand() *cobra.Command {
6770
return debugCommand
6871
}
6972

70-
func runDebugCommand(command *cobra.Command, args []string) {
73+
func runDebugCommand(args []string, portArgs *arguments.Port, fqbnArg *arguments.Fqbn,
74+
interpreter string, importDir string, programmer *arguments.Programmer, printInfo bool) {
7175
instance := instance.CreateAndInit()
7276
logrus.Info("Executing `arduino-cli debug`")
7377

@@ -81,7 +85,7 @@ func runDebugCommand(command *cobra.Command, args []string) {
8185
if err != nil {
8286
feedback.FatalError(err, feedback.ErrGeneric)
8387
}
84-
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, instance, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
88+
fqbn, port := arguments.CalculateFQBNAndPort(portArgs, fqbnArg, instance, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
8589
debugConfigRequested := &rpc.GetDebugConfigRequest{
8690
Instance: instance,
8791
Fqbn: fqbn,

0 commit comments

Comments
 (0)