1818package board
1919
2020import (
21+ "context"
22+ "fmt"
23+ "os"
2124 "sort"
22- "strings"
2325
2426 "github.com/arduino/arduino-cli/cli"
27+ "github.com/arduino/arduino-cli/commands/board"
2528 "github.com/arduino/arduino-cli/common/formatter"
26- "github.com/arduino/arduino-cli/common/formatter/output"
29+ "github.com/arduino/arduino-cli/output"
30+ "github.com/arduino/arduino-cli/rpc"
2731 "github.com/spf13/cobra"
2832)
2933
@@ -45,36 +49,30 @@ func initListAllCommand() *cobra.Command {
4549
4650// runListAllCommand list all installed boards
4751func runListAllCommand (cmd * cobra.Command , args []string ) {
48- pm , _ := cli .InitPackageAndLibraryManager ()
52+ instance := cli .CreateInstance ()
4953
50- match := func (name string ) bool {
51- name = strings .ToLower (name )
52- for _ , term := range args {
53- if ! strings .Contains (name , strings .ToLower (term )) {
54- return false
55- }
56- }
57- return true
54+ list , err := board .BoardListAll (context .Background (), & rpc.BoardListAllReq {
55+ Instance : instance ,
56+ SearchArgs : args ,
57+ })
58+ if err != nil {
59+ formatter .PrintError (err , "Error listing boards" )
60+ os .Exit (cli .ErrGeneric )
5861 }
62+ if cli .OutputJSONOrElse (list ) {
63+ outputBoardListAll (list )
64+ }
65+ }
66+
67+ func outputBoardListAll (list * rpc.BoardListAllResp ) {
68+ sort .Slice (list .Boards , func (i , j int ) bool {
69+ return list .Boards [i ].GetName () < list .Boards [j ].GetName ()
70+ })
5971
60- list := & output.BoardList {}
61- for _ , targetPackage := range pm .GetPackages ().Packages {
62- for _ , platform := range targetPackage .Platforms {
63- platformRelease := pm .GetInstalledPlatformRelease (platform )
64- if platformRelease == nil {
65- continue
66- }
67- for _ , board := range platformRelease .Boards {
68- if ! match (board .Name ()) {
69- continue
70- }
71- list .Boards = append (list .Boards , & output.BoardListItem {
72- Name : board .Name (),
73- Fqbn : board .FQBN (),
74- })
75- }
76- }
72+ table := output .NewTable ()
73+ table .SetHeader ("Board Name" , "FQBN" )
74+ for _ , item := range list .GetBoards () {
75+ table .AddRow (item .GetName (), item .GetFQBN ())
7776 }
78- sort .Sort (list )
79- formatter .Print (list )
77+ fmt .Print (table .Render ())
8078}
0 commit comments