55 "fmt"
66 "os"
77 "os/exec"
8+ "sort"
89 "strings"
910 "sync"
1011 "text/tabwriter"
@@ -21,25 +22,25 @@ import (
2122 "github.com/docker/machine/state"
2223)
2324
24- type HostListItem struct {
25+ type hostListItem struct {
2526 Name string
2627 Active bool
2728 DriverName string
2829 State state.State
2930 URL string
3031}
3132
32- type HostListItemByName []HostListItem
33+ type hostListItemByName []hostListItem
3334
34- func (h HostListItemByName ) Len () int {
35+ func (h hostListItemByName ) Len () int {
3536 return len (h )
3637}
3738
38- func (h HostListItemByName ) Swap (i , j int ) {
39+ func (h hostListItemByName ) Swap (i , j int ) {
3940 h [i ], h [j ] = h [j ], h [i ]
4041}
4142
42- func (h HostListItemByName ) Less (i , j int ) bool {
43+ func (h hostListItemByName ) Less (i , j int ) bool {
4344 return strings .ToLower (h [i ].Name ) < strings .ToLower (h [j ].Name )
4445}
4546
@@ -176,6 +177,7 @@ var Commands = []cli.Command{
176177 }
177178
178179 wg := sync.WaitGroup {}
180+ items := []hostListItem {}
179181
180182 for _ , host := range hostList {
181183 host := host
@@ -204,19 +206,32 @@ var Commands = []cli.Command{
204206 host .Name , err )
205207 }
206208
207- activeString := ""
208- if isActive {
209- activeString = "*"
210- }
209+ items = append (items , hostListItem {
210+ Name : host .Name ,
211+ Active : isActive ,
212+ DriverName : host .Driver .DriverName (),
213+ State : currentState ,
214+ URL : url ,
215+ })
211216
212- fmt .Fprintf (w , "%s\t %s\t %s\t %s\t %s\n " ,
213- host .Name , activeString , host .Driver .DriverName (), currentState , url )
214217 wg .Done ()
215218 }()
216219 }
217220 }
218221
219222 wg .Wait ()
223+
224+ sort .Sort (hostListItemByName (items ))
225+
226+ for _ , item := range items {
227+ activeString := ""
228+ if item .Active {
229+ activeString = "*"
230+ }
231+ fmt .Fprintf (w , "%s\t %s\t %s\t %s\t %s\n " ,
232+ item .Name , activeString , item .DriverName , item .State , item .URL )
233+ }
234+
220235 w .Flush ()
221236 },
222237 },
0 commit comments