Sort output of snapshots in descending timestamp order
By default, the snapshots command seems to output in alphabetical order of hash, which isn't meaningful, as far as I can tell. This change modifies the order of the command output so that ./litestream snapshots returns snapshots from newest to oldest.
This commit is contained in:
committed by
Ben Johnson
parent
d09f4ef618
commit
ba6e13b5d0
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -85,6 +86,8 @@ func (c *SnapshotsCommand) Run(ctx context.Context, args []string) (err error) {
|
|||||||
log.Printf("cannot determine snapshots: %s", err)
|
log.Printf("cannot determine snapshots: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Sort snapshots by creation time from newest to oldest.
|
||||||
|
sort.Slice(infos, func(i, j int) bool { return infos[i].CreatedAt.After(infos[j].CreatedAt) })
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
fmt.Fprintf(w, "%s\t%s\t%d\t%d\t%s\n",
|
fmt.Fprintf(w, "%s\t%s\t%d\t%d\t%s\n",
|
||||||
r.Name(),
|
r.Name(),
|
||||||
|
|||||||
Reference in New Issue
Block a user