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