output: display key in filtered output for csv, column and table
Fixes #63
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
diff --git a/cmd/output.go b/cmd/output.go
index 63b4404..91c434d 100644
--- a/cmd/output.go
+++ b/cmd/output.go
@@ -175,7 +175,7 @@
}
}
-func filterResponse(response map[string]interface{}, filter []string) map[string]interface{} {
+func filterResponse(response map[string]interface{}, filter []string, outputType string) map[string]interface{} {
if filter == nil || len(filter) == 0 {
return response
}
@@ -195,11 +195,19 @@
}
filteredRow := make(map[string]interface{})
for _, filterKey := range filter {
+ if len(strings.TrimSpace(filterKey)) == 0 {
+ continue
+ }
for field := range row {
if filterKey == field {
filteredRow[field] = row[field]
}
}
+ if outputType == config.COLUMN || outputType == config.CSV || outputType == config.TABLE {
+ if _, ok := filteredRow[filterKey]; !ok {
+ filteredRow[filterKey] = ""
+ }
+ }
}
filteredRows = append(filteredRows, filteredRow)
}
@@ -214,7 +222,7 @@
}
func printResult(outputType string, response map[string]interface{}, filter []string) {
- response = filterResponse(response, filter)
+ response = filterResponse(response, filter, outputType)
switch outputType {
case config.JSON:
printJSON(response)
diff --git a/config/about.go b/config/about.go
index b603ff2..c2a4384 100644
--- a/config/about.go
+++ b/config/about.go
@@ -26,7 +26,7 @@
// Version CLI
func (c *Config) Version() string {
- return "6.1.0-alpha"
+ return "6.1.0"
}
// PrintHeader prints startup message in CLI mode