mirror of
https://github.com/status-im/consul.git
synced 2025-02-13 14:16:35 +00:00
command/members: USe the columnize library for members
This commit is contained in:
parent
e914c0a70b
commit
76578ea752
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hashicorp/consul/command/agent"
|
"github.com/hashicorp/consul/command/agent"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
|
"github.com/ryanuber/columnize"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -85,6 +86,7 @@ func (c *MembersCommand) Run(args []string) int {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result := make([]string, 0, len(members))
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
// Skip the non-matching members
|
// Skip the non-matching members
|
||||||
if !roleRe.MatchString(member.Tags["role"]) || !statusRe.MatchString(member.Status) {
|
if !roleRe.MatchString(member.Tags["role"]) || !statusRe.MatchString(member.Status) {
|
||||||
@ -99,17 +101,21 @@ func (c *MembersCommand) Run(args []string) int {
|
|||||||
tags := strings.Join(tagPairs, ",")
|
tags := strings.Join(tagPairs, ",")
|
||||||
|
|
||||||
addr := net.TCPAddr{IP: member.Addr, Port: int(member.Port)}
|
addr := net.TCPAddr{IP: member.Addr, Port: int(member.Port)}
|
||||||
c.Ui.Output(fmt.Sprintf("%s %s %s %s",
|
line := fmt.Sprintf("%s|%s|%s|%s",
|
||||||
member.Name, addr.String(), member.Status, tags))
|
member.Name, addr.String(), member.Status, tags)
|
||||||
|
|
||||||
if detailed {
|
if detailed {
|
||||||
c.Ui.Output(fmt.Sprintf(" Protocol Version: %d",
|
line += fmt.Sprintf(
|
||||||
member.DelegateCur))
|
"|Protocol Version: %d|Available Protocol Range: [%d, %d]",
|
||||||
c.Ui.Output(fmt.Sprintf(" Available Protocol Range: [%d, %d]",
|
member.DelegateCur, member.DelegateMin, member.DelegateMax)
|
||||||
member.DelegateMin, member.DelegateMax))
|
|
||||||
}
|
}
|
||||||
|
result = append(result, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate the columnized version
|
||||||
|
output, _ := columnize.SimpleFormat(result)
|
||||||
|
c.Ui.Output(string(output))
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user