File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ package cmd
1919
2020import (
2121 "encoding/json"
22+ "encoding/csv"
2223 "fmt"
2324 "os"
2425 "reflect"
@@ -168,6 +169,7 @@ func printColumn(response map[string]interface{}, filter []string) {
168169
169170func printCsv (response map [string ]interface {}, filter []string ) {
170171 format := "csv"
172+ enc := csv .NewWriter (os .Stdout )
171173 for _ , v := range response {
172174 valueType := reflect .TypeOf (v )
173175 if valueType .Kind () == reflect .Slice || valueType .Kind () == reflect .Map {
@@ -191,16 +193,17 @@ func printCsv(response map[string]interface{}, filter []string) {
191193 }
192194 sort .Strings (header )
193195 }
194- fmt . Println ( strings . Join ( header , "," ) )
196+ enc . Write ( header )
195197 }
196198 var values []string
197199 for _ , key := range header {
198200 values = append (values , jsonify (row [key ], format ))
199201 }
200- fmt . Println ( strings . Join ( values , "," ) )
202+ enc . Write ( values )
201203 }
202204 }
203205 }
206+ enc .Flush ()
204207}
205208
206209func filterResponse (response map [string ]interface {}, filter []string , outputType string ) map [string ]interface {} {
You can’t perform that action at this time.
0 commit comments