Skip to content

Commit 6ecbadd

Browse files
committed
cli: sort the list command output by date
1 parent c89b94f commit 6ecbadd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cli/commands.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ func SubCmd(name, signature, description string) *flag.FlagSet {
129129
return flags
130130
}
131131

132+
type ByDate []*rpc.Mirror
133+
134+
func (d ByDate) Len() int { return len(d) }
135+
func (d ByDate) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
136+
func (d ByDate) Less(i, j int) bool { return d[i].StateSince.Seconds > d[j].StateSince.Seconds }
137+
132138
func (c *cli) CmdList(args ...string) error {
133139
cmd := SubCmd("list", "", "Get the list of mirrors")
134140
http := cmd.Bool("http", false, "Print HTTP addresses")
@@ -157,6 +163,8 @@ func (c *cli) CmdList(args ...string) error {
157163
log.Fatal("list error:", err)
158164
}
159165

166+
sort.Sort(ByDate(list.Mirrors))
167+
160168
w := new(tabwriter.Writer)
161169
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
162170
fmt.Fprint(w, "Identifier ")

0 commit comments

Comments
 (0)