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 4b01df1787
commit ed31e0a5f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 ( import (
"fmt" "fmt"
"sort"
"strings" "strings"
"github.com/hashicorp/nomad/api" "github.com/hashicorp/nomad/api"
@ -84,6 +85,10 @@ func (c *OperatorRaftListCommand) Run(args []string) int {
// Format it as a nice table. // Format it as a nice table.
result := []string{"Node|ID|Address|State|Voter|RaftProtocol"} 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 { for _, s := range reply.Servers {
state := "follower" state := "follower"
if s.Leader { if s.Leader {