Skip to content

Commit 1d2e51a

Browse files
author
Massimiliano Pippi
committed
restore output format, make --names work with json too
1 parent 77b1ff3 commit 1d2e51a

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

cli/lib/search.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,26 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
6565
}
6666

6767
if globals.OutputFormat == "json" {
68-
feedback.PrintJSON(searchResp)
68+
if searchFlags.namesOnly {
69+
type LibName struct {
70+
Name string `json:"name,required"`
71+
}
72+
73+
type NamesOnly struct {
74+
Libraries []LibName `json:"libraries,required"`
75+
}
76+
77+
names := []LibName{}
78+
results := searchResp.GetLibraries()
79+
for _, lsr := range results {
80+
names = append(names, LibName{lsr.Name})
81+
}
82+
feedback.PrintJSON(NamesOnly{
83+
names,
84+
})
85+
} else {
86+
feedback.PrintJSON(searchResp)
87+
}
6988
} else {
7089
// get a sorted slice of results
7190
results := searchResp.GetLibraries()
@@ -87,7 +106,7 @@ func outputSearchedLibrary(results []*rpc.SearchedLibrary, namesOnly bool) {
87106
}
88107

89108
for _, lsr := range results {
90-
feedback.Printf("Name: '%s'", lsr.Name)
109+
feedback.Printf(`Name: "%s"`, lsr.Name)
91110
if namesOnly {
92111
continue
93112
}

0 commit comments

Comments
 (0)