Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add profile flag to debug command
  • Loading branch information
MatteoPologruto committed Jan 18, 2024
commit e4668e74a7004930f707ec8dfd89fc4d9c25a64d
32 changes: 26 additions & 6 deletions internal/cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func NewCommand() *cobra.Command {
var (
fqbnArg arguments.Fqbn
portArgs arguments.Port
profileArg arguments.Profile
interpreter string
importDir string
printInfo bool
Expand All @@ -56,14 +57,15 @@ func NewCommand() *cobra.Command {
Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
runDebugCommand(args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo)
runDebugCommand(args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo, &profileArg)
},
}

debugCommand.AddCommand(newDebugCheckCommand())
fqbnArg.AddToCommand(debugCommand)
portArgs.AddToCommand(debugCommand)
programmer.AddToCommand(debugCommand)
profileArg.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."))
Expand All @@ -72,8 +74,7 @@ func NewCommand() *cobra.Command {
}

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

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

fqbn, port := arguments.CalculateFQBNAndPort(portArgs, fqbnArg, instance, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
var inst *rpc.Instance
var profile *rpc.SketchProfile

if profileArg.Get() == "" {
inst, profile = instance.CreateAndInitWithProfile(sk.GetDefaultProfile().GetName(), sketchPath)
} else {
inst, profile = instance.CreateAndInitWithProfile(profileArg.Get(), sketchPath)
}

if fqbnArg.String() == "" {
fqbnArg.Set(profile.GetFqbn())
}

fqbn, port := arguments.CalculateFQBNAndPort(portArgs, fqbnArg, inst, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())

prog := profile.GetProgrammer()
if prog == "" || programmer.GetProgrammer() != "" {
prog = programmer.String(inst, fqbn)
}

debugConfigRequested := &rpc.GetDebugConfigRequest{
Instance: instance,
Instance: inst,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Port: port,
Interpreter: interpreter,
ImportDir: importDir,
Programmer: programmer.String(instance, fqbn),
Programmer: prog,
}

if printInfo {
Expand Down