Commit 6ec261e6 authored by Cristian Maglie's avatar Cristian Maglie

Use rpc getters instead of direct access to fields

parent f06a5999
......@@ -72,26 +72,32 @@ func runListCommand(cmd *cobra.Command, args []string) {
}
func outputListResp(resp *rpc.BoardListResp) {
sort.Slice(resp.Ports, func(i, j int) bool {
x, y := resp.Ports[i], resp.Ports[j]
return x.Protocol < y.Protocol || (x.Protocol == y.Protocol && x.Address < y.Address)
ports := resp.GetPorts()
if len(ports) == 0 {
formatter.Print("No boards found.")
return
}
sort.Slice(ports, func(i, j int) bool {
x, y := ports[i], ports[j]
return x.GetProtocol() < y.GetProtocol() ||
(x.GetProtocol() == y.GetProtocol() && x.GetAddress() < y.GetAddress())
})
table := output.NewTable()
table.SetHeader("Port", "Type", "Board Name", "FQBN")
for _, port := range resp.Ports {
address := port.Protocol + "://" + port.Address
if port.Protocol == "serial" {
address = port.Address
for _, port := range resp.GetPorts() {
address := port.GetProtocol() + "://" + port.GetAddress()
if port.GetProtocol() == "serial" {
address = port.GetAddress()
}
protocol := port.ProtocolLabel
if len(port.Boards) > 0 {
sort.Slice(port.Boards, func(i, j int) bool {
x, y := port.Boards[i], port.Boards[j]
return x.Name < y.Name || (x.Name == y.Name && x.FQBN < y.FQBN)
protocol := port.GetProtocolLabel()
if boards := port.GetBoards(); len(boards) > 0 {
sort.Slice(boards, func(i, j int) bool {
x, y := boards[i], boards[j]
return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFQBN() < y.GetFQBN())
})
for _, b := range port.Boards {
board := b.Name
fqbn := b.FQBN
for _, b := range boards {
board := b.GetName()
fqbn := b.GetFQBN()
table.AddRow(address, protocol, board, fqbn)
// show address and protocol only on the first row
address = ""
......
......@@ -116,9 +116,8 @@ func Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) {
}
func Destroy(ctx context.Context, req *rpc.DestroyReq) (*rpc.DestroyResp, error) {
id := req.Instance.Id
_, ok := instances[id]
if !ok {
id := req.GetInstance().GetId()
if _, ok := instances[id]; !ok {
return nil, fmt.Errorf("invalid handle")
}
delete(instances, id)
......@@ -147,7 +146,7 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexReq,
}
func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB DownloadProgressCB) (*rpc.UpdateIndexResp, error) {
id := req.Instance.Id
id := req.GetInstance().GetId()
coreInstance, ok := instances[id]
if !ok {
return nil, fmt.Errorf("invalid handle")
......@@ -196,7 +195,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo
}
func Rescan(ctx context.Context, req *rpc.RescanReq) (*rpc.RescanResp, error) {
id := req.Instance.Id
id := req.GetInstance().GetId()
coreInstance, ok := instances[id]
if !ok {
return nil, fmt.Errorf("invalid handle")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment