-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathserverless.ts
436 lines (431 loc) · 10 KB
/
serverless.ts
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
import YAML from "yaml";
const options: Record<string, Fig.Option> = {
awsProfile: {
name: "--aws-profile",
description: "AWS profile to use with the command",
args: {
name: "profile name",
},
},
function: {
name: ["--function", "-f"],
description: "Name of the function",
args: {
name: "function",
},
},
region: {
name: ["--region", "-r"],
description: "Region of the service",
args: {
name: "region",
suggestions: [
"us-east-2",
"us-east-1",
"us-west-1",
"us-west-2",
"af-south-1",
"ap-east-1",
"ap-south-1",
"ap-northeast-3",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ca-central-1",
"cn-north-1",
"cn-northwest-1",
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-south-1",
"eu-west-3",
"eu-north-1",
"me-south-1",
"sa-east-1",
"us-gov-east-1",
"us-gov-west-1",
],
},
},
useLocalCredentials: {
name: "--use-local-credentials",
description:
"Rely on locally resolved AWS credentials instead of loading them from Dashboard provider settings (applies only to services integrated with Dashboard)",
},
config: {
name: ["--config", "-c"],
description: "Path to serverless config file",
args: {
name: ".yml file",
template: "filepaths",
},
},
app: {
name: "--app",
description: "Dashboard app",
args: {
name: "app",
},
},
org: {
name: "--org",
description: "Dashboard org",
args: {
name: "org",
},
},
help: {
name: ["--help", "-h"],
description: "Show help",
},
version: {
name: "--version",
description: "Show version info",
},
stage: {
name: ["--stage", "-s"],
description: "Stage of the service",
args: {
name: "stage",
},
},
verbose: {
name: ["--verbose", "-v"],
description: "Show all stack events during deployment",
args: {
name: "production",
},
},
package: {
name: ["--package", "-p"],
description: "Path of the deployment package",
args: {
name: "package",
template: "folders",
},
},
conceal: {
name: "--conceal",
description: "Hide secrets from the output (e.g. API Gateway key values)",
},
qualifier: {
name: ["--qualifier", "-q"],
description: "Version number or alias to invoke",
args: {
name: "qualifier",
},
},
path: {
name: ["--path", "-p"],
description: "Path to JSON or YAML file holding input data",
args: {
name: "path",
template: "filepaths",
},
},
type: {
name: ["--type", "-t"],
description: "Type of invocation",
args: {
name: "type",
},
},
log: {
name: ["--log", "-l"],
description: "Trigger logging data output",
},
data: {
name: ["--data", "-d"],
description: "Input data",
args: {
name: "input",
},
},
raw: {
name: "--raw",
description: "Flag to pass input data as a raw string",
},
context: {
name: "--context",
description: "Context of the service",
args: {
name: "package",
},
},
contextPath: {
name: "--contextPath",
description: "Path to JSON or YAML file holding context data",
args: {
name: "path",
template: "filepaths",
},
},
env: {
name: ["--env", "-e"],
description:
"Override environment variables. e.g. --env VAR1=val1 --env VAR2=val2",
args: {
name: "--env VAR1=val1 --env VAR2=val2",
},
},
};
const completionSpec: Fig.Spec = {
name: "serverless",
description: "Zero-friction serverless development",
options: [
{
name: "--help",
description: "Show help",
},
],
subcommands: [
{
name: "deploy",
description: "Deploy a Serverless service",
subcommands: [
{
name: "function",
options: [
options.app,
options.awsProfile,
options.config,
options.function,
options.help,
options.org,
options.region,
options.stage,
options.useLocalCredentials,
options.version,
{
name: "--force",
description: "Forces a deployment to take place",
},
{
name: ["--update-config", "-u"],
description:
"Updates function configuration, e.g. Timeout or Memory Size without deploying code",
args: {
name: "config",
},
},
],
},
{
name: "list",
subcommands: [
{
name: "functions",
options: [
options.region,
options.awsProfile,
options.app,
options.org,
options.useLocalCredentials,
options.config,
options.stage,
options.help,
options.version,
],
},
],
options: [
options.region,
options.awsProfile,
options.app,
options.org,
options.useLocalCredentials,
options.config,
options.stage,
options.help,
options.version,
],
},
],
options: [
options.conceal,
options.package,
options.verbose,
{
name: "--force",
description: "Forces a deployment to take place",
},
options.function,
{
name: "--aws-s3-accelerate",
description:
"Enables S3 Transfer Acceleration making uploading artifacts much faster",
},
options.region,
options.awsProfile,
options.app,
options.org,
options.useLocalCredentials,
options.config,
options.stage,
options.help,
options.version,
],
},
{
name: "info",
description: "Display information about the service",
options: [
options.conceal,
options.region,
options.awsProfile,
options.app,
options.org,
options.useLocalCredentials,
options.config,
options.stage,
options.help,
options.version,
],
},
{
name: "invoke",
description: "Invoke a deployed function",
options: [
{ ...options.function, ...{ isRequired: true } },
options.path,
options.data,
options.raw,
options.context,
options.contextPath,
options.region,
options.awsProfile,
options.app,
options.org,
options.useLocalCredentials,
options.config,
options.stage,
options.help,
options.version,
],
subcommands: [
{
name: "local",
options: [
{ ...options.function, ...{ isRequired: true } },
options.path,
options.data,
options.raw,
options.context,
options.contextPath,
options.env,
options.region,
options.awsProfile,
options.app,
options.org,
options.useLocalCredentials,
options.config,
options.stage,
options.help,
options.version,
],
},
],
},
{
name: "logs",
description: "Output the logs of a deployed function",
},
{
name: "metrics",
description: "Show metrics for a specific function",
},
{
name: "remove",
description: "Remove Serverless service and all resources",
},
{
name: "rollback",
description: "Rollback the Serverless service to a specific deployment",
},
{
name: "studio",
description: "Develop a Serverless application in the cloud",
},
{
name: "test",
description: "Run HTTP tests",
},
{
name: "package",
description: "Package a Serverless service",
},
{
name: "plugin",
description: "Handle plugins",
},
{
name: "print",
description: "Print your compiled and resolved config file",
},
{
name: "create",
description: "Create new Serverless service",
},
{
name: "dashboard",
description: "Open the Serverless dashboard",
},
{
name: "generate-event",
description: "Generate event",
},
{
name: "install",
description:
"Install a Serverless service from GitHub or a plugin from the Serverless registry",
},
{
name: "login",
description: "Login or sign up for Serverless",
},
{
name: "logout",
description: "Logout from Serverless",
},
{
name: "output",
description: "Get/list value of dashboard deployment profile parameter",
},
{
name: "param",
description: "Get/list value of dashboard service output",
},
{
name: "slstats",
description: "Enable or disable stats",
},
],
generateSpec: async (tokens, executeShellCommand) => {
const { stdout } = await executeShellCommand({
command: "cat",
// eslint-disable-next-line @withfig/fig-linter/no-useless-arrays
args: ["serverless-compose.yml"],
});
const servicesObject = YAML.parse(stdout).services;
const services: string[] = Object.keys(servicesObject);
// Avoid infinite recursion of generated subcommands
if (services.includes(tokens[0])) {
return;
}
const subcommands: Fig.Subcommand[] = services.map((service) => ({
name: service,
description: tokens.join(","),
priority: 100,
loadSpec: "serverless",
icon: "fig://icon?type=box",
}));
if (subcommands.length > 0) {
return {
name: "serverless",
subcommands,
};
}
},
};
export default completionSpec;