-
Notifications
You must be signed in to change notification settings - Fork 5
/
command_up.go
71 lines (61 loc) · 1.72 KB
/
command_up.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
62
63
64
65
66
67
68
69
70
71
package vagrant
// UpCommand specifies options and output from vagrant up.
type UpCommand struct {
BaseCommand
UpResponse
ProvisioningArgument
// Destroy on error (default: true)
DestroyOnError bool
// Enable parallel execution if the provider supports it (default: true)
Parallel bool
// Provider to use (default: blank which means vagrant will use the default
// provider)
Provider string
// Install the provider if it isn't installed, if possible (default: false)
InstallProvider bool
}
// Run vagrant up. After setting options as appropriate, you must call Run()
// or Start() followed by Wait() to execute. Output will be in VMInfo or Error.
func (client *VagrantClient) Up() *UpCommand {
return &UpCommand{
BaseCommand: newBaseCommand(client),
UpResponse: newUpResponse(),
DestroyOnError: true,
Parallel: true,
InstallProvider: true,
}
}
func (cmd *UpCommand) buildArguments() []string {
args := cmd.ProvisioningArgument.buildArguments()
if !cmd.DestroyOnError {
args = append(args, "--no-destroy-on-error")
}
if !cmd.Parallel {
args = append(args, "--no-parallel")
}
if len(cmd.Provider) > 0 {
args = append(args, "--provider", cmd.Provider)
}
if !cmd.InstallProvider {
args = append(args, "--no-install-provider")
}
return args
}
func (cmd *UpCommand) init() error {
args := cmd.buildArguments()
return cmd.BaseCommand.init(&cmd.UpResponse, "up", args...)
}
// Run the command
func (cmd *UpCommand) Run() error {
if err := cmd.init(); err != nil {
return err
}
return cmd.BaseCommand.Run()
}
// Start the command. You must call Wait() to complete execution.
func (cmd *UpCommand) Start() error {
if err := cmd.init(); err != nil {
return err
}
return cmd.BaseCommand.Start()
}