-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.go
61 lines (50 loc) · 994 Bytes
/
remove.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
type removeOptions struct {
*globalOptions
name string
}
func newRemoveCommand() *cobra.Command {
cmd := &cobra.Command{
Args: cobra.ExactArgs(1),
Short: "Remove a virtual machine",
Use: "remove [name]",
Aliases: []string{
"rm",
},
RunE: func(cmd *cobra.Command, args []string) error {
globalOptions, err := newGlobalOptions(cmd)
if err != nil {
return err
}
opts := &removeOptions{
name: args[0],
globalOptions: globalOptions,
}
if err := runRemove(opts); err != nil {
fmt.Printf("Error: %s\n", err)
os.Exit(1)
}
return nil
},
}
return cmd
}
func runRemove(opts *removeOptions) error {
eng, err := newEngine(opts.globalOptions)
if err != nil {
return err
}
if err != nil {
return err
}
vm := eng.FindVirtualMachine(opts.name)
if vm == nil {
return fmt.Errorf(`virtual machine "%s" not found`, opts.name)
}
return vm.Remove()
}