diff --git a/.changelog/16221.txt b/.changelog/16221.txt new file mode 100644 index 000000000..75ebc9cb4 --- /dev/null +++ b/.changelog/16221.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: Sort output by Node name of the command `nomad operator raft list-peers` +``` diff --git a/command/operator_raft_list.go b/command/operator_raft_list.go index 27a6aee64..2e235e255 100644 --- a/command/operator_raft_list.go +++ b/command/operator_raft_list.go @@ -2,6 +2,7 @@ package command import ( "fmt" + "sort" "strings" "github.com/hashicorp/nomad/api" @@ -84,6 +85,10 @@ func (c *OperatorRaftListCommand) Run(args []string) int { // Format it as a nice table. result := []string{"Node|ID|Address|State|Voter|RaftProtocol"} + sort.Slice(reply.Servers, func(i, j int) bool { + return reply.Servers[i].Node < reply.Servers[j].Node + }) + for _, s := range reply.Servers { state := "follower" if s.Leader {