@@ -19,11 +19,15 @@ package core
19
19
20
20
import (
21
21
"context"
22
+ "fmt"
23
+ "os"
24
+ "sort"
22
25
23
26
"strings"
24
27
25
28
"github.com/arduino/arduino-cli/cli"
26
29
"github.com/arduino/arduino-cli/commands/core"
30
+ "github.com/arduino/arduino-cli/common/formatter"
27
31
"github.com/arduino/arduino-cli/output"
28
32
"github.com/arduino/arduino-cli/rpc"
29
33
"github.com/sirupsen/logrus"
@@ -46,8 +50,30 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
46
50
logrus .Info ("Executing `arduino core search`" )
47
51
instance := cli .CreateInstance ()
48
52
arguments := strings .ToLower (strings .Join (args , " " ))
49
- core .PlatformSearch (context .Background (), & rpc.PlatformSearchReq {
53
+ resp , err := core .PlatformSearch (context .Background (), & rpc.PlatformSearchReq {
50
54
Instance : instance ,
51
55
SearchArgs : arguments ,
52
56
}, output .NewTaskProgressCB ())
57
+ if err != nil {
58
+ formatter .PrintError (err , "Error saerching for platforms" )
59
+ os .Exit (cli .ErrGeneric )
60
+ }
61
+ coreslist := resp .GetSearchOutput ()
62
+ if coreslist != nil && len (coreslist ) > 0 {
63
+ if cli .OutputJSONOrElse (coreslist ) {
64
+ outputSearchCores (coreslist )
65
+ }
66
+ }
67
+ }
68
+
69
+ func outputSearchCores (cores []* rpc.SearchOutput ) {
70
+ table := output .NewTable ()
71
+ table .AddRow ("ID" , "Version" , "Name" )
72
+ sort .Slice (cores , func (i , j int ) bool {
73
+ return cores [i ].ID < cores [j ].ID
74
+ })
75
+ for _ , item := range cores {
76
+ table .AddRow (item .GetID (), item .GetVersion (), item .GetName ())
77
+ }
78
+ fmt .Print (table .Render ())
53
79
}
0 commit comments