mirror of https://github.com/docker/docs.git
Sort `machine ls` output by machine name
Signed-off-by: Guillaume Giamarchi <guillaume.giamarchi@gmail.com>
This commit is contained in:
parent
932779fed1
commit
1547a48dde
28
commands.go
28
commands.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
@ -115,6 +116,8 @@ func (cli *DockerCli) CmdLs(args ...string) error {
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
|
|
||||||
|
hostStateList := []HostState{}
|
||||||
|
|
||||||
for _, host := range hostList {
|
for _, host := range hostList {
|
||||||
host := host
|
host := host
|
||||||
if *quiet {
|
if *quiet {
|
||||||
|
@ -142,19 +145,32 @@ func (cli *DockerCli) CmdLs(args ...string) error {
|
||||||
host.Name, err)
|
host.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
activeString := ""
|
hostStateList = append(hostStateList, HostState{
|
||||||
if isActive {
|
Name: host.Name,
|
||||||
activeString = "*"
|
Active: isActive,
|
||||||
}
|
DriverName: host.Driver.DriverName(),
|
||||||
|
State: currentState,
|
||||||
|
URL: url,
|
||||||
|
})
|
||||||
|
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
|
|
||||||
host.Name, activeString, host.Driver.DriverName(), currentState, url)
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
sort.Sort(HostStateByName(hostStateList))
|
||||||
|
|
||||||
|
for _, hostState := range hostStateList {
|
||||||
|
activeString := ""
|
||||||
|
if hostState.Active {
|
||||||
|
activeString = "*"
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
|
||||||
|
hostState.Name, activeString, hostState.DriverName, hostState.State, hostState.URL)
|
||||||
|
}
|
||||||
|
|
||||||
w.Flush()
|
w.Flush()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
24
host.go
24
host.go
|
@ -7,9 +7,11 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/machine/drivers"
|
"github.com/docker/machine/drivers"
|
||||||
|
"github.com/docker/machine/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -24,6 +26,28 @@ type Host struct {
|
||||||
storePath string
|
storePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HostState struct {
|
||||||
|
Name string
|
||||||
|
Active bool
|
||||||
|
DriverName string
|
||||||
|
State state.State
|
||||||
|
URL string
|
||||||
|
}
|
||||||
|
|
||||||
|
type HostStateByName []HostState
|
||||||
|
|
||||||
|
func (h HostStateByName) Len() int {
|
||||||
|
return len(h)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HostStateByName) Swap(i, j int) {
|
||||||
|
h[i], h[j] = h[j], h[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HostStateByName) Less(i, j int) bool {
|
||||||
|
return strings.ToLower(h[i].Name) < strings.ToLower(h[j].Name)
|
||||||
|
}
|
||||||
|
|
||||||
type hostConfig struct {
|
type hostConfig struct {
|
||||||
DriverName string
|
DriverName string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue