@@ -66,25 +66,30 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
66
66
}
67
67
68
68
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
74
80
}
75
81
76
- func outputSearchCores ( cores [] * rpc. Platform ) {
77
- if len (cores ) > 0 {
82
+ func ( sr searchResults ) String () string {
83
+ if len (sr . platforms ) > 0 {
78
84
t := table .New ()
79
85
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
82
88
})
83
- for _ , item := range cores {
89
+ for _ , item := range sr . platforms {
84
90
t .AddRow (item .GetID (), item .GetLatest (), item .GetName ())
85
91
}
86
- feedback .Print (t .Render ())
87
- } else {
88
- feedback .Print ("No platforms matching your search." )
92
+ return t .Render ()
89
93
}
94
+ return "No platforms matching your search."
90
95
}
0 commit comments