@@ -27,6 +27,7 @@ import (
2727 "github.com/arduino/arduino-cli/commands/board"
2828 "github.com/arduino/arduino-cli/internal/cli/arguments"
2929 "github.com/arduino/arduino-cli/internal/cli/feedback"
30+ "github.com/arduino/arduino-cli/internal/cli/feedback/result"
3031 "github.com/arduino/arduino-cli/internal/cli/instance"
3132 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3233 "github.com/arduino/arduino-cli/table"
@@ -81,7 +82,8 @@ func runListCommand(watch bool, timeout int64, fqbn string) {
8182 for _ , err := range discoveryErrors {
8283 feedback .Warning (tr ("Error starting discovery: %v" , err ))
8384 }
84- feedback .PrintResult (result {ports })
85+
86+ feedback .PrintResult (listResult {result .NewDetectedPorts (ports )})
8587}
8688
8789func watchList (inst * rpc.Instance ) {
@@ -98,58 +100,60 @@ func watchList(inst *rpc.Instance) {
98100 }
99101
100102 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+ }
107111 }
108112}
109113
110114// output from this command requires special formatting, let's create a dedicated
111115// feedback.Result implementation
112- type result struct {
113- ports []* rpc .DetectedPort
116+ type listResult struct {
117+ ports []* result .DetectedPort
114118}
115119
116- func (dr result ) Data () interface {} {
120+ func (dr listResult ) Data () interface {} {
117121 return dr .ports
118122}
119123
120- func (dr result ) String () string {
124+ func (dr listResult ) String () string {
121125 if len (dr .ports ) == 0 {
122126 return tr ("No boards found." )
123127 }
124128
125129 sort .Slice (dr .ports , func (i , j int ) bool {
126130 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 )
129133 })
130134
131135 t := table .New ()
132136 t .SetHeader (tr ("Port" ), tr ("Protocol" ), tr ("Type" ), tr ("Board Name" ), tr ("FQBN" ), tr ("Core" ))
133137 for _ , detectedPort := range dr .ports {
134138 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
139143 }
140- protocolLabel := port .GetProtocolLabel ()
141- if boards := detectedPort .GetMatchingBoards () ; len (boards ) > 0 {
144+ protocolLabel := port .ProtocolLabel
145+ if boards := detectedPort .MatchingBoards ; len (boards ) > 0 {
142146 sort .Slice (boards , func (i , j int ) bool {
143147 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 )
145149 })
146150 for _ , b := range boards {
147- board := b .GetName ()
151+ board := b .Name
148152
149153 // to improve the user experience, show on a dedicated column
150154 // the name of the core supporting the board detected
151155 var coreName = ""
152- fqbn , err := cores .ParseFQBN (b .GetFqbn () )
156+ fqbn , err := cores .ParseFQBN (b .Fqbn )
153157 if err == nil {
154158 coreName = fmt .Sprintf ("%s:%s" , fqbn .Package , fqbn .PlatformArch )
155159 }
@@ -170,18 +174,18 @@ func (dr result) String() string {
170174 return t .Render ()
171175}
172176
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"`
178182}
179183
180- func (dr watchEvent ) Data () interface {} {
184+ func (dr watchEventResult ) Data () interface {} {
181185 return dr
182186}
183187
184- func (dr watchEvent ) String () string {
188+ func (dr watchEventResult ) String () string {
185189 t := table .New ()
186190
187191 event := map [string ]string {
@@ -197,15 +201,15 @@ func (dr watchEvent) String() string {
197201 if boards := dr .Boards ; len (boards ) > 0 {
198202 sort .Slice (boards , func (i , j int ) bool {
199203 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 )
201205 })
202206 for _ , b := range boards {
203- board := b .GetName ()
207+ board := b .Name
204208
205209 // to improve the user experience, show on a dedicated column
206210 // the name of the core supporting the board detected
207211 var coreName = ""
208- fqbn , err := cores .ParseFQBN (b .GetFqbn () )
212+ fqbn , err := cores .ParseFQBN (b .Fqbn )
209213 if err == nil {
210214 coreName = fmt .Sprintf ("%s:%s" , fqbn .Package , fqbn .PlatformArch )
211215 }
0 commit comments