Skip to content

Commit 6ec261e

Browse files
committed
Use rpc getters instead of direct access to fields
1 parent f06a599 commit 6ec261e

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

cli/board/list.go

+21-15
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,32 @@ func runListCommand(cmd *cobra.Command, args []string) {
7272
}
7373

7474
func outputListResp(resp *rpc.BoardListResp) {
75-
sort.Slice(resp.Ports, func(i, j int) bool {
76-
x, y := resp.Ports[i], resp.Ports[j]
77-
return x.Protocol < y.Protocol || (x.Protocol == y.Protocol && x.Address < y.Address)
75+
ports := resp.GetPorts()
76+
if len(ports) == 0 {
77+
formatter.Print("No boards found.")
78+
return
79+
}
80+
sort.Slice(ports, func(i, j int) bool {
81+
x, y := ports[i], ports[j]
82+
return x.GetProtocol() < y.GetProtocol() ||
83+
(x.GetProtocol() == y.GetProtocol() && x.GetAddress() < y.GetAddress())
7884
})
7985
table := output.NewTable()
8086
table.SetHeader("Port", "Type", "Board Name", "FQBN")
81-
for _, port := range resp.Ports {
82-
address := port.Protocol + "://" + port.Address
83-
if port.Protocol == "serial" {
84-
address = port.Address
87+
for _, port := range resp.GetPorts() {
88+
address := port.GetProtocol() + "://" + port.GetAddress()
89+
if port.GetProtocol() == "serial" {
90+
address = port.GetAddress()
8591
}
86-
protocol := port.ProtocolLabel
87-
if len(port.Boards) > 0 {
88-
sort.Slice(port.Boards, func(i, j int) bool {
89-
x, y := port.Boards[i], port.Boards[j]
90-
return x.Name < y.Name || (x.Name == y.Name && x.FQBN < y.FQBN)
92+
protocol := port.GetProtocolLabel()
93+
if boards := port.GetBoards(); len(boards) > 0 {
94+
sort.Slice(boards, func(i, j int) bool {
95+
x, y := boards[i], boards[j]
96+
return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFQBN() < y.GetFQBN())
9197
})
92-
for _, b := range port.Boards {
93-
board := b.Name
94-
fqbn := b.FQBN
98+
for _, b := range boards {
99+
board := b.GetName()
100+
fqbn := b.GetFQBN()
95101
table.AddRow(address, protocol, board, fqbn)
96102
// show address and protocol only on the first row
97103
address = ""

commands/instances.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ func Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) {
116116
}
117117

118118
func Destroy(ctx context.Context, req *rpc.DestroyReq) (*rpc.DestroyResp, error) {
119-
id := req.Instance.Id
120-
_, ok := instances[id]
121-
if !ok {
119+
id := req.GetInstance().GetId()
120+
if _, ok := instances[id]; !ok {
122121
return nil, fmt.Errorf("invalid handle")
123122
}
124123
delete(instances, id)
@@ -147,7 +146,7 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexReq,
147146
}
148147

149148
func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB DownloadProgressCB) (*rpc.UpdateIndexResp, error) {
150-
id := req.Instance.Id
149+
id := req.GetInstance().GetId()
151150
coreInstance, ok := instances[id]
152151
if !ok {
153152
return nil, fmt.Errorf("invalid handle")
@@ -196,7 +195,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
196195
}
197196

198197
func Rescan(ctx context.Context, req *rpc.RescanReq) (*rpc.RescanResp, error) {
199-
id := req.Instance.Id
198+
id := req.GetInstance().GetId()
200199
coreInstance, ok := instances[id]
201200
if !ok {
202201
return nil, fmt.Errorf("invalid handle")

0 commit comments

Comments
 (0)