@@ -27,6 +27,7 @@ import (
27
27
"github.com/arduino/arduino-cli/commands/board"
28
28
"github.com/arduino/arduino-cli/internal/cli/arguments"
29
29
"github.com/arduino/arduino-cli/internal/cli/feedback"
30
+ "github.com/arduino/arduino-cli/internal/cli/feedback/result"
30
31
"github.com/arduino/arduino-cli/internal/cli/instance"
31
32
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
32
33
"github.com/arduino/arduino-cli/table"
@@ -81,7 +82,8 @@ func runListCommand(watch bool, timeout int64, fqbn string) {
81
82
for _ , err := range discoveryErrors {
82
83
feedback .Warning (tr ("Error starting discovery: %v" , err ))
83
84
}
84
- feedback .PrintResult (result {ports })
85
+
86
+ feedback .PrintResult (listResult {result .NewDetectedPorts (ports )})
85
87
}
86
88
87
89
func watchList (inst * rpc.Instance ) {
@@ -98,58 +100,60 @@ func watchList(inst *rpc.Instance) {
98
100
}
99
101
100
102
for event := range eventsChan {
101
- feedback .PrintResult (watchEvent {
102
- Type : event .EventType ,
103
- Boards : event .Port .MatchingBoards ,
104
- Port : event .Port .Port ,
105
- Error : event .Error ,
106
- })
103
+ if res := result .NewBoardListWatchResponse (event ); res != nil {
104
+ feedback .PrintResult (watchEventResult {
105
+ Type : res .EventType ,
106
+ Boards : res .Port .MatchingBoards ,
107
+ Port : res .Port .Port ,
108
+ Error : res .Error ,
109
+ })
110
+ }
107
111
}
108
112
}
109
113
110
114
// output from this command requires special formatting, let's create a dedicated
111
115
// feedback.Result implementation
112
- type result struct {
113
- ports []* rpc .DetectedPort
116
+ type listResult struct {
117
+ ports []* result .DetectedPort
114
118
}
115
119
116
- func (dr result ) Data () interface {} {
120
+ func (dr listResult ) Data () interface {} {
117
121
return dr .ports
118
122
}
119
123
120
- func (dr result ) String () string {
124
+ func (dr listResult ) String () string {
121
125
if len (dr .ports ) == 0 {
122
126
return tr ("No boards found." )
123
127
}
124
128
125
129
sort .Slice (dr .ports , func (i , j int ) bool {
126
130
x , y := dr .ports [i ].Port , dr .ports [j ].Port
127
- return x .GetProtocol () < y .GetProtocol () ||
128
- (x .GetProtocol () == y .GetProtocol () && x .GetAddress () < y .GetAddress () )
131
+ return x .Protocol < y .Protocol ||
132
+ (x .Protocol == y .Protocol && x .Address < y .Address )
129
133
})
130
134
131
135
t := table .New ()
132
136
t .SetHeader (tr ("Port" ), tr ("Protocol" ), tr ("Type" ), tr ("Board Name" ), tr ("FQBN" ), tr ("Core" ))
133
137
for _ , detectedPort := range dr .ports {
134
138
port := detectedPort .Port
135
- protocol := port .GetProtocol ()
136
- address := port .GetAddress ()
137
- if port .GetProtocol () == "serial" {
138
- address = port .GetAddress ()
139
+ protocol := port .Protocol
140
+ address := port .Address
141
+ if port .Protocol == "serial" {
142
+ address = port .Address
139
143
}
140
- protocolLabel := port .GetProtocolLabel ()
141
- if boards := detectedPort .GetMatchingBoards () ; len (boards ) > 0 {
144
+ protocolLabel := port .ProtocolLabel
145
+ if boards := detectedPort .MatchingBoards ; len (boards ) > 0 {
142
146
sort .Slice (boards , func (i , j int ) bool {
143
147
x , y := boards [i ], boards [j ]
144
- return x .GetName () < y .GetName () || (x .GetName () == y .GetName () && x .GetFqbn () < y .GetFqbn () )
148
+ return x .Name < y .Name || (x .Name == y .Name && x .Fqbn < y .Fqbn )
145
149
})
146
150
for _ , b := range boards {
147
- board := b .GetName ()
151
+ board := b .Name
148
152
149
153
// to improve the user experience, show on a dedicated column
150
154
// the name of the core supporting the board detected
151
155
var coreName = ""
152
- fqbn , err := cores .ParseFQBN (b .GetFqbn () )
156
+ fqbn , err := cores .ParseFQBN (b .Fqbn )
153
157
if err == nil {
154
158
coreName = fmt .Sprintf ("%s:%s" , fqbn .Package , fqbn .PlatformArch )
155
159
}
@@ -170,18 +174,18 @@ func (dr result) String() string {
170
174
return t .Render ()
171
175
}
172
176
173
- type watchEvent struct {
174
- Type string `json:"eventType"`
175
- Boards []* rpc .BoardListItem `json:"matching_boards,omitempty"`
176
- Port * rpc .Port `json:"port,omitempty"`
177
- Error string `json:"error,omitempty"`
177
+ type watchEventResult struct {
178
+ Type string `json:"eventType"`
179
+ Boards []* result .BoardListItem `json:"matching_boards,omitempty"`
180
+ Port * result .Port `json:"port,omitempty"`
181
+ Error string `json:"error,omitempty"`
178
182
}
179
183
180
- func (dr watchEvent ) Data () interface {} {
184
+ func (dr watchEventResult ) Data () interface {} {
181
185
return dr
182
186
}
183
187
184
- func (dr watchEvent ) String () string {
188
+ func (dr watchEventResult ) String () string {
185
189
t := table .New ()
186
190
187
191
event := map [string ]string {
@@ -197,15 +201,15 @@ func (dr watchEvent) String() string {
197
201
if boards := dr .Boards ; len (boards ) > 0 {
198
202
sort .Slice (boards , func (i , j int ) bool {
199
203
x , y := boards [i ], boards [j ]
200
- return x .GetName () < y .GetName () || (x .GetName () == y .GetName () && x .GetFqbn () < y .GetFqbn () )
204
+ return x .Name < y .Name || (x .Name == y .Name && x .Fqbn < y .Fqbn )
201
205
})
202
206
for _ , b := range boards {
203
- board := b .GetName ()
207
+ board := b .Name
204
208
205
209
// to improve the user experience, show on a dedicated column
206
210
// the name of the core supporting the board detected
207
211
var coreName = ""
208
- fqbn , err := cores .ParseFQBN (b .GetFqbn () )
212
+ fqbn , err := cores .ParseFQBN (b .Fqbn )
209
213
if err == nil {
210
214
coreName = fmt .Sprintf ("%s:%s" , fqbn .Package , fqbn .PlatformArch )
211
215
}
0 commit comments