Skip to content

Commit e24bbd0

Browse files
committed
output: display key in filtered output for csv, column and table
Fixes #63 Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 98fa493 commit e24bbd0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cmd/output.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

216224
func 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)

config/about.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (c *Config) Name() string {
2626

2727
// Version CLI
2828
func (c *Config) Version() string {
29-
return "6.1.0-alpha"
29+
return "6.1.0"
3030
}
3131

3232
// PrintHeader prints startup message in CLI mode

0 commit comments

Comments
 (0)