forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm.go
41 lines (33 loc) · 847 Bytes
/
rm.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
package commands
import (
"errors"
"fmt"
"github.com/docker/machine/cli"
"github.com/docker/machine/libmachine/log"
)
func cmdRm(c *cli.Context) error {
if len(c.Args()) == 0 {
cli.ShowCommandHelp(c, "rm")
return errors.New("You must specify a machine name")
}
force := c.Bool("force")
store := getStore(c)
for _, hostName := range c.Args() {
h, err := loadHost(store, hostName)
if err != nil {
return fmt.Errorf("Error removing host %q: %s", hostName, err)
}
if err := h.Driver.Remove(); err != nil {
if !force {
log.Errorf("Provider error removing machine %q: %s", hostName, err)
continue
}
}
if err := store.Remove(hostName); err != nil {
log.Errorf("Error removing machine %q from store: %s", hostName, err)
} else {
log.Infof("Successfully removed %s", hostName)
}
}
return nil
}