Skip to content

Commit 4d59516

Browse files
committed
Implementation of cli command 'debug check'
1 parent f5c0877 commit 4d59516

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

internal/cli/debug/debug.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func NewCommand() *cobra.Command {
6060
},
6161
}
6262

63+
debugCommand.AddCommand(newDebugCheckCommand())
6364
fqbnArg.AddToCommand(debugCommand)
6465
portArgs.AddToCommand(debugCommand)
6566
programmer.AddToCommand(debugCommand)

internal/cli/debug/debug_check.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package debug
17+
18+
import (
19+
"context"
20+
"os"
21+
22+
"github.com/arduino/arduino-cli/commands/debug"
23+
"github.com/arduino/arduino-cli/internal/cli/arguments"
24+
"github.com/arduino/arduino-cli/internal/cli/feedback"
25+
"github.com/arduino/arduino-cli/internal/cli/feedback/result"
26+
"github.com/arduino/arduino-cli/internal/cli/instance"
27+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
28+
"github.com/sirupsen/logrus"
29+
"github.com/spf13/cobra"
30+
)
31+
32+
func newDebugCheckCommand() *cobra.Command {
33+
var (
34+
fqbnArg arguments.Fqbn
35+
portArgs arguments.Port
36+
interpreter string
37+
programmer arguments.Programmer
38+
)
39+
debugCheckCommand := &cobra.Command{
40+
Use: "check",
41+
Short: tr("Check if the given board/programmer combination supports debugging."),
42+
Example: " " + os.Args[0] + " debug check -b arduino:samd:mkr1000 -P atmel_ice",
43+
Run: func(cmd *cobra.Command, args []string) {
44+
runDebugCheckCommand(&portArgs, &fqbnArg, interpreter, &programmer)
45+
},
46+
}
47+
fqbnArg.AddToCommand(debugCheckCommand)
48+
portArgs.AddToCommand(debugCheckCommand)
49+
programmer.AddToCommand(debugCheckCommand)
50+
debugCheckCommand.Flags().StringVar(&interpreter, "interpreter", "console", tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
51+
return debugCheckCommand
52+
}
53+
54+
func runDebugCheckCommand(portArgs *arguments.Port, fqbnArg *arguments.Fqbn, interpreter string, programmerArg *arguments.Programmer) {
55+
instance := instance.CreateAndInit()
56+
logrus.Info("Executing `arduino-cli debug`")
57+
58+
port, err := portArgs.GetPort(instance, "", "")
59+
if err != nil {
60+
feedback.FatalError(err, feedback.ErrBadArgument)
61+
}
62+
fqbn := fqbnArg.String()
63+
resp, err := debug.IsDebugSupported(context.Background(), &rpc.IsDebugSupportedRequest{
64+
Instance: instance,
65+
Fqbn: fqbn,
66+
Port: port,
67+
Interpreter: interpreter,
68+
Programmer: programmerArg.String(instance, fqbn),
69+
})
70+
if err != nil {
71+
feedback.FatalError(err, feedback.ErrGeneric)
72+
}
73+
feedback.PrintResult(&debugCheckResult{result.NewIsDebugSupportedResponse(resp)})
74+
}
75+
76+
type debugCheckResult struct {
77+
Result *result.IsDebugSupportedResponse
78+
}
79+
80+
func (d *debugCheckResult) Data() interface{} {
81+
return d.Result
82+
}
83+
84+
func (d *debugCheckResult) String() string {
85+
if d.Result.Supported {
86+
return tr("The given board/programmer configuration supports debugging.")
87+
}
88+
return tr("The given board/programmer configuration does NOT support debugging.")
89+
}

internal/cli/feedback/result/rpc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,3 +1057,13 @@ func NewCompileDiagnosticNote(cdn *rpc.CompileDiagnosticNote) *CompileDiagnostic
10571057
Column: cdn.GetColumn(),
10581058
}
10591059
}
1060+
1061+
type IsDebugSupportedResponse struct {
1062+
Supported bool `json:"supported"`
1063+
}
1064+
1065+
func NewIsDebugSupportedResponse(resp *rpc.IsDebugSupportedResponse) *IsDebugSupportedResponse {
1066+
return &IsDebugSupportedResponse{
1067+
Supported: resp.GetSupported(),
1068+
}
1069+
}

internal/cli/feedback/result/rpc_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ func TestAllFieldAreMapped(t *testing.T) {
217217
compileDiagnosticNoteRpc := &rpc.CompileDiagnosticNote{}
218218
compileDiagnosticNoteResult := result.NewCompileDiagnosticNote(compileDiagnosticNoteRpc)
219219
mustContainsAllPropertyOfRpcStruct(t, compileDiagnosticNoteRpc, compileDiagnosticNoteResult)
220+
221+
isDebugSupportedResponseRpc := &rpc.IsDebugSupportedResponse{}
222+
isDebugSupportedResponseResult := result.NewIsDebugSupportedResponse(isDebugSupportedResponseRpc)
223+
mustContainsAllPropertyOfRpcStruct(t, isDebugSupportedResponseRpc, isDebugSupportedResponseResult)
220224
}
221225

222226
func TestEnumsMapsEveryRpcCounterpart(t *testing.T) {

0 commit comments

Comments
 (0)