Commit 3b98cef7 authored by Cristian Maglie's avatar Cristian Maglie

Implemented BoardListAll grpc method

parent b6a5eb49
......@@ -18,12 +18,16 @@
package board
import (
"context"
"fmt"
"os"
"sort"
"strings"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/common/formatter/output"
"github.com/arduino/arduino-cli/output"
"github.com/arduino/arduino-cli/rpc"
"github.com/spf13/cobra"
)
......@@ -45,36 +49,30 @@ func initListAllCommand() *cobra.Command {
// runListAllCommand list all installed boards
func runListAllCommand(cmd *cobra.Command, args []string) {
pm, _ := cli.InitPackageAndLibraryManager()
instance := cli.CreateInstance()
match := func(name string) bool {
name = strings.ToLower(name)
for _, term := range args {
if !strings.Contains(name, strings.ToLower(term)) {
return false
}
}
return true
list, err := board.BoardListAll(context.Background(), &rpc.BoardListAllReq{
Instance: instance,
SearchArgs: args,
})
if err != nil {
formatter.PrintError(err, "Error listing boards")
os.Exit(cli.ErrGeneric)
}
if cli.OutputJSONOrElse(list) {
outputBoardListAll(list)
}
}
func outputBoardListAll(list *rpc.BoardListAllResp) {
sort.Slice(list.Boards, func(i, j int) bool {
return list.Boards[i].GetName() < list.Boards[j].GetName()
})
list := &output.BoardList{}
for _, targetPackage := range pm.GetPackages().Packages {
for _, platform := range targetPackage.Platforms {
platformRelease := pm.GetInstalledPlatformRelease(platform)
if platformRelease == nil {
continue
}
for _, board := range platformRelease.Boards {
if !match(board.Name()) {
continue
}
list.Boards = append(list.Boards, &output.BoardListItem{
Name: board.Name(),
Fqbn: board.FQBN(),
})
}
}
table := output.NewTable()
table.SetHeader("Board Name", "FQBN")
for _, item := range list.GetBoards() {
table.AddRow(item.GetName(), item.GetFQBN())
}
sort.Sort(list)
formatter.Print(list)
fmt.Print(table.Render())
}
......@@ -40,9 +40,9 @@ func BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp,
continue
}
for _, port := range ports {
b := []*rpc.DetectedBoard{}
b := []*rpc.BoardListItem{}
for _, board := range pm.IdentifyBoard(port.IdentificationPrefs) {
b = append(b, &rpc.DetectedBoard{
b = append(b, &rpc.BoardListItem{
Name: board.Name(),
FQBN: board.FQBN(),
})
......
/*
* This file is part of arduino-cli.
*
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
*
* This software is released under the GNU General Public License version 3,
* which covers the main part of arduino-cli.
* The terms of this license can be found at:
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* You can be released from the requirements of the above licenses by purchasing
* a commercial license. Buying such a license is mandatory if you want to modify or
* otherwise use the software for commercial activities involving the Arduino
* software without disclosing the source code of your own applications. To purchase
* a commercial license, send an email to license@arduino.cc.
*/
package board
import (
"context"
"errors"
"strings"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc"
)
func BoardListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
return nil, errors.New("invalid instance")
}
args := req.GetSearchArgs()
match := func(name string) bool {
if len(args) == 0 {
return true
}
name = strings.ToLower(name)
for _, term := range args {
if !strings.Contains(name, strings.ToLower(term)) {
return false
}
}
return true
}
list := &rpc.BoardListAllResp{Boards: []*rpc.BoardListItem{}}
for _, targetPackage := range pm.GetPackages().Packages {
for _, platform := range targetPackage.Platforms {
platformRelease := pm.GetInstalledPlatformRelease(platform)
if platformRelease == nil {
continue
}
for _, board := range platformRelease.Boards {
if !match(board.Name()) {
continue
}
list.Boards = append(list.Boards, &rpc.BoardListItem{
Name: board.Name(),
FQBN: board.FQBN(),
})
}
}
}
return list, nil
}
......@@ -58,38 +58,3 @@ func (bl *AttachedBoardList) String() string {
}
return fmt.Sprintln(table)
}
// BoardListItem is a supported board
type BoardListItem struct {
Name string `json:"name,required"`
Fqbn string `json:"fqbn,required"`
}
// BoardList is a list of supported boards
type BoardList struct {
Boards []*BoardListItem `json:"boards,required"`
}
func (bl *BoardList) String() string {
table := uitable.New()
table.MaxColWidth = 100
table.Wrap = true // wrap columns
table.AddRow("Board Name", "FQBN")
for _, item := range bl.Boards {
table.AddRow(item.Name, item.Fqbn)
}
return fmt.Sprintln(table)
}
func (bl *BoardList) Len() int {
return len(bl.Boards)
}
func (bl *BoardList) Less(i, j int) bool {
return bl.Boards[i].Name < bl.Boards[j].Name
}
func (bl *BoardList) Swap(i, j int) {
bl.Boards[i], bl.Boards[j] = bl.Boards[j], bl.Boards[i]
}
......@@ -64,6 +64,10 @@ func (s *ArduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardLis
return board.BoardList(ctx, req)
}
func (s *ArduinoCoreServerImpl) BoardListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllResp, error) {
return board.BoardListAll(ctx, req)
}
func (s *ArduinoCoreServerImpl) BoardAttach(req *rpc.BoardAttachReq, stream rpc.ArduinoCore_BoardAttachServer) error {
resp, err := board.BoardAttach(stream.Context(), req,
......
This diff is collapsed.
......@@ -76,10 +76,19 @@ message DetectedPort {
string address = 1;
string protocol = 2;
string protocol_label = 3;
repeated DetectedBoard boards = 4;
repeated BoardListItem boards = 4;
}
message DetectedBoard {
message BoardListAllReq {
Instance instance = 1;
repeated string search_args = 2;
}
message BoardListAllResp {
repeated BoardListItem boards = 1;
}
message BoardListItem {
string name = 1;
string FQBN = 2;
}
This diff is collapsed.
......@@ -58,6 +58,8 @@ service ArduinoCore {
rpc BoardList(BoardListReq) returns (BoardListResp);
rpc BoardListAll(BoardListAllReq) returns (BoardListAllResp);
rpc Compile(CompileReq) returns (stream CompileResp);
rpc PlatformInstall(PlatformInstallReq) returns (stream PlatformInstallResp);
......
......@@ -41,7 +41,7 @@ func (m *CompileReq) Reset() { *m = CompileReq{} }
func (m *CompileReq) String() string { return proto.CompactTextString(m) }
func (*CompileReq) ProtoMessage() {}
func (*CompileReq) Descriptor() ([]byte, []int) {
return fileDescriptor_compile_cef1caa660007272, []int{0}
return fileDescriptor_compile_56a3ee3fd90c77e2, []int{0}
}
func (m *CompileReq) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_CompileReq.Unmarshal(m, b)
......@@ -153,20 +153,18 @@ func (m *CompileReq) GetExportFile() string {
}
type CompileResp struct {
OutStream []byte `protobuf:"bytes,1,opt,name=out_stream,json=outStream,proto3" json:"out_stream,omitempty"`
ErrStream []byte `protobuf:"bytes,2,opt,name=err_stream,json=errStream,proto3" json:"err_stream,omitempty"`
DownloadProgress *DownloadProgress `protobuf:"bytes,3,opt,name=download_progress,json=downloadProgress,proto3" json:"download_progress,omitempty"`
TaskProgress *TaskProgress `protobuf:"bytes,4,opt,name=task_progress,json=taskProgress,proto3" json:"task_progress,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
OutStream []byte `protobuf:"bytes,1,opt,name=out_stream,json=outStream,proto3" json:"out_stream,omitempty"`
ErrStream []byte `protobuf:"bytes,2,opt,name=err_stream,json=errStream,proto3" json:"err_stream,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *CompileResp) Reset() { *m = CompileResp{} }
func (m *CompileResp) String() string { return proto.CompactTextString(m) }
func (*CompileResp) ProtoMessage() {}
func (*CompileResp) Descriptor() ([]byte, []int) {
return fileDescriptor_compile_cef1caa660007272, []int{1}
return fileDescriptor_compile_56a3ee3fd90c77e2, []int{1}
}
func (m *CompileResp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_CompileResp.Unmarshal(m, b)
......@@ -200,54 +198,36 @@ func (m *CompileResp) GetErrStream() []byte {
return nil
}
func (m *CompileResp) GetDownloadProgress() *DownloadProgress {
if m != nil {
return m.DownloadProgress
}
return nil
}
func (m *CompileResp) GetTaskProgress() *TaskProgress {
if m != nil {
return m.TaskProgress
}
return nil
}
func init() {
proto.RegisterType((*CompileReq)(nil), "cc.arduino.core.rpc.CompileReq")
proto.RegisterType((*CompileResp)(nil), "cc.arduino.core.rpc.CompileResp")
}
func init() { proto.RegisterFile("compile.proto", fileDescriptor_compile_cef1caa660007272) }
var fileDescriptor_compile_cef1caa660007272 = []byte{
// 422 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x92, 0xcf, 0x8e, 0xd3, 0x30,
0x10, 0x87, 0xd5, 0x6d, 0xb7, 0xdb, 0x4e, 0x5b, 0xfe, 0x18, 0x84, 0xac, 0x15, 0x8b, 0x96, 0x0a,
0xd0, 0x5e, 0xc8, 0x4a, 0x70, 0xe2, 0xca, 0xa2, 0x95, 0xb8, 0x55, 0x81, 0x13, 0x97, 0x95, 0xe3,
0x0c, 0x8d, 0xb5, 0x8d, 0x9d, 0xda, 0x4e, 0xcb, 0x9b, 0xf1, 0x48, 0xbc, 0x06, 0xce, 0x24, 0x4d,
0xaa, 0xa8, 0xa7, 0x76, 0xbe, 0xf9, 0xfc, 0xb3, 0x63, 0x0f, 0x2c, 0xa4, 0xc9, 0x0b, 0xb5, 0xc1,
0xa8, 0xb0, 0xc6, 0x1b, 0xf6, 0x42, 0xca, 0x48, 0xd8, 0xb4, 0x54, 0xda, 0x44, 0xd2, 0x58, 0x8c,
0x6c, 0x21, 0x2f, 0xe7, 0xc1, 0xc9, 0x8d, 0xae, 0x95, 0xe5, 0xdf, 0x21, 0xc0, 0x5d, 0xbd, 0x28,
0xc6, 0x2d, 0xfb, 0x02, 0x13, 0xa5, 0x9d, 0x17, 0x5a, 0x22, 0x1f, 0x5c, 0x0f, 0x6e, 0x66, 0x9f,
0xae, 0xa2, 0x13, 0x21, 0xd1, 0xf7, 0x46, 0x8a, 0x5b, 0x9d, 0x31, 0x18, 0xfd, 0xde, 0x26, 0x9a,
0x9f, 0x85, 0x65, 0xd3, 0x98, 0xfe, 0xb3, 0x37, 0x00, 0xee, 0x11, 0xbd, 0xcc, 0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, 0xea, 0xda, 0x56, 0x17, 0x3d, 0xa4, 0x09, 0x78, 0x7f, 0x72, 0x02,
0xbe, 0x35, 0xf6, 0xaa, 0x91, 0xe3, 0x67, 0x69, 0x8f, 0xb0, 0x7b, 0x58, 0x78, 0xe1, 0x1e, 0xbb,
0xbc, 0x11, 0xe5, 0xbd, 0x3d, 0x99, 0xf7, 0x33, 0x98, 0x6d, 0xd6, 0xdc, 0x1f, 0x55, 0x5f, 0xdf,
0xfd, 0x5a, 0xae, 0x95, 0xcf, 0xca, 0x24, 0xd8, 0xf9, 0x6d, 0xb3, 0xf2, 0xf0, 0xfb, 0x51, 0x6e,
0xd4, 0x6d, 0x08, 0x48, 0xc6, 0x34, 0xd0, 0x9f, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0x19, 0xa1,
0xc2, 0xe4, 0x04, 0x03, 0x00, 0x00,
func init() { proto.RegisterFile("compile.proto", fileDescriptor_compile_56a3ee3fd90c77e2) }
var fileDescriptor_compile_56a3ee3fd90c77e2 = []byte{
// 366 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x6c, 0x92, 0x4f, 0x6b, 0xe3, 0x30,
0x10, 0xc5, 0xc9, 0x7f, 0x7b, 0x92, 0xec, 0x82, 0x76, 0x59, 0x44, 0xd8, 0x2c, 0x21, 0x2c, 0x25,
0x97, 0x3a, 0xd0, 0x9e, 0x7a, 0x6d, 0xa0, 0x50, 0x7a, 0x09, 0xee, 0xad, 0x97, 0x62, 0xcb, 0xd3,
0x58, 0x34, 0xb6, 0x1c, 0x49, 0x4e, 0xfa, 0xcd, 0xfa, 0xf5, 0x2a, 0x8f, 0xf3, 0x8f, 0xd0, 0x53,
0x32, 0xbf, 0xf7, 0xf4, 0x34, 0xf6, 0x33, 0x0c, 0x85, 0xca, 0x0a, 0xb9, 0xc6, 0xa0, 0xd0, 0xca,
0x2a, 0xf6, 0x4b, 0x88, 0x20,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xf0, 0x01, 0x25, 0xed, 0xa7, 0xea, 0x99, 0xf1, 0xa3, 0x50, 0xda, 0x3e, 0xb8, 0x6e, 0xf8, 0xb0,
0x7e, 0x77, 0x27, 0x32, 0x7d, 0x82, 0xfe, 0xb1, 0x38, 0x53, 0xb0, 0x31, 0x80, 0x2a, 0xed, 0xab,
0xb1, 0x1a, 0xa3, 0x8c, 0xba, 0x1b, 0x84, 0xbe, 0x23, 0xcf, 0x04, 0x2a, 0x19, 0xb5, 0x3e, 0xc8,
0xcd, 0x5a, 0x76, 0xa4, 0x96, 0xef, 0xff, 0xbf, 0x4c, 0x57, 0xd2, 0xa6, 0x65, 0xec, 0x2a, 0xce,
0xe6, 0xfb, 0xba, 0x0f, 0xbf, 0xd7, 0x62, 0x2d, 0xe7, 0xae, 0xf5, 0xb8, 0x4b, 0xdf, 0xcc, 0xed,
0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0x76, 0x47, 0x15, 0x51, 0x67, 0x02, 0x00, 0x00,
}
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