-
Notifications
You must be signed in to change notification settings - Fork 5
/
command_destroy.go
60 lines (52 loc) · 1.52 KB
/
command_destroy.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
package vagrant
// A DestroyCommand specifies the options and output of vagrant destroy.
type DestroyCommand struct {
BaseCommand
MachineNameArgument
ErrorResponse
// Destroy without confirmation (defaults to true because, when false,
// vagrant will try to ask for confirmation, but can't because it's running
// without a TTY so it errors).
Force bool
// Enable parallelism if the provider supports it (automatically enables
// force, default: false)
Parallel bool
}
// Destroy will destroy the vagrant machines. After setting options as
// appropriate, you must call Run() or Start() followed by Wait() to execute.
// Errors will be recorded in Error.
func (client *VagrantClient) Destroy() *DestroyCommand {
return &DestroyCommand{
BaseCommand: newBaseCommand(client),
ErrorResponse: newErrorResponse(),
Force: true,
}
}
func (cmd *DestroyCommand) buildArguments() []string {
args := []string{}
if cmd.Force {
args = append(args, "--force")
}
if cmd.Parallel {
args = append(args, "--parallel")
}
return cmd.appendMachineName(args)
}
func (cmd *DestroyCommand) init() error {
args := cmd.buildArguments()
return cmd.BaseCommand.init(&cmd.ErrorResponse, "destroy", args...)
}
// Run the command
func (cmd *DestroyCommand) Run() error {
if err := cmd.Start(); err != nil {
return err
}
return cmd.Wait()
}
// Start the command. You must call Wait() to complete execution.
func (cmd *DestroyCommand) Start() error {
if err := cmd.init(); err != nil {
return err
}
return cmd.BaseCommand.Start()
}