Skip to content

Commit 494a924

Browse files
committed
Added output to new 'core search' command
1 parent 554160c commit 494a924

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cli/core/search.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ package core
1919

2020
import (
2121
"context"
22+
"fmt"
23+
"os"
24+
"sort"
2225

2326
"strings"
2427

2528
"github.com/arduino/arduino-cli/cli"
2629
"github.com/arduino/arduino-cli/commands/core"
30+
"github.com/arduino/arduino-cli/common/formatter"
2731
"github.com/arduino/arduino-cli/output"
2832
"github.com/arduino/arduino-cli/rpc"
2933
"github.com/sirupsen/logrus"
@@ -46,8 +50,30 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
4650
logrus.Info("Executing `arduino core search`")
4751
instance := cli.CreateInstance()
4852
arguments := strings.ToLower(strings.Join(args, " "))
49-
core.PlatformSearch(context.Background(), &rpc.PlatformSearchReq{
53+
resp, err := core.PlatformSearch(context.Background(), &rpc.PlatformSearchReq{
5054
Instance: instance,
5155
SearchArgs: arguments,
5256
}, 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())
5379
}

0 commit comments

Comments
 (0)