@@ -175,7 +175,7 @@ func printCsv(response map[string]interface{}) {
175175 }
176176}
177177
178- func filterResponse (response map [string ]interface {}, filter []string ) map [string ]interface {} {
178+ func filterResponse (response map [string ]interface {}, filter []string , outputType string ) map [string ]interface {} {
179179 if filter == nil || len (filter ) == 0 {
180180 return response
181181 }
@@ -195,11 +195,19 @@ func filterResponse(response map[string]interface{}, filter []string) map[string
195195 }
196196 filteredRow := make (map [string ]interface {})
197197 for _ , filterKey := range filter {
198+ if len (strings .TrimSpace (filterKey )) == 0 {
199+ continue
200+ }
198201 for field := range row {
199202 if filterKey == field {
200203 filteredRow [field ] = row [field ]
201204 }
202205 }
206+ if outputType == config .COLUMN || outputType == config .CSV || outputType == config .TABLE {
207+ if _ , ok := filteredRow [filterKey ]; ! ok {
208+ filteredRow [filterKey ] = ""
209+ }
210+ }
203211 }
204212 filteredRows = append (filteredRows , filteredRow )
205213 }
@@ -214,7 +222,7 @@ func filterResponse(response map[string]interface{}, filter []string) map[string
214222}
215223
216224func printResult (outputType string , response map [string ]interface {}, filter []string ) {
217- response = filterResponse (response , filter )
225+ response = filterResponse (response , filter , outputType )
218226 switch outputType {
219227 case config .JSON :
220228 printJSON (response )
0 commit comments