Skip to content

Commit e85b21c

Browse files
Add profile flag to debug command
1 parent 032be41 commit e85b21c

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

Diff for: internal/cli/debug/debug.go

+26-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func NewCommand() *cobra.Command {
4343
var (
4444
fqbnArg arguments.Fqbn
4545
portArgs arguments.Port
46+
profileArg arguments.Profile
4647
interpreter string
4748
importDir string
4849
printInfo bool
@@ -56,14 +57,15 @@ func NewCommand() *cobra.Command {
5657
Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch",
5758
Args: cobra.MaximumNArgs(1),
5859
Run: func(cmd *cobra.Command, args []string) {
59-
runDebugCommand(args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo)
60+
runDebugCommand(args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo, &profileArg)
6061
},
6162
}
6263

6364
debugCommand.AddCommand(newDebugCheckCommand())
6465
fqbnArg.AddToCommand(debugCommand)
6566
portArgs.AddToCommand(debugCommand)
6667
programmer.AddToCommand(debugCommand)
68+
profileArg.AddToCommand(debugCommand)
6769
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
6870
debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries for debug."))
6971
debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, tr("Show metadata about the debug session instead of starting the debugger."))
@@ -72,8 +74,7 @@ func NewCommand() *cobra.Command {
7274
}
7375

7476
func runDebugCommand(args []string, portArgs *arguments.Port, fqbnArg *arguments.Fqbn,
75-
interpreter string, importDir string, programmer *arguments.Programmer, printInfo bool) {
76-
instance := instance.CreateAndInit()
77+
interpreter string, importDir string, programmer *arguments.Programmer, printInfo bool, profileArg *arguments.Profile) {
7778
logrus.Info("Executing `arduino-cli debug`")
7879

7980
path := ""
@@ -88,15 +89,34 @@ func runDebugCommand(args []string, portArgs *arguments.Port, fqbnArg *arguments
8889
}
8990
feedback.WarnAboutDeprecatedFiles(sk)
9091

91-
fqbn, port := arguments.CalculateFQBNAndPort(portArgs, fqbnArg, instance, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
92+
var inst *rpc.Instance
93+
var profile *rpc.Profile
94+
95+
if profileArg.Get() == "" {
96+
inst, profile = instance.CreateAndInitWithProfile(sk.GetDefaultProfile().GetName(), sketchPath)
97+
} else {
98+
inst, profile = instance.CreateAndInitWithProfile(profileArg.Get(), sketchPath)
99+
}
100+
101+
if fqbnArg.String() == "" {
102+
fqbnArg.Set(profile.GetFqbn())
103+
}
104+
105+
fqbn, port := arguments.CalculateFQBNAndPort(portArgs, fqbnArg, inst, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
106+
107+
prog := profile.GetProgrammer()
108+
if prog == "" || programmer.GetProgrammer() != "" {
109+
prog = programmer.String(inst, fqbn)
110+
}
111+
92112
debugConfigRequested := &rpc.GetDebugConfigRequest{
93-
Instance: instance,
113+
Instance: inst,
94114
Fqbn: fqbn,
95115
SketchPath: sketchPath.String(),
96116
Port: port,
97117
Interpreter: interpreter,
98118
ImportDir: importDir,
99-
Programmer: programmer.String(instance, fqbn),
119+
Programmer: prog,
100120
}
101121

102122
if printInfo {

0 commit comments

Comments
 (0)