From 81d75ccba4f7c764b2c39fa44cea5fee566742de Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 24 Jan 2014 13:21:41 +0400 Subject: [PATCH] Sort snapshots when listing. --- cmd_snapshot.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd_snapshot.go b/cmd_snapshot.go index fd4fac64..6f151b4e 100644 --- a/cmd_snapshot.go +++ b/cmd_snapshot.go @@ -6,6 +6,7 @@ import ( "github.com/gonuts/flag" "github.com/smira/aptly/debian" "github.com/wsxiaoys/terminal/color" + "sort" "strings" ) @@ -58,11 +59,21 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error { if snapshotCollection.Len() > 0 { fmt.Printf("List of snapshots:\n") + + snapshots := make(sort.StringSlice, snapshotCollection.Len()) + + i := 0 snapshotCollection.ForEach(func(snapshot *debian.Snapshot) error { - fmt.Printf(" * %s\n", snapshot) + snapshots[i] = snapshot.String() + i++ return nil }) + sort.Strings(snapshots) + for _, snapshot := range snapshots { + fmt.Printf(" * %s\n", snapshot) + } + fmt.Printf("\nTo get more information about snapshot, run `aptly snapshot show `.\n") } else { fmt.Printf("\nNo snapshots found, create one with `aptly snapshot create...`.\n")