Sort members in by name for consul members

This commit is contained in:
Adam Renberg 2015-05-22 10:37:54 +02:00
parent 6aa21152d1
commit 7d0959b34e
1 changed files with 9 additions and 0 deletions

View File

@ -96,6 +96,8 @@ func (c *MembersCommand) Run(args []string) int {
return 2
}
sort.Sort(ByMemberName(members))
// Generate the output
var result []string
if detailed {
@ -111,6 +113,13 @@ func (c *MembersCommand) Run(args []string) int {
return 0
}
// so we can sort members by name
type ByMemberName []agent.Member
func (m ByMemberName) Len() int { return len(m) }
func (m ByMemberName) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
func (m ByMemberName) Less(i, j int) bool { return m[i].Name < m[j].Name }
// standardOutput is used to dump the most useful information about nodes
// in a more human-friendly format
func (c *MembersCommand) standardOutput(members []agent.Member) []string {