-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathapps.go
More file actions
272 lines (208 loc) · 5.38 KB
/
apps.go
File metadata and controls
272 lines (208 loc) · 5.38 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package parser
import (
"strconv"
"strings"
"github.com/deis/deis/client/cmd"
docopt "github.com/docopt/docopt-go"
)
// Apps routes app commands to their specific function.
func Apps(argv []string) error {
usage := `
Valid commands for apps:
apps:create create a new application
apps:list list accessible applications
apps:info view info about an application
apps:open open the application in a browser
apps:logs view aggregated application logs
apps:run run a command in an ephemeral app container
apps:destroy destroy an application
apps:transfer transfer app ownership to another user
Use 'deis help [command]' to learn more.
`
switch argv[0] {
case "apps:create":
return appCreate(argv)
case "apps:list":
return appsList(argv)
case "apps:info":
return appInfo(argv)
case "apps:open":
return appOpen(argv)
case "apps:logs":
return appLogs(argv)
case "apps:run":
return appRun(argv)
case "apps:destroy":
return appDestroy(argv)
case "apps:transfer":
return appTransfer(argv)
default:
if printHelp(argv, usage) {
return nil
}
if argv[0] == "apps" {
argv[0] = "apps:list"
return appsList(argv)
}
PrintUsage()
return nil
}
}
func appCreate(argv []string) error {
usage := `
Creates a new application.
- if no <id> is provided, one will be generated automatically.
Usage: deis apps:create [<id>] [options]
Arguments:
<id>
a uniquely identifiable name for the application. No other app can already
exist with this name.
Options:
--no-remote
do not create a 'deis' git remote.
-b --buildpack BUILDPACK
a buildpack url to use for this app
-r --remote REMOTE
name of remote to create. [default: deis]
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
id := safeGetValue(args, "<id>")
buildpack := safeGetValue(args, "--buildpack")
remote := safeGetValue(args, "--remote")
noRemote := args["--no-remote"].(bool)
return cmd.AppCreate(id, buildpack, remote, noRemote)
}
func appsList(argv []string) error {
usage := `
Lists applications visible to the current user.
Usage: deis apps:list [options]
Options:
-l --limit=<num>
the maximum number of results to display, defaults to config setting
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
results, err := responseLimit(safeGetValue(args, "--limit"))
if err != nil {
return err
}
return cmd.AppsList(results)
}
func appInfo(argv []string) error {
usage := `
Prints info about the current application.
Usage: deis apps:info [options]
Options:
-a --app=<app>
the uniquely identifiable name for the application.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
app := safeGetValue(args, "--app")
return cmd.AppInfo(app)
}
func appOpen(argv []string) error {
usage := `
Opens a URL to the application in the default browser.
Usage: deis apps:open [options]
Options:
-a --app=<app>
the uniquely identifiable name for the application.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
app := safeGetValue(args, "--app")
return cmd.AppOpen(app)
}
func appLogs(argv []string) error {
usage := `
Retrieves the most recent log events.
Usage: deis apps:logs [options]
Options:
-a --app=<app>
the uniquely identifiable name for the application.
-n --lines=<lines>
the number of lines to display
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
app := safeGetValue(args, "--app")
linesStr := safeGetValue(args, "--lines")
var lines int
if linesStr == "" {
lines = -1
} else {
lines, err = strconv.Atoi(linesStr)
if err != nil {
return err
}
}
return cmd.AppLogs(app, lines)
}
func appRun(argv []string) error {
usage := `
Runs a command inside an ephemeral app container. Default environment is
/bin/bash.
Usage: deis apps:run [options] [--] <command>...
Arguments:
<command>
the shell command to run inside the container.
Options:
-a --app=<app>
the uniquely identifiable name for the application.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
app := safeGetValue(args, "--app")
command := strings.Join(args["<command>"].([]string), " ")
return cmd.AppRun(app, command)
}
func appDestroy(argv []string) error {
usage := `
Destroys an application.
Usage: deis apps:destroy [options]
Options:
-a --app=<app>
the uniquely identifiable name for the application.
--confirm=<app>
skips the prompt for the application name. <app> is the uniquely identifiable
name for the application.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
app := safeGetValue(args, "--app")
confirm := safeGetValue(args, "--confirm")
return cmd.AppDestroy(app, confirm)
}
func appTransfer(argv []string) error {
usage := `
Transfer app ownership to another user.
Usage: deis apps:transfer <username> [options]
Arguments:
<username>
the user that the app will be transfered to.
Options:
-a --app=<app>
the uniquely identifiable name for the application.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
return cmd.AppTransfer(safeGetValue(args, "--app"), safeGetValue(args, "<username>"))
}