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) { ...@@ -72,26 +72,32 @@ func runListCommand(cmd *cobra.Command, args []string) {
} }
func outputListResp(resp *rpc.BoardListResp) { func outputListResp(resp *rpc.BoardListResp) {
sort.Slice(resp.Ports, func(i, j int) bool { ports := resp.GetPorts()
x, y := resp.Ports[i], resp.Ports[j] if len(ports) == 0 {
return x.Protocol < y.Protocol || (x.Protocol == y.Protocol && x.Address < y.Address) 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 := output.NewTable()
table.SetHeader("Port", "Type", "Board Name", "FQBN") table.SetHeader("Port", "Type", "Board Name", "FQBN")
for _, port := range resp.Ports { for _, port := range resp.GetPorts() {
address := port.Protocol + "://" + port.Address address := port.GetProtocol() + "://" + port.GetAddress()
if port.Protocol == "serial" { if port.GetProtocol() == "serial" {
address = port.Address address = port.GetAddress()
} }
protocol := port.ProtocolLabel protocol := port.GetProtocolLabel()
if len(port.Boards) > 0 { if boards := port.GetBoards(); len(boards) > 0 {
sort.Slice(port.Boards, func(i, j int) bool { sort.Slice(boards, func(i, j int) bool {
x, y := port.Boards[i], port.Boards[j] x, y := boards[i], boards[j]
return x.Name < y.Name || (x.Name == y.Name && x.FQBN < y.FQBN) return x.GetName() < y.GetName() || (x.GetName() == y.GetName() && x.GetFQBN() < y.GetFQBN())
}) })
for _, b := range port.Boards { for _, b := range boards {
board := b.Name board := b.GetName()
fqbn := b.FQBN fqbn := b.GetFQBN()
table.AddRow(address, protocol, board, fqbn) table.AddRow(address, protocol, board, fqbn)
// show address and protocol only on the first row // show address and protocol only on the first row
address = "" address = ""
......
...@@ -116,9 +116,8 @@ func Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) { ...@@ -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) { func Destroy(ctx context.Context, req *rpc.DestroyReq) (*rpc.DestroyResp, error) {
id := req.Instance.Id id := req.GetInstance().GetId()
_, ok := instances[id] if _, ok := instances[id]; !ok {
if !ok {
return nil, fmt.Errorf("invalid handle") return nil, fmt.Errorf("invalid handle")
} }
delete(instances, id) delete(instances, id)
...@@ -147,7 +146,7 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexReq, ...@@ -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) { 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] coreInstance, ok := instances[id]
if !ok { if !ok {
return nil, fmt.Errorf("invalid handle") return nil, fmt.Errorf("invalid handle")
...@@ -196,7 +195,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo ...@@ -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) { func Rescan(ctx context.Context, req *rpc.RescanReq) (*rpc.RescanResp, error) {
id := req.Instance.Id id := req.GetInstance().GetId()
coreInstance, ok := instances[id] coreInstance, ok := instances[id]
if !ok { if !ok {
return nil, fmt.Errorf("invalid handle") 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