Refactoring: make snapshot sorting non-intrusive to collection contents. #168

This commit is contained in:
Andrey Smirnov
2015-01-22 22:01:00 +03:00
parent 7c3629337c
commit d828732307
5 changed files with 75 additions and 55 deletions
+6 -3
View File
@@ -17,10 +17,9 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error {
sortMethodString := cmd.Flag.Lookup("sort").Value.Get().(string)
collection := context.CollectionFactory().SnapshotCollection()
collection.Sort(sortMethodString)
if raw {
collection.ForEach(func(snapshot *deb.Snapshot) error {
collection.ForEachSorted(sortMethodString, func(snapshot *deb.Snapshot) error {
fmt.Printf("%s\n", snapshot.Name)
return nil
})
@@ -28,11 +27,15 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error {
if collection.Len() > 0 {
fmt.Printf("List of snapshots:\n")
collection.ForEach(func(snapshot *deb.Snapshot) error {
err = collection.ForEachSorted(sortMethodString, func(snapshot *deb.Snapshot) error {
fmt.Printf(" * %s\n", snapshot.String())
return nil
})
if err != nil {
return err
}
fmt.Printf("\nTo get more information about snapshot, run `aptly snapshot show <name>`.\n")
} else {
fmt.Printf("\nNo snapshots found, create one with `aptly snapshot create...`.\n")