From ba6e13b5d09a056786f62b99061312c71d414906 Mon Sep 17 00:00:00 2001 From: Michael Lynch Date: Sun, 28 Nov 2021 11:19:50 -0500 Subject: [PATCH] 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. --- cmd/litestream/snapshots.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/litestream/snapshots.go b/cmd/litestream/snapshots.go index 72e67a5..574ec64 100644 --- a/cmd/litestream/snapshots.go +++ b/cmd/litestream/snapshots.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "os" + "sort" "text/tabwriter" "time" @@ -85,6 +86,8 @@ func (c *SnapshotsCommand) Run(ctx context.Context, args []string) (err error) { log.Printf("cannot determine snapshots: %s", err) 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 { fmt.Fprintf(w, "%s\t%s\t%d\t%d\t%s\n", r.Name(),