From 219e67d9e0def6bc6a266d6a4720b613073f6225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Pawe=C5=82=20G=C5=82azik?= Date: Sat, 12 Dec 2015 13:39:16 +0100 Subject: [PATCH 1/3] Sort output of agent-info --- command/agent_info.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/command/agent_info.go b/command/agent_info.go index a36d835391b..abf83c4f81a 100644 --- a/command/agent_info.go +++ b/command/agent_info.go @@ -2,6 +2,7 @@ package command import ( "fmt" + "sort" "strings" ) @@ -53,14 +54,26 @@ func (c *AgentInfoCommand) Run(args []string) int { return 1 } + // Sort and output agent info var stats map[string]interface{} stats, _ = info["stats"] + stats_keys := make([]string, 0, len(stats)) + for key := range stats { + stats_keys = append(stats_keys, key) + } + sort.Strings(stats_keys) + + for _, key := range stats_keys { + c.Ui.Output(key) + d, _ := stats[key].(map[string]interface{}) + d_keys := make([]string, 0, len(d)) + for key := range d { + d_keys = append(d_keys, key) + } + sort.Strings(d_keys) - for section, data := range stats { - c.Ui.Output(section) - d, _ := data.(map[string]interface{}) - for k, v := range d { - c.Ui.Output(fmt.Sprintf(" %s = %v", k, v)) + for _, key := range d_keys { + c.Ui.Output(fmt.Sprintf(" %s = %v", key, d[key])) } } From 8e2633d81c539793a752ffd80d532c46ab53c0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Pawe=C5=82=20G=C5=82azik?= Date: Thu, 17 Dec 2015 23:53:33 +0100 Subject: [PATCH 2/3] small refactor --- command/agent_info.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/command/agent_info.go b/command/agent_info.go index abf83c4f81a..c4b290787a5 100644 --- a/command/agent_info.go +++ b/command/agent_info.go @@ -57,23 +57,23 @@ func (c *AgentInfoCommand) Run(args []string) int { // Sort and output agent info var stats map[string]interface{} stats, _ = info["stats"] - stats_keys := make([]string, 0, len(stats)) + statsKeys := make([]string, 0, len(stats)) for key := range stats { - stats_keys = append(stats_keys, key) + statsKeys = append(statsKeys, key) } - sort.Strings(stats_keys) + sort.Strings(statsKeys) - for _, key := range stats_keys { + for _, key := range statsKeys { c.Ui.Output(key) - d, _ := stats[key].(map[string]interface{}) - d_keys := make([]string, 0, len(d)) - for key := range d { - d_keys = append(d_keys, key) + statsData, _ := stats[key].(map[string]interface{}) + statsDataKeys := make([]string, 0, len(statsData)) + for key := range statsData { + statsDataKeys = append(statsDataKeys, key) } - sort.Strings(d_keys) + sort.Strings(statsDataKeys) - for _, key := range d_keys { - c.Ui.Output(fmt.Sprintf(" %s = %v", key, d[key])) + for _, key := range statsDataKeys { + c.Ui.Output(fmt.Sprintf(" %s = %v", key, statsData[key])) } } From c8a25c6a8b55e330b270496641af1ddf5734db03 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 21 Dec 2015 15:10:49 -0800 Subject: [PATCH 3/3] Fix append issue --- command/agent_info.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/command/agent_info.go b/command/agent_info.go index c4b290787a5..98231df9fd8 100644 --- a/command/agent_info.go +++ b/command/agent_info.go @@ -66,9 +66,11 @@ func (c *AgentInfoCommand) Run(args []string) int { for _, key := range statsKeys { c.Ui.Output(key) statsData, _ := stats[key].(map[string]interface{}) - statsDataKeys := make([]string, 0, len(statsData)) + statsDataKeys := make([]string, len(statsData)) + i := 0 for key := range statsData { - statsDataKeys = append(statsDataKeys, key) + statsDataKeys[i] = key + i++ } sort.Strings(statsDataKeys)