@@ -66,25 +66,30 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
6666 }
6767
6868 coreslist := resp .GetSearchOutput ()
69- if globals .OutputFormat == "json" {
70- feedback .PrintJSON (coreslist )
71- } else {
72- outputSearchCores (coreslist )
73- }
69+ feedback .PrintResult (searchResults {coreslist })
70+ }
71+
72+ // ouput from this command requires special formatting, let's create a dedicated
73+ // feedback.Result implementation
74+ type searchResults struct {
75+ platforms []* rpc.Platform
76+ }
77+
78+ func (sr searchResults ) Data () interface {} {
79+ return sr .platforms
7480}
7581
76- func outputSearchCores ( cores [] * rpc. Platform ) {
77- if len (cores ) > 0 {
82+ func ( sr searchResults ) String () string {
83+ if len (sr . platforms ) > 0 {
7884 t := table .New ()
7985 t .SetHeader ("ID" , "Version" , "Name" )
80- sort .Slice (cores , func (i , j int ) bool {
81- return cores [i ].ID < cores [j ].ID
86+ sort .Slice (sr . platforms , func (i , j int ) bool {
87+ return sr . platforms [i ].ID < sr . platforms [j ].ID
8288 })
83- for _ , item := range cores {
89+ for _ , item := range sr . platforms {
8490 t .AddRow (item .GetID (), item .GetLatest (), item .GetName ())
8591 }
86- feedback .Print (t .Render ())
87- } else {
88- feedback .Print ("No platforms matching your search." )
92+ return t .Render ()
8993 }
94+ return "No platforms matching your search."
9095}
0 commit comments