Skip to content

[breaking] Align board list --watch and board list json output #2219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,58 @@ Here you can find a list of migration guides to handle breaking changes between

## 0.34.0

### `board list --watch` command JSON output has changed

`board list --watch` command JSON output changed from:

```
{
"type": "add",
"address": "COM3",
"label": "COM3",
"protocol": "serial",
"protocol_label": "Serial Port (USB)",
"hardwareId": "93B0245008567CB2",
"properties": {
"pid": "0x005E",
"serialNumber": "93B0245008567CB2",
"vid": "0x2341"
},
"boards": [
{
"name": "Arduino Nano RP2040 Connect",
"fqbn": "arduino:mbed_nano:nanorp2040connect"
}
]
}
```

to:

```
{
"eventType": "add",
"matching_boards": [
{
"name": "Arduino Nano RP2040 Connect",
"fqbn": "arduino:mbed_nano:nanorp2040connect"
}
],
"port": {
"address": "COM3",
"label": "COM3",
"protocol": "serial",
"protocol_label": "Serial Port (USB)",
"properties": {
"pid": "0x005E",
"serialNumber": "93B0245008567CB2",
"vid": "0x2341"
},
"hardware_id": "93B0245008567CB2"
}
}
```

### Updated sketch name specifications

[Sketch name specifications](https://arduino.github.io/arduino-cli/dev/sketch-specification) have been updated to
Expand Down
34 changes: 12 additions & 22 deletions internal/cli/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,10 @@ func watchList(inst *rpc.Instance) {

for event := range eventsChan {
feedback.PrintResult(watchEvent{
Type: event.EventType,
Label: event.Port.Port.Label,
Address: event.Port.Port.Address,
Protocol: event.Port.Port.Protocol,
ProtocolLabel: event.Port.Port.ProtocolLabel,
HardwareID: event.Port.Port.HardwareId,
Properties: event.Port.Port.Properties,
Boards: event.Port.MatchingBoards,
Error: event.Error,
Type: event.EventType,
Boards: event.Port.MatchingBoards,
Port: event.Port.Port,
Error: event.Error,
})
}
}
Expand Down Expand Up @@ -176,15 +171,10 @@ func (dr result) String() string {
}

type watchEvent struct {
Type string `json:"type"`
Address string `json:"address,omitempty"`
Label string `json:"label,omitempty"`
Protocol string `json:"protocol,omitempty"`
ProtocolLabel string `json:"protocol_label,omitempty"`
HardwareID string `json:"hardwareId,omitempty"`
Properties map[string]string `json:"properties"`
Boards []*rpc.BoardListItem `json:"boards,omitempty"`
Error string `json:"error,omitempty"`
Type string `json:"eventType"`
Boards []*rpc.BoardListItem `json:"matching_boards,omitempty"`
Port *rpc.Port `json:"port,omitempty"`
Error string `json:"error,omitempty"`
}

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

address := fmt.Sprintf("%s://%s", dr.Protocol, dr.Address)
if dr.Protocol == "serial" || dr.Protocol == "" {
address = dr.Address
address := fmt.Sprintf("%s://%s", dr.Port.Protocol, dr.Port.Address)
if dr.Port.Protocol == "serial" || dr.Port.Protocol == "" {
address = dr.Port.Address
}
protocol := dr.ProtocolLabel
protocol := dr.Port.ProtocolLabel
if boards := dr.Boards; len(boards) > 0 {
sort.Slice(boards, func(i, j int) bool {
x, y := boards[i], boards[j]
Expand Down