@@ -3,6 +3,7 @@ package commands
33import (
44 "fmt"
55 "io"
6+ "sort"
67 "strings"
78 "text/tabwriter"
89 "time"
@@ -53,28 +54,15 @@ func listCmd(dockerCli command.Cli) *cobra.Command {
5354
5455func runList (dockerCli command.Cli , opts listOptions ) error {
5556 targetContext := getTargetContext (opts .targetContext , dockerCli .CurrentContext ())
56-
57- appstore , err := store .NewApplicationStore (config .Dir ())
58- if err != nil {
59- return err
60- }
61- installationStore , err := appstore .InstallationStore (targetContext )
57+ installations , err := getInstallations (targetContext , config .Dir ())
6258 if err != nil {
6359 return err
6460 }
6561
66- installations , err := installationStore .List ()
67- if err != nil {
68- return err
69- }
7062 w := tabwriter .NewWriter (dockerCli .Out (), 0 , 0 , 1 , ' ' , 0 )
7163 printHeaders (w )
7264
73- for _ , name := range installations {
74- installation , err := installationStore .Read (name )
75- if err != nil {
76- return err
77- }
65+ for _ , installation := range installations {
7866 printValues (w , installation )
7967 }
8068 return w .Flush ()
@@ -95,3 +83,31 @@ func printValues(w io.Writer, installation *store.Installation) {
9583 }
9684 fmt .Fprintln (w , strings .Join (values , "\t " ))
9785}
86+
87+ func getInstallations (targetContext , configDir string ) ([]* store.Installation , error ) {
88+ appstore , err := store .NewApplicationStore (configDir )
89+ if err != nil {
90+ return nil , err
91+ }
92+ installationStore , err := appstore .InstallationStore (targetContext )
93+ if err != nil {
94+ return nil , err
95+ }
96+ installationNames , err := installationStore .List ()
97+ if err != nil {
98+ return nil , err
99+ }
100+ installations := make ([]* store.Installation , len (installationNames ))
101+ for i , name := range installationNames {
102+ installation , err := installationStore .Read (name )
103+ if err != nil {
104+ return nil , err
105+ }
106+ installations [i ] = installation
107+ }
108+ // Sort installations with last modified first
109+ sort .Slice (installations , func (i , j int ) bool {
110+ return installations [i ].Modified .After (installations [j ].Modified )
111+ })
112+ return installations , nil
113+ }
0 commit comments