From 273b76aa12d4d9c9640f4d3998fec29179a9cb55 Mon Sep 17 00:00:00 2001 From: Dao Thanh Tung Date: Fri, 3 Mar 2023 05:16:30 +0800 Subject: [PATCH] cli: sort Node value in `nomad operator raft list-peers` command (#16221) Signed-off-by: dttung2905 --- .changelog/16221.txt | 3 +++ command/operator_raft_list.go | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 .changelog/16221.txt 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 {