Skip to content

Commit a6ee865

Browse files
committed
add fix for #152
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 9999507 commit a6ee865

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

cmd/output.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,27 @@ func printText(response map[string]interface{}) {
6666
format := "text"
6767
for k, v := range response {
6868
valueType := reflect.TypeOf(v)
69-
if valueType.Kind() == reflect.Slice {
70-
fmt.Printf("%v:\n", k)
71-
for idx, item := range v.([]interface{}) {
72-
if idx > 0 {
73-
fmt.Println("================================================================================")
74-
}
75-
row, isMap := item.(map[string]interface{})
76-
if isMap {
77-
for field, value := range row {
78-
fmt.Printf("%s = %v\n", field, jsonify(value, format))
69+
if valueType.Kind() == reflect.Slice || valueType.Kind() == reflect.Map {
70+
items, ok := getItemsFromValue(v)
71+
if ok {
72+
fmt.Printf("%v:\n", k)
73+
for idx, item := range items {
74+
if idx > 0 {
75+
fmt.Println("================================================================================")
76+
}
77+
row, isMap := item.(map[string]interface{})
78+
if isMap {
79+
for field, value := range row {
80+
fmt.Printf("%s = %v\n", field, jsonify(value, format))
81+
}
82+
} else {
83+
fmt.Printf("%v\n", item)
7984
}
80-
} else {
81-
fmt.Printf("%v\n", item)
8285
}
86+
return
8387
}
84-
} else {
85-
fmt.Printf("%v = %v\n", k, jsonify(v, format))
8688
}
89+
fmt.Printf("%v = %v\n", k, jsonify(v, format))
8790
}
8891
}
8992

@@ -92,8 +95,8 @@ func printTable(response map[string]interface{}, filter []string) {
9295
table := tablewriter.NewWriter(os.Stdout)
9396
for k, v := range response {
9497
valueType := reflect.TypeOf(v)
95-
if valueType.Kind() == reflect.Slice {
96-
items, ok := v.([]interface{})
98+
if valueType.Kind() == reflect.Slice || valueType.Kind() == reflect.Map {
99+
items, ok := getItemsFromValue(v)
97100
if !ok {
98101
continue
99102
}
@@ -134,7 +137,7 @@ func printColumn(response map[string]interface{}, filter []string) {
134137
for _, v := range response {
135138
valueType := reflect.TypeOf(v)
136139
if valueType.Kind() == reflect.Slice || valueType.Kind() == reflect.Map {
137-
items, ok := v.([]interface{})
140+
items, ok := getItemsFromValue(v)
138141
if !ok {
139142
continue
140143
}
@@ -173,7 +176,7 @@ func printCsv(response map[string]interface{}, filter []string) {
173176
for _, v := range response {
174177
valueType := reflect.TypeOf(v)
175178
if valueType.Kind() == reflect.Slice || valueType.Kind() == reflect.Map {
176-
items, ok := v.([]interface{})
179+
items, ok := getItemsFromValue(v)
177180
if !ok {
178181
continue
179182
}

0 commit comments

Comments
 (0)