cli: sort Node value in nomad operator raft list-peers command (#16221)

Signed-off-by: dttung2905 <ttdao.2015@accountancy.smu.edu.sg>
This commit is contained in:
Dao Thanh Tung
2023-03-03 05:16:30 +08:00
committed by GitHub
parent f553dc8654
commit 273b76aa12
2 changed files with 8 additions and 0 deletions

3
.changelog/16221.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
cli: Sort output by Node name of the command `nomad operator raft list-peers`
```

View File

@@ -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 {