Skip to content

Commit 9bc2afc

Browse files
[breaking] Align board list --watch and board list json output (#2219)
* Align `board list --watch` and `board list` json output * Update docs
1 parent ffb3d2f commit 9bc2afc

File tree

2 files changed

+64
-22
lines changed

2 files changed

+64
-22
lines changed

docs/UPGRADING.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,58 @@ Here you can find a list of migration guides to handle breaking changes between
44

55
## 0.34.0
66

7+
### `board list --watch` command JSON output has changed
8+
9+
`board list --watch` command JSON output changed from:
10+
11+
```
12+
{
13+
"type": "add",
14+
"address": "COM3",
15+
"label": "COM3",
16+
"protocol": "serial",
17+
"protocol_label": "Serial Port (USB)",
18+
"hardwareId": "93B0245008567CB2",
19+
"properties": {
20+
"pid": "0x005E",
21+
"serialNumber": "93B0245008567CB2",
22+
"vid": "0x2341"
23+
},
24+
"boards": [
25+
{
26+
"name": "Arduino Nano RP2040 Connect",
27+
"fqbn": "arduino:mbed_nano:nanorp2040connect"
28+
}
29+
]
30+
}
31+
```
32+
33+
to:
34+
35+
```
36+
{
37+
"eventType": "add",
38+
"matching_boards": [
39+
{
40+
"name": "Arduino Nano RP2040 Connect",
41+
"fqbn": "arduino:mbed_nano:nanorp2040connect"
42+
}
43+
],
44+
"port": {
45+
"address": "COM3",
46+
"label": "COM3",
47+
"protocol": "serial",
48+
"protocol_label": "Serial Port (USB)",
49+
"properties": {
50+
"pid": "0x005E",
51+
"serialNumber": "93B0245008567CB2",
52+
"vid": "0x2341"
53+
},
54+
"hardware_id": "93B0245008567CB2"
55+
}
56+
}
57+
```
58+
759
### Updated sketch name specifications
860

961
[Sketch name specifications](https://arduino.github.io/arduino-cli/dev/sketch-specification) have been updated to

internal/cli/board/list.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,10 @@ func watchList(inst *rpc.Instance) {
9999

100100
for event := range eventsChan {
101101
feedback.PrintResult(watchEvent{
102-
Type: event.EventType,
103-
Label: event.Port.Port.Label,
104-
Address: event.Port.Port.Address,
105-
Protocol: event.Port.Port.Protocol,
106-
ProtocolLabel: event.Port.Port.ProtocolLabel,
107-
HardwareID: event.Port.Port.HardwareId,
108-
Properties: event.Port.Port.Properties,
109-
Boards: event.Port.MatchingBoards,
110-
Error: event.Error,
102+
Type: event.EventType,
103+
Boards: event.Port.MatchingBoards,
104+
Port: event.Port.Port,
105+
Error: event.Error,
111106
})
112107
}
113108
}
@@ -176,15 +171,10 @@ func (dr result) String() string {
176171
}
177172

178173
type watchEvent struct {
179-
Type string `json:"type"`
180-
Address string `json:"address,omitempty"`
181-
Label string `json:"label,omitempty"`
182-
Protocol string `json:"protocol,omitempty"`
183-
ProtocolLabel string `json:"protocol_label,omitempty"`
184-
HardwareID string `json:"hardwareId,omitempty"`
185-
Properties map[string]string `json:"properties"`
186-
Boards []*rpc.BoardListItem `json:"boards,omitempty"`
187-
Error string `json:"error,omitempty"`
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"`
188178
}
189179

190180
func (dr watchEvent) Data() interface{} {
@@ -199,11 +189,11 @@ func (dr watchEvent) String() string {
199189
"remove": tr("Disconnected"),
200190
}[dr.Type]
201191

202-
address := fmt.Sprintf("%s://%s", dr.Protocol, dr.Address)
203-
if dr.Protocol == "serial" || dr.Protocol == "" {
204-
address = dr.Address
192+
address := fmt.Sprintf("%s://%s", dr.Port.Protocol, dr.Port.Address)
193+
if dr.Port.Protocol == "serial" || dr.Port.Protocol == "" {
194+
address = dr.Port.Address
205195
}
206-
protocol := dr.ProtocolLabel
196+
protocol := dr.Port.ProtocolLabel
207197
if boards := dr.Boards; len(boards) > 0 {
208198
sort.Slice(boards, func(i, j int) bool {
209199
x, y := boards[i], boards[j]

0 commit comments

Comments
 (0)