Skip to content

Commit 55c9b06

Browse files
committed
Added json output to 'lib update index'
1 parent e387859 commit 55c9b06

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

Diff for: internal/cli/feedback/result/rpc.go

+10
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,16 @@ func NewUpdateIndexResponse_ResultResult(resp *rpc.UpdateIndexResponse_Result) *
10761076
}
10771077
}
10781078

1079+
type UpdateLibrariesIndexResponse_ResultResult struct {
1080+
LibrariesIndex *IndexUpdateReportResult `json:"libraries_index"`
1081+
}
1082+
1083+
func NewUpdateLibrariesIndexResponse_ResultResult(resp *rpc.UpdateLibrariesIndexResponse_Result) *UpdateLibrariesIndexResponse_ResultResult {
1084+
return &UpdateLibrariesIndexResponse_ResultResult{
1085+
LibrariesIndex: NewIndexUpdateReportResult(resp.GetLibrariesIndex()),
1086+
}
1087+
}
1088+
10791089
type IndexUpdateReportResult struct {
10801090
IndexURL string `json:"index_url"`
10811091
Status IndexUpdateReport_Status `json:"status"`

Diff for: internal/cli/feedback/result/rpc_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ func TestAllFieldAreMapped(t *testing.T) {
226226
updateIndexResponse_ResultResult := result.NewUpdateIndexResponse_ResultResult(updateIndexResponse_ResultRpc)
227227
mustContainsAllPropertyOfRpcStruct(t, updateIndexResponse_ResultRpc, updateIndexResponse_ResultResult)
228228

229+
updateLibrariesIndexResponse_ResultRpc := &rpc.UpdateLibrariesIndexResponse_Result{}
230+
updateLibrariesIndexResponse_ResultResult := result.NewUpdateLibrariesIndexResponse_ResultResult(updateLibrariesIndexResponse_ResultRpc)
231+
mustContainsAllPropertyOfRpcStruct(t, updateLibrariesIndexResponse_ResultRpc, updateLibrariesIndexResponse_ResultResult)
232+
229233
indexUpdateReportRpc := &rpc.IndexUpdateReport{}
230234
indexUpdateReportResult := result.NewIndexUpdateReportResult(indexUpdateReportRpc)
231235
mustContainsAllPropertyOfRpcStruct(t, indexUpdateReportRpc, indexUpdateReportResult)

Diff for: internal/cli/lib/update_index.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/arduino/arduino-cli/commands"
2323
"github.com/arduino/arduino-cli/internal/cli/feedback"
24+
"github.com/arduino/arduino-cli/internal/cli/feedback/result"
2425
"github.com/arduino/arduino-cli/internal/cli/instance"
2526
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2627
"github.com/sirupsen/logrus"
@@ -42,15 +43,29 @@ func initUpdateIndexCommand() *cobra.Command {
4243
func runUpdateIndexCommand(cmd *cobra.Command, args []string) {
4344
inst := instance.CreateAndInit()
4445
logrus.Info("Executing `arduino-cli lib update-index`")
45-
UpdateIndex(inst)
46+
resp := UpdateIndex(inst)
47+
feedback.PrintResult(&libUpdateIndexResult{result.NewUpdateLibrariesIndexResponse_ResultResult(resp)})
4648
}
4749

4850
// UpdateIndex updates the index of libraries.
49-
func UpdateIndex(inst *rpc.Instance) {
50-
_, err := commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexRequest{
51+
func UpdateIndex(inst *rpc.Instance) *rpc.UpdateLibrariesIndexResponse_Result {
52+
resp, err := commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexRequest{
5153
Instance: inst,
5254
}, feedback.ProgressBar())
5355
if err != nil {
5456
feedback.Fatal(tr("Error updating library index: %v", err), feedback.ErrGeneric)
5557
}
58+
return resp
59+
}
60+
61+
type libUpdateIndexResult struct {
62+
*result.UpdateLibrariesIndexResponse_ResultResult
63+
}
64+
65+
func (l *libUpdateIndexResult) String() string {
66+
return ""
67+
}
68+
69+
func (l *libUpdateIndexResult) Data() interface{} {
70+
return l
5671
}

0 commit comments

Comments
 (0)