@@ -62,30 +62,30 @@ func printJSON(response map[string]interface{}) {
6262 enc .Encode (response )
6363}
6464
65- func getItemsFromValue (v interface {}) ([]interface {}, bool ) {
66- valueType := reflect .TypeOf (v )
67- if valueType . Kind () == reflect .Slice {
65+ func getItemsFromValue (v interface {}) ([]interface {}, reflect. Kind , bool ) {
66+ valueKind := reflect .TypeOf (v ). Kind ( )
67+ if valueKind == reflect .Slice {
6868 sliceItems , ok := v .([]interface {})
6969 if ! ok {
70- return nil , false
70+ return nil , valueKind , false
7171 }
72- return sliceItems , true
73- } else if valueType . Kind () == reflect .Map {
72+ return sliceItems , valueKind , true
73+ } else if valueKind == reflect .Map {
7474 mapItem , ok := v .(map [string ]interface {})
7575 if ! ok {
76- return nil , false
76+ return nil , valueKind , false
7777 }
78- return []interface {}{mapItem }, true
78+ return []interface {}{mapItem }, valueKind , true
7979 }
80- return nil , false
80+ return nil , valueKind , false
8181}
8282
8383func printText (response map [string ]interface {}) {
8484 format := "text"
8585 for k , v := range response {
8686 valueType := reflect .TypeOf (v )
8787 if valueType .Kind () == reflect .Slice || valueType .Kind () == reflect .Map {
88- items , ok := getItemsFromValue (v )
88+ items , _ , ok := getItemsFromValue (v )
8989 if ok {
9090 fmt .Printf ("%v:\n " , k )
9191 for idx , item := range items {
@@ -114,7 +114,7 @@ func printTable(response map[string]interface{}, filter []string) {
114114 for k , v := range response {
115115 valueType := reflect .TypeOf (v )
116116 if valueType .Kind () == reflect .Slice || valueType .Kind () == reflect .Map {
117- items , ok := getItemsFromValue (v )
117+ items , _ , ok := getItemsFromValue (v )
118118 if ! ok {
119119 continue
120120 }
@@ -155,7 +155,7 @@ func printColumn(response map[string]interface{}, filter []string) {
155155 for _ , v := range response {
156156 valueType := reflect .TypeOf (v )
157157 if valueType .Kind () == reflect .Slice || valueType .Kind () == reflect .Map {
158- items , ok := getItemsFromValue (v )
158+ items , _ , ok := getItemsFromValue (v )
159159 if ! ok {
160160 continue
161161 }
@@ -194,7 +194,7 @@ func printCsv(response map[string]interface{}, filter []string) {
194194 for _ , v := range response {
195195 valueType := reflect .TypeOf (v )
196196 if valueType .Kind () == reflect .Slice || valueType .Kind () == reflect .Map {
197- items , ok := getItemsFromValue (v )
197+ items , _ , ok := getItemsFromValue (v )
198198 if ! ok {
199199 continue
200200 }
@@ -247,7 +247,7 @@ func filterResponse(response map[string]interface{}, filter []string, excludeFil
247247 for key , value := range response {
248248 valueType := reflect .TypeOf (value )
249249 if valueType .Kind () == reflect .Slice || valueType .Kind () == reflect .Map {
250- items , ok := getItemsFromValue (value )
250+ items , originalKind , ok := getItemsFromValue (value )
251251 if ! ok {
252252 continue
253253 }
@@ -280,7 +280,11 @@ func filterResponse(response map[string]interface{}, filter []string, excludeFil
280280
281281 filteredRows = append (filteredRows , filteredRow )
282282 }
283- filteredResponse [key ] = filteredRows
283+ if originalKind == reflect .Map && len (filteredRows ) > 0 {
284+ filteredResponse [key ] = filteredRows [0 ]
285+ } else {
286+ filteredResponse [key ] = filteredRows
287+ }
284288 } else {
285289 filteredResponse [key ] = value
286290 }
0 commit comments