Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort output of agent-info #572

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions command/agent_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"fmt"
"sort"
"strings"
)

Expand Down Expand Up @@ -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"]
statsKeys := make([]string, 0, len(stats))
for key := range stats {
statsKeys = append(statsKeys, key)
}
sort.Strings(statsKeys)

for _, key := range statsKeys {
c.Ui.Output(key)
statsData, _ := stats[key].(map[string]interface{})
statsDataKeys := make([]string, 0, len(statsData))
for key := range statsData {
statsDataKeys = append(statsDataKeys, key)
}
sort.Strings(statsDataKeys)

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 statsDataKeys {
c.Ui.Output(fmt.Sprintf(" %s = %v", key, statsData[key]))
}
}

Expand Down