forked from roots/trellis-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
242 lines (224 loc) · 6.99 KB
/
main.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/roots/trellis-cli/app_paths"
"github.com/roots/trellis-cli/cmd"
"github.com/roots/trellis-cli/github"
"github.com/roots/trellis-cli/plugin"
"github.com/roots/trellis-cli/trellis"
"github.com/roots/trellis-cli/update"
"github.com/fatih/color"
"github.com/mitchellh/cli"
)
// To be replaced by goreleaser build flags.
var version = "canary"
var updaterRepo = ""
var experimentalCommands = []string{
"vm",
}
func main() {
c := cli.NewCLI("trellis", version)
c.Args = os.Args[1:]
ui := &cli.ColoredUi{
ErrorColor: cli.UiColorRed,
WarnColor: cli.UiColor{Code: int(color.FgYellow), Bold: false},
Ui: &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
},
}
trellis := trellis.NewTrellis()
if err := trellis.LoadGlobalCliConfig(); err != nil {
ui.Error(err.Error())
os.Exit(1)
}
updateNotifier := &update.Notifier{
CacheDir: app_paths.CacheDir(),
Client: github.Client,
Repo: updaterRepo,
SkipCheck: !trellis.CliConfig.CheckForUpdates,
Version: version,
}
updateMessageChan := make(chan *github.Release)
go func() {
release, _ := updateNotifier.CheckForUpdate()
updateMessageChan <- release
}()
c.Commands = map[string]cli.CommandFactory{
"alias": func() (cli.Command, error) {
return cmd.NewAliasCommand(ui, trellis), nil
},
"check": func() (cli.Command, error) {
return &cmd.CheckCommand{UI: ui, Trellis: trellis}, nil
},
"db": func() (cli.Command, error) {
return &cmd.NamespaceCommand{
HelpText: "Usage: trellis db <subcommand> [<args>]",
SynopsisText: "Commands for database management",
}, nil
},
"db open": func() (cli.Command, error) {
return cmd.NewDBOpenCommand(ui, trellis), nil
},
"deploy": func() (cli.Command, error) {
return cmd.NewDeployCommand(ui, trellis), nil
},
"dotenv": func() (cli.Command, error) {
return cmd.NewDotEnvCommand(ui, trellis), nil
},
"down": func() (cli.Command, error) {
return &cmd.DownCommand{UI: ui, Trellis: trellis}, nil
},
"droplet": func() (cli.Command, error) {
return &cmd.NamespaceCommand{
HelpText: "Usage: trellis droplet <subcommand> [<args>]",
SynopsisText: "Commands for DigitalOcean Droplets",
}, nil
},
"droplet create": func() (cli.Command, error) {
return cmd.NewDropletCreateCommand(ui, trellis), nil
},
"droplet dns": func() (cli.Command, error) {
return cmd.NewDropletDnsCommand(ui, trellis), nil
},
"exec": func() (cli.Command, error) {
return &cmd.ExecCommand{UI: ui, Trellis: trellis}, nil
},
"galaxy": func() (cli.Command, error) {
return &cmd.NamespaceCommand{
HelpText: "Usage: trellis galaxy <subcommand> [<args>]",
SynopsisText: "Commands for Ansible Galaxy",
}, nil
},
"galaxy install": func() (cli.Command, error) {
return &cmd.GalaxyInstallCommand{UI: ui, Trellis: trellis}, nil
},
"info": func() (cli.Command, error) {
return &cmd.InfoCommand{UI: ui, Trellis: trellis}, nil
},
"init": func() (cli.Command, error) {
return cmd.NewInitCommand(ui, trellis), nil
},
"key": func() (cli.Command, error) {
return &cmd.NamespaceCommand{
HelpText: "Usage: trellis key <subcommand> [<args>]",
SynopsisText: "Commands for managing SSH keys",
}, nil
},
"key generate": func() (cli.Command, error) {
return cmd.NewKeyGenerateCommand(ui, trellis), nil
},
"logs": func() (cli.Command, error) {
return cmd.NewLogsCommand(ui, trellis), nil
},
"new": func() (cli.Command, error) {
return cmd.NewNewCommand(ui, trellis, c.Version), nil
},
"open": func() (cli.Command, error) {
return &cmd.OpenCommand{UI: ui, Trellis: trellis}, nil
},
"provision": func() (cli.Command, error) {
return cmd.NewProvisionCommand(ui, trellis), nil
},
"rollback": func() (cli.Command, error) {
return cmd.NewRollbackCommand(ui, trellis), nil
},
"shell-init": func() (cli.Command, error) {
return &cmd.ShellInitCommand{UI: ui}, nil
},
"ssh": func() (cli.Command, error) {
return cmd.NewSshCommand(ui, trellis), nil
},
"up": func() (cli.Command, error) {
return cmd.NewUpCommand(ui, trellis), nil
},
"vault": func() (cli.Command, error) {
return &cmd.NamespaceCommand{
HelpText: "Usage: trellis vault <subcommand> [<args>]",
SynopsisText: "Commands for Ansible Vault",
}, nil
},
"vault edit": func() (cli.Command, error) {
return cmd.NewVaultEditCommand(ui, trellis), nil
},
"vault encrypt": func() (cli.Command, error) {
return cmd.NewVaultEncryptCommand(ui, trellis), nil
},
"vault decrypt": func() (cli.Command, error) {
return cmd.NewVaultDecryptCommand(ui, trellis), nil
},
"vault view": func() (cli.Command, error) {
return cmd.NewVaultViewCommand(ui, trellis), nil
},
"valet": func() (cli.Command, error) {
return &cmd.NamespaceCommand{
HelpText: "Usage: trellis valet <subcommand> [<args>]",
SynopsisText: "Commands for Laravel Valet",
}, nil
},
"valet link": func() (cli.Command, error) {
return &cmd.ValetLinkCommand{UI: ui, Trellis: trellis}, nil
},
"venv hook": func() (cli.Command, error) {
return &cmd.VenvHookCommand{UI: ui, Trellis: trellis}, nil
},
"vm": func() (cli.Command, error) {
return &cmd.NamespaceCommand{
HelpText: "Usage: trellis vm <subcommand> [<args>]",
SynopsisText: "Commands for managing development virtual machines",
}, nil
},
"vm delete": func() (cli.Command, error) {
return cmd.NewVmDeleteCommand(ui, trellis), nil
},
"vm shell": func() (cli.Command, error) {
return cmd.NewVmShellCommand(ui, trellis), nil
},
"vm start": func() (cli.Command, error) {
return cmd.NewVmStartCommand(ui, trellis), nil
},
"vm stop": func() (cli.Command, error) {
return cmd.NewVmStopCommand(ui, trellis), nil
},
"vm sudoers": func() (cli.Command, error) {
return &cmd.VmSudoersCommand{UI: ui, Trellis: trellis}, nil
},
"xdebug-tunnel": func() (cli.Command, error) {
return &cmd.NamespaceCommand{
HelpText: "Usage: trellis xdebug-tunnel <subcommand> [<args>]",
SynopsisText: "Commands for Xdebug tunnel",
}, nil
},
"xdebug-tunnel open": func() (cli.Command, error) {
return cmd.NewXdebugTunnelOpenCommand(ui, trellis), nil
},
"xdebug-tunnel close": func() (cli.Command, error) {
return cmd.NewXdebugTunnelCloseCommand(ui, trellis), nil
},
}
c.HiddenCommands = []string{"venv", "venv hook"}
c.HelpFunc = experimentalCommandHelpFunc(c.Name, cli.BasicHelpFunc("trellis"))
if trellis.CliConfig.LoadPlugins {
pluginPaths := filepath.SplitList(os.Getenv("PATH"))
plugin.Register(c, pluginPaths, []string{"trellis"})
}
exitStatus, err := c.Run()
if err != nil {
ui.Error(err.Error())
}
newRelease := <-updateMessageChan
if newRelease != nil {
msg := fmt.Sprintf(
"\n%s %s → %s\n%s",
color.YellowString("A new release of trellis-cli is available:"),
color.CyanString(version),
color.CyanString(newRelease.Version),
color.YellowString(newRelease.URL),
)
ui.Info(msg)
}
os.Exit(exitStatus)
}