Skip to content

Commit 9f44678

Browse files
author
Massimiliano Pippi
committed
fix regression on search output
1 parent 183a159 commit 9f44678

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

cli/lib/search.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,8 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
6363
os.Exit(errorcodes.ErrGeneric)
6464
}
6565

66-
// get a sorted slice of results
67-
results := searchResp.GetLibraries()
68-
sort.Slice(results, func(i, j int) bool {
69-
return results[i].Name < results[j].Name
70-
})
71-
7266
feedback.PrintResult(result{
73-
results: results,
67+
results: searchResp,
7468
namesOnly: searchFlags.namesOnly,
7569
})
7670

@@ -80,7 +74,7 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
8074
// ouput from this command requires special formatting, let's create a dedicated
8175
// feedback.Result implementation
8276
type result struct {
83-
results []*rpc.SearchedLibrary
77+
results *rpc.LibrarySearchResp
8478
namesOnly bool
8579
}
8680

@@ -95,7 +89,8 @@ func (res result) Data() interface{} {
9589
}
9690

9791
names := []LibName{}
98-
for _, lsr := range res.results {
92+
results := res.results.GetLibraries()
93+
for _, lsr := range results {
9994
names = append(names, LibName{lsr.Name})
10095
}
10196

@@ -108,13 +103,19 @@ func (res result) Data() interface{} {
108103
}
109104

110105
func (res result) String() string {
111-
if len(res.results) == 0 {
106+
results := res.results.GetLibraries()
107+
if len(results) == 0 {
112108
return "No libraries matching your search."
113109
}
114110

111+
// get a sorted slice of results
112+
sort.Slice(results, func(i, j int) bool {
113+
return results[i].Name < results[j].Name
114+
})
115+
115116
var out strings.Builder
116117

117-
for _, lsr := range res.results {
118+
for _, lsr := range results {
118119
out.WriteString(fmt.Sprintf("Name: \"%s\"\n", lsr.Name))
119120
if res.namesOnly {
120121
continue

0 commit comments

Comments
 (0)