This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git


The following commit(s) were added to refs/heads/master by this push:
     new e24bbd0  output: display key in filtered output for csv, column and 
table
e24bbd0 is described below

commit e24bbd007dd00934cd71a81d6250c176a6696cec
Author: Rohit Yadav <rohit.ya...@shapeblue.com>
AuthorDate: Thu Jun 18 11:07:03 2020 +0530

    output: display key in filtered output for csv, column and table
    
    Fixes #63
    
    Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>
---
 cmd/output.go   | 12 ++++++++++--
 config/about.go |  2 +-
 2 files changed, 11 insertions(+), 3 deletions(-)

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 printCsv(response map[string]interface{}) {
        }
 }
 
-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 @@ func filterResponse(response map[string]interface{}, 
filter []string) map[string
                                }
                                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 filterResponse(response map[string]interface{}, filter 
[]string) map[string
 }
 
 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 @@ func (c *Config) Name() string {
 
 // Version CLI
 func (c *Config) Version() string {
-       return "6.1.0-alpha"
+       return "6.1.0"
 }
 
 // PrintHeader prints startup message in CLI mode

Reply via email to