@@ -3,6 +3,7 @@ package commands
3
3
import (
4
4
"fmt"
5
5
"io"
6
+ "sort"
6
7
"strings"
7
8
"text/tabwriter"
8
9
"time"
@@ -53,28 +54,15 @@ func listCmd(dockerCli command.Cli) *cobra.Command {
53
54
54
55
func runList (dockerCli command.Cli , opts listOptions ) error {
55
56
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 ())
62
58
if err != nil {
63
59
return err
64
60
}
65
61
66
- installations , err := installationStore .List ()
67
- if err != nil {
68
- return err
69
- }
70
62
w := tabwriter .NewWriter (dockerCli .Out (), 0 , 0 , 1 , ' ' , 0 )
71
63
printHeaders (w )
72
64
73
- for _ , name := range installations {
74
- installation , err := installationStore .Read (name )
75
- if err != nil {
76
- return err
77
- }
65
+ for _ , installation := range installations {
78
66
printValues (w , installation )
79
67
}
80
68
return w .Flush ()
@@ -95,3 +83,31 @@ func printValues(w io.Writer, installation *store.Installation) {
95
83
}
96
84
fmt .Fprintln (w , strings .Join (values , "\t " ))
97
85
}
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