forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
active.go
44 lines (34 loc) · 811 Bytes
/
active.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package commands
import (
"errors"
"fmt"
"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/persist"
)
var (
errNoActiveHost = errors.New("No active host found")
)
func cmdActive(c CommandLine, api libmachine.API) error {
if len(c.Args()) > 0 {
return ErrTooManyArguments
}
hosts, hostsInError, err := persist.LoadAllHosts(api)
if err != nil {
return fmt.Errorf("Error getting active host: %s", err)
}
items := getHostListItems(hosts, hostsInError)
active, err := activeHost(items)
if err != nil {
return err
}
fmt.Println(active.Name)
return nil
}
func activeHost(items []HostListItem) (HostListItem, error) {
for _, item := range items {
if item.ActiveHost || item.ActiveSwarm {
return item, nil
}
}
return HostListItem{}, errNoActiveHost
}