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 #617

Merged
merged 4 commits into from
Dec 21, 2015
Merged
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
25 changes: 20 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,28 @@ 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, len(statsData))
i := 0
for key := range statsData {
statsDataKeys[i] = key
i++
}
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key is shadowed in a few places. It's obviously using the inner value but the shadowing is a bit awkward. Can we change these variables names so they don't shadow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to just commit to master making the desired name changes @cbednarski

c.Ui.Output(fmt.Sprintf(" %s = %v", key, statsData[key]))
}
}

Expand Down