-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathup.go
More file actions
139 lines (105 loc) · 3.07 KB
/
up.go
File metadata and controls
139 lines (105 loc) · 3.07 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package cmd
import (
"flag"
"os"
"strings"
"github.com/hashicorp/cli"
"github.com/posener/complete"
"github.com/roots/trellis-cli/command"
"github.com/roots/trellis-cli/trellis"
)
type UpCommand struct {
UI cli.Ui
Trellis *trellis.Trellis
flags *flag.FlagSet
noGalaxy bool
noProvision bool
debug bool
}
func NewUpCommand(ui cli.Ui, trellis *trellis.Trellis) *UpCommand {
c := &UpCommand{UI: ui, Trellis: trellis}
c.init()
return c
}
func (c *UpCommand) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.flags.Usage = func() { c.UI.Info(c.Help()) }
c.flags.BoolVar(&c.noGalaxy, "no-galaxy", false, "Skip Ansible Galaxy install")
c.flags.BoolVar(&c.noProvision, "no-provision", false, "Skip provisioning")
c.flags.BoolVar(&c.debug, "debug", false, "Enable vagrant's debug mode")
}
func (c *UpCommand) Run(args []string) int {
if err := c.Trellis.LoadProject(); err != nil {
c.UI.Error(err.Error())
return 1
}
c.Trellis.CheckVirtualenv(c.UI)
if err := c.flags.Parse(args); err != nil {
return 1
}
args = c.flags.Args()
commandArgumentValidator := &CommandArgumentValidator{required: 0, optional: 0}
commandArgumentErr := commandArgumentValidator.validate(args)
if commandArgumentErr != nil {
c.UI.Error(commandArgumentErr.Error())
c.UI.Output(c.Help())
return 1
}
if !c.noGalaxy {
galaxyInstallCommand := &GalaxyInstallCommand{c.UI, c.Trellis}
galaxyInstallCommand.Run([]string{})
}
vagrantArgs := []string{"up"}
if c.noProvision {
vagrantArgs = append(vagrantArgs, "--no-provision")
}
if c.debug {
vagrantArgs = append(vagrantArgs, "--debug")
}
vagrantUp := command.WithOptions(command.WithTermOutput(), command.WithLogging(c.UI)).Cmd("vagrant", vagrantArgs)
env := os.Environ()
// To allow moc.CmdCommand injects its environment variables.
if vagrantUp.Env != nil {
env = vagrantUp.Env
}
vagrantUp.Env = append(env, "SKIP_GALAXY=true")
err := vagrantUp.Run()
if err != nil {
c.UI.Error(err.Error())
return 1
}
return 0
}
func (c *UpCommand) Synopsis() string {
return "Starts and provisions the Vagrant environment by running 'vagrant up'"
}
func (c *UpCommand) Help() string {
helpText := `
Usage: trellis up [options]
Starts and provisions the Vagrant environment by running 'vagrant up'.
Start Vagrant VM:
$ trellis up
Start VM without provisioning:
$ trellis up --no-provision
Start VM and skip Galaxy install:
$ trellis up --no-galaxy
Start VM and display debug output:
$ trellis up --debug
Options:
--no-provision (default: false) Skip provisioning
--no-galaxy (default: false) Skip Ansible Galaxy install
--debug (default: false) Enable vagrant's debug mode
-h, --help show this help
`
return strings.TrimSpace(helpText)
}
func (c *UpCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *UpCommand) AutocompleteFlags() complete.Flags {
return complete.Flags{
"--no-provision": complete.PredictNothing,
"--no-galaxy": complete.PredictNothing,
"--debug": complete.PredictNothing,
}
}