/
commands.go
181 lines (152 loc) · 3.24 KB
/
commands.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
package cmd
import (
"github.com/Scalingo/cli/config"
"github.com/urfave/cli"
)
type AppCommands struct {
commands []cli.Command
}
type Command struct {
cli.Command
// Regional flag not available if Global is true
Global bool
}
func (cmds *AppCommands) AddCommand(cmd Command) {
if !cmd.Global {
regionFlag := cli.StringFlag{Name: "region", Value: "", Usage: "Name of the region to use"}
cmd.Command.Flags = append(cmd.Command.Flags, regionFlag)
}
action := cmd.Command.Action.(func(c *cli.Context))
cmd.Command.Action = func(c *cli.Context) {
region := c.GlobalString("region")
if region == "" {
region = c.String("region")
}
if region != "" {
config.C.ScalingoRegion = region
}
action(c)
}
cmds.commands = append(cmds.commands, cmd.Command)
}
func (cmds *AppCommands) Commands() []cli.Command {
return cmds.commands
}
func NewAppCommands() *AppCommands {
cmds := AppCommands{}
for _, cmd := range regionalCommands {
cmds.AddCommand(Command{Command: cmd})
}
for _, cmd := range globalCommands {
cmds.AddCommand(Command{Global: true, Command: cmd})
}
return &cmds
}
var (
regionalCommands = []cli.Command{
// Apps
appsCommand,
CreateCommand,
DestroyCommand,
renameCommand,
appsInfoCommand,
// Apps Actions
LogsCommand,
LogsArchivesCommand,
RunCommand,
// Apps Process Actions
psCommand,
scaleCommand,
RestartCommand,
// Routing Settings
forceHTTPSCommand,
stickySessionCommand,
setCanonicalDomainCommand,
unsetCanonicalDomainCommand,
// Events
UserTimelineCommand,
TimelineCommand,
// Environment
envCommand,
envSetCommand,
envUnsetCommand,
// Domains
DomainsListCommand,
DomainsAddCommand,
DomainsRemoveCommand,
DomainsSSLCommand,
// Deployments
DeploymentsListCommand,
DeploymentLogCommand,
DeploymentFollowCommand,
DeploymentDeployCommand,
DeploymentCacheResetCommand,
// Collaborators
CollaboratorsListCommand,
CollaboratorsAddCommand,
CollaboratorsRemoveCommand,
// Stacks
stacksListCommand,
stacksSetCommand,
// Addons
AddonProvidersListCommand,
AddonProvidersPlansCommand,
AddonsListCommand,
AddonsAddCommand,
AddonsRemoveCommand,
AddonsUpgradeCommand,
// Notifiers
NotifiersListCommand,
NotifiersDetailsCommand,
NotifiersAddCommand,
NotifiersUpdateCommand,
NotifiersRemoveCommand,
// Notification platforms
NotificationPlatformListCommand,
// DB Access
DbTunnelCommand,
RedisConsoleCommand,
MongoConsoleCommand,
MySQLConsoleCommand,
PgSQLConsoleCommand,
InfluxDBConsoleCommand,
// Backups
BackupListCommand,
BackupDownloadCommand,
// Alerts
alertsListCommand,
alertsAddCommand,
alertsUpdateCommand,
alertsEnableCommand,
alertsDisableCommand,
alertsRemoveCommand,
// Stats
StatsCommand,
// Autoscalers
autoscalersListCommand,
autoscalersAddCommand,
autoscalersRemoveCommand,
autoscalersUpdateCommand,
autoscalersDisableCommand,
autoscalersEnableCommand,
gitSetup,
gitShow,
}
globalCommands = []cli.Command{
// SSH keys
ListSSHKeyCommand,
AddSSHKeyCommand,
RemoveSSHKeyCommand,
// Sessions
LoginCommand,
LogoutCommand,
RegionsListCommand,
ConfigCommand,
selfCommand,
whoamiCommand,
// Version
UpdateCommand,
// Help
HelpCommand,
}
)