Skip to content

Commit 8b9aa4d

Browse files
committed
account/list: Sort users by ID
1 parent 227ebb8 commit 8b9aa4d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pkg/util/util.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"log"
1111
"os"
12+
"sort"
1213
"strings"
1314
"syscall"
1415
"text/template"
@@ -156,10 +157,25 @@ type UserClaims struct {
156157
Version uint `json:"version"`
157158
}
158159

160+
type usersList []iam.User
161+
162+
func (l usersList) Len() int {
163+
return len(l)
164+
}
165+
func (l usersList) Less(i, j int) bool {
166+
return l[i].Id < l[j].Id
167+
}
168+
func (l usersList) Swap(i, j int) {
169+
l[i], l[j] = l[j], l[i]
170+
}
171+
159172
// PrintUsers renders a list of users (with various output options)
160173
func PrintUsers(users []iam.User, outputType string, single bool) error {
174+
sUsers := usersList(users)
175+
sort.Sort(sUsers)
176+
161177
var data interface{}
162-
data = users
178+
data = sUsers
163179
if single && len(users) == 1 {
164180
data = users[0]
165181
}

0 commit comments

Comments
 (0)