This repository was archived by the owner on May 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathcommand-parser.ts
More file actions
636 lines (524 loc) · 34.2 KB
/
command-parser.ts
File metadata and controls
636 lines (524 loc) · 34.2 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
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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
import * as yargs from "yargs";
import * as cli from "../definitions/cli";
import * as chalk from "chalk";
import * as updateNotifier from "update-notifier";
import backslash = require("backslash");
var packageJson = require("../package.json");
const USAGE_PREFIX = "Usage: code-push";
// Command categories are: access-key, app, release, deployment, deployment-key, login, logout, register
var isValidCommandCategory = false;
// Commands are the verb following the command category (e.g.: "add" in "app add").
var isValidCommand = false;
var wasHelpShown = false;
export function showHelp(showRootDescription?: boolean): void {
if (!wasHelpShown) {
if (showRootDescription) {
console.log(chalk.cyan(" _____ __ " + chalk.green(" ___ __ ")));
console.log(chalk.cyan(" / ___/__ ___/ /__" + chalk.green(" / _ \\__ _____ / / ")));
console.log(chalk.cyan("/ /__/ _ \\/ _ / -_)" + chalk.green(" ___/ // (_-</ _ \\")));
console.log(chalk.cyan("\\___/\\___/\\_,_/\\__/" + chalk.green("_/ \\_,_/___/_//_/")) + " CLI v" + packageJson.version);
console.log(chalk.cyan("======================================"));
console.log("");
console.log("CodePush is a service that allows you to publish mobile app updates directly to your users' devices.\n");
updateCheck();
}
yargs.showHelp();
wasHelpShown = true;
}
}
function updateCheck(): void {
var notifier: updateNotifier.IResult = updateNotifier({ pkg: packageJson });
if (notifier.update) {
notifier.notify();
}
}
function accessKeyAdd(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " access-key " + commandName + " <description>")
.demand(/*count*/ 3, /*max*/ 3) // Require exactly two non-option arguments.
.example("access-key " + commandName + " \"VSO Integration\"", "Generates a new access key with the description \"VSO Integration\"");
addCommonConfiguration(yargs);
}
function accessKeyList(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " access-key " + commandName + " [--format <format>]")
.demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
.example("access-key " + commandName, "Lists access keys in tabular format")
.example("access-key " + commandName + " --format json", "Lists apps in JSON format")
.option("format", { default: "table", demand: false, description: "The output format (\"json\" or \"table\")", type: "string" });
addCommonConfiguration(yargs);
}
function accessKeyRemove(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " access-key " + commandName + " <accessKey>")
.demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments.
.example("access-key " + commandName + " 8d6513de-050c-4788-96f7-b2a50dd9684v", "Removes the \"8d6513de-050c-4788-96f7-b2a50dd9684v\" access key");
addCommonConfiguration(yargs);
}
function addCommonConfiguration(yargs: yargs.Argv): void {
yargs.wrap(/*columnLimit*/ null)
.strict() // Validate hyphenated (named) arguments.
.fail((msg: string) => showHelp()); // Suppress the default error message.
}
function appList(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " app " + commandName + " [--format <format>]")
.demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
.example("app " + commandName, "Lists apps in tabular format")
.example("app " + commandName + " --format json", "Lists apps in JSON format")
.option("format", { default: "table", demand: false, description: "The output format (\"json\" or \"table\")", type: "string" });
addCommonConfiguration(yargs);
}
function appRemove(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " app " + commandName + " <appName>")
.demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments.
.example("app " + commandName + " MyApp", "Removes app \"MyApp\"");
addCommonConfiguration(yargs);
}
function listCollaborators(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " collaborator " + commandName + " <appName> [--format <format>]")
.demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments.
.example("collaborator " + commandName + " MyApp", "Lists collaborators for app \"MyApp\" in tabular format")
.example("collaborator " + commandName + " MyApp --format json", "Lists collaborators for app \"MyApp\" in JSON format")
.option("format", { default: "table", demand: false, description: "The output format (\"json\" or \"table\")", type: "string" });
addCommonConfiguration(yargs);
}
function removeCollaborator(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " collaborator " + commandName + " <appName> <email>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("collaborator " + commandName + " MyApp foo@bar.com", "Removes foo@bar.com from app \"MyApp\" as a collaborator");
addCommonConfiguration(yargs);
}
function deploymentHistoryClear(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " deployment " + commandName + " <appName> <deploymentName>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("deployment " + commandName + " MyApp MyDeployment", "Clears the release history associated with deployment \"MyDeployment\" from app \"MyApp\"");
addCommonConfiguration(yargs);
}
function deploymentList(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " deployment " + commandName + " <appName> [--format <format>] [--displayKeys]")
.demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments.
.example("deployment " + commandName + " MyApp", "Lists deployments for app \"MyApp\" in tabular format")
.example("deployment " + commandName + " MyApp --format json", "Lists deployments for app \"MyApp\" in JSON format")
.option("format", { default: "table", demand: false, description: "The output format (\"json\" or \"table\")", type: "string" })
.option("displayKeys", { alias: "k", default: false, demand: false, description: "Whether to display the deployment keys", type: "boolean" });
addCommonConfiguration(yargs);
}
function deploymentRemove(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " deployment " + commandName + " <appName> <deploymentName>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("deployment " + commandName + " MyApp MyDeployment", "Removes deployment \"MyDeployment\" from app \"MyApp\"");
addCommonConfiguration(yargs);
}
function deploymentHistory(commandName: string, yargs: yargs.Argv): void {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " deployment " + commandName + " <appName> <deploymentName> [--format <format>] [--displayAuthor]")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("deployment " + commandName + " MyApp MyDeployment", "Shows the release history for deployment \"MyDeployment\" from app \"MyApp\" in tabular format")
.example("deployment " + commandName + " MyApp MyDeployment --format json", "Shows the release history for deployment \"MyDeployment\" from app \"MyApp\" in JSON format")
.option("format", { default: "table", demand: false, description: "The output format (\"json\" or \"table\")", type: "string" })
.option("displayAuthor", { alias: "a", default: false, demand: false, description: "Whether to display who performed the release", type: "boolean" });
addCommonConfiguration(yargs);
}
var argv = yargs.usage(USAGE_PREFIX + " <command>")
.demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option argument.
.command("access-key", "View and delete active user sessions", (yargs: yargs.Argv) => {
isValidCommandCategory = true;
yargs.usage(USAGE_PREFIX + " access-key <command>")
.demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
.command("add", "Create a new access key associated with your account", (yargs: yargs.Argv) => accessKeyAdd("add", yargs))
.command("remove", "Remove an existing access key", (yargs: yargs.Argv) => accessKeyRemove("remove", yargs))
.command("rm", "Remove an existing access key", (yargs: yargs.Argv) => accessKeyRemove("rm", yargs))
.command("list", "List the access keys associated with your account", (yargs: yargs.Argv) => accessKeyList("list", yargs))
.command("ls", "List the access keys associated with your account", (yargs: yargs.Argv) => accessKeyList("ls", yargs))
.check((argv: any, aliases: { [aliases: string]: string }): any => isValidCommand); // Report unrecognized, non-hyphenated command category.
addCommonConfiguration(yargs);
})
.command("app", "View and manage your CodePush-enabled apps", (yargs: yargs.Argv) => {
isValidCommandCategory = true;
yargs.usage(USAGE_PREFIX + " app <command>")
.demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
.command("add", "Add a new app to your account", (yargs: yargs.Argv): void => {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " app add <appName>")
.demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments.
.example("app add MyApp", "Adds app \"MyApp\"");
addCommonConfiguration(yargs);
})
.command("remove", "Remove an app from your account", (yargs: yargs.Argv) => appRemove("remove", yargs))
.command("rm", "Remove an app from your account", (yargs: yargs.Argv) => appRemove("rm", yargs))
.command("rename", "Rename an existing app", (yargs: yargs.Argv) => {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " app rename <currentAppName> <newAppName>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("app rename CurrentName NewName", "Renames app \"CurrentName\" to \"NewName\"");
addCommonConfiguration(yargs);
})
.command("list", "List the apps associated with your account", (yargs: yargs.Argv) => appList("list", yargs))
.command("ls", "List the apps associated with your account", (yargs: yargs.Argv) => appList("ls", yargs))
.command("transfer", "Transfer the ownership of an app to another account", (yargs: yargs.Argv) => {
yargs.usage(USAGE_PREFIX + " app transfer <appName> <email>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("app transfer MyApp foo@bar.com", "Transfers the ownership of app \"MyApp\" to an account with email \"foo@bar.com\"");
addCommonConfiguration(yargs);
})
.check((argv: any, aliases: { [aliases: string]: string }): any => isValidCommand); // Report unrecognized, non-hyphenated command category.
addCommonConfiguration(yargs);
})
.command("collaborator", "View and manage collaborators for a given app", (yargs: yargs.Argv) => {
isValidCommandCategory = true;
yargs.usage(USAGE_PREFIX + " collaborator <command>")
.demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
.command("add", "Add a new collaborator to the given app", (yargs: yargs.Argv): void => {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " collaborator add <appName> <email>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("collaborator add MyApp foo@bar.com", "Adds foo@bar.com as a collaborator to app \"MyApp\"");
addCommonConfiguration(yargs);
})
.command("remove", "Remove an app from your account", (yargs: yargs.Argv) => removeCollaborator("remove", yargs))
.command("rm", "Remove an app from your account", (yargs: yargs.Argv) => removeCollaborator("rm", yargs))
.command("list", "List the apps associated with your account", (yargs: yargs.Argv) => listCollaborators("list", yargs))
.command("ls", "List the apps associated with your account", (yargs: yargs.Argv) => listCollaborators("ls", yargs))
.check((argv: any, aliases: { [aliases: string]: string }): any => isValidCommand); // Report unrecognized, non-hyphenated command category.
addCommonConfiguration(yargs);
})
.command("deployment", "View and manage the deployments for your apps", (yargs: yargs.Argv) => {
isValidCommandCategory = true;
yargs.usage(USAGE_PREFIX + " deployment <command>")
.demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments.
.command("add", "Add a new deployment to an existing app", (yargs: yargs.Argv): void => {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " deployment add <appName> <deploymentName>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("deployment add MyApp MyDeployment", "Adds deployment \"MyDeployment\" to app \"MyApp\"");
addCommonConfiguration(yargs);
})
.command("clear", "Clears the release history associated with a deployment", (yargs: yargs.Argv) => deploymentHistoryClear("clear", yargs))
.command("remove", "Remove a deployment from an app", (yargs: yargs.Argv) => deploymentRemove("remove", yargs))
.command("rm", "Remove a deployment from an app", (yargs: yargs.Argv) => deploymentRemove("rm", yargs))
.command("rename", "Rename an existing deployment", (yargs: yargs.Argv) => {
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " deployment rename <appName> <currentDeploymentName> <newDeploymentName>")
.demand(/*count*/ 5, /*max*/ 5) // Require exactly five non-option arguments.
.example("deployment rename MyApp CurrentDeploymentName NewDeploymentName", "Renames deployment \"CurrentDeploymentName\" to \"NewDeploymentName\"");
addCommonConfiguration(yargs);
})
.command("list", "List the deployments associated with an app", (yargs: yargs.Argv) => deploymentList("list", yargs))
.command("ls", "List the deployments associated with an app", (yargs: yargs.Argv) => deploymentList("ls", yargs))
.command("history", "Show the release history of a specific deployment", (yargs: yargs.Argv) => deploymentHistory("history", yargs))
.command("h", "Show the release history of a specific deployment", (yargs: yargs.Argv) => deploymentHistory("h", yargs))
.check((argv: any, aliases: { [aliases: string]: string }): any => isValidCommand); // Report unrecognized, non-hyphenated command category.
addCommonConfiguration(yargs);
})
.command("login", "Authenticate with the CodePush server in order to begin managing your apps", (yargs: yargs.Argv) => {
isValidCommandCategory = true;
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " login [--accessKey <accessKey>]")
.demand(/*count*/ 1, /*max*/ 2) // Require one non-optional and one optional argument.
.example("login", "Logs in to the CodePush server")
.example("login --accessKey mykey", "Logs in on behalf of the user who owns and created the access key \"mykey\"")
.option("accessKey", { alias: "key", default: null, demand: false, description: "The access key to be used for this session", type: "string" })
.check((argv: any, aliases: { [aliases: string]: string }): any => isValidCommand); // Report unrecognized, non-hyphenated command category.
addCommonConfiguration(yargs);
})
.command("logout", "Log out of the current session", (yargs: yargs.Argv) => {
isValidCommandCategory = true;
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " logout")
.demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option argument.
.example("logout", "Log out and end your session");
addCommonConfiguration(yargs);
})
.command("promote", "Promote the package from one deployment of your app to another", (yargs: yargs.Argv) => {
yargs.usage(USAGE_PREFIX + " promote <appName> <sourceDeploymentName> <destDeploymentName>")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("promote MyApp Staging Production", "Promote the latest \"Staging\" package of \"MyApp\" to \"Production\"");
addCommonConfiguration(yargs);
})
.command("register", "Register a new account with the CodePush server", (yargs: yargs.Argv) => {
isValidCommandCategory = true;
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " register")
.demand(/*count*/ 1, /*max*/ 2) // Require one non-optional and one optional argument.
.example("register", "Creates a new user account on the CodePush server")
.check((argv: any, aliases: { [aliases: string]: string }): any => isValidCommand); // Report unrecognized, non-hyphenated command category.
addCommonConfiguration(yargs);
})
.command("release", "Release a new version of your app to a specific deployment", (yargs: yargs.Argv) => {
yargs.usage(USAGE_PREFIX + " release <appName> <updateContentsPath> <targetBinaryVersion> [--deploymentName <deploymentName>] [--description <description>] [--mandatory]")
.demand(/*count*/ 4, /*max*/ 4) // Require exactly four non-option arguments.
.example("release MyApp app.js \"*\"", "Release the \"app.js\" file to the \"MyApp\" app's \"Staging\" deployment, targeting any binary version using the \"*\" wildcard range syntax.")
.example("release MyApp ./platforms/ios/www 1.0.3 -d Production", "Release the \"./platforms/ios/www\" folder and all its contents to the \"MyApp\" app's \"Production\" deployment, targeting only the 1.0.3 binary version")
.option("deploymentName", { alias: "d", default: "Staging", demand: false, description: "The deployment to publish the update to", type: "string" })
.option("description", { alias: "des", default: null, demand: false, description: "The description of changes made to the app with this update", type: "string" })
.option("mandatory", { alias: "m", default: false, demand: false, description: "Whether this update should be considered mandatory to the client", type: "boolean" });
addCommonConfiguration(yargs);
})
.command("release-react", "Release a new version of your React Native app to a specific deployment", (yargs: yargs.Argv) => {
yargs.usage(USAGE_PREFIX + " release-react <appName> <platform> [--deploymentName <deploymentName>] [--description <description>] [--entryFile <entryFile>] [--mandatory] [--sourcemapOutput <sourcemapOutput>] [--targetBinaryVersion <targetBinaryVersion>]")
.demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments.
.example("release-react MyApp ios", "Release the React Native iOS project in the current working directory to the \"MyApp\" app's \"Staging\" deployment")
.example("release-react MyApp android -d Production", "Release the React Native Android project in the current working directory to the \"MyApp\" app's \"Production\" deployment")
.option("bundleName", { alias: "b", default: null, demand: false, description: "The name of the output JS bundle. If omitted, the standard bundle name will be used for the specified platform: \"main.jsbundle\" (iOS) and \"index.android.bundle\" (Android)", type: "string" })
.option("deploymentName", { alias: "d", default: "Staging", demand: false, description: "The deployment to publish the update to", type: "string" })
.option("description", { alias: "des", default: null, demand: false, description: "The description of changes made to the app with this update", type: "string" })
.option("development", { alias: "dev", default: false, demand: false, description: "Whether to generate a unminified, development JS bundle.", type: "boolean" })
.option("entryFile", { alias: "e", default: null, demand: false, description: "The path to the root JS file. If unspecified, \"index.<platform>.js\" and then \"index.js\" will be tried and used if they exist.", type: "string" })
.option("mandatory", { alias: "m", default: false, demand: false, description: "Whether this update should be considered mandatory to the client", type: "boolean" })
.option("sourcemapOutput", { alias: "s", default: null, demand: false, description: "The path to where the sourcemap for the resulting bundle should be stored. If unspecified, sourcemaps will not be generated.", type: "string" })
.option("targetBinaryVersion", { alias: "t", default: null, demand: false, description: "The semver range expression spanning all the binary app store versions that should get this update. If omitted, the update will default to target only the same version as the current binary version specified in \"Info.plist\" (iOS) or \"build.gradle\" (Android)", type: "string" });
addCommonConfiguration(yargs);
})
.command("rollback", "Performs a rollback on the latest package of a specific deployment", (yargs: yargs.Argv) => {
yargs.usage(USAGE_PREFIX + " rollback <appName> <deploymentName> [--targetRelease <releaseLabel>]")
.demand(/*count*/ 3, /*max*/ 3) // Require exactly three non-option arguments.
.example("rollback MyApp Production", "Perform a rollback on the \"Production\" deployment of \"MyApp\"")
.example("rollback MyApp Production --targetRelease v4", "Perform a rollback on the \"Production\" deployment of \"MyApp\" to the v4 release")
.option("targetRelease", { alias: "r", default: null, demand: false, description: "The label of the release to be rolled back to (e.g. v4)", type: "string" });
addCommonConfiguration(yargs);
})
.alias("v", "version")
.version(require("../package.json").version)
.wrap(/*columnLimit*/ null)
.strict() // Validate hyphenated (named) arguments.
.check((argv: any, aliases: { [aliases: string]: string }): any => isValidCommandCategory) // Report unrecognized, non-hyphenated command category.
.fail((msg: string) => showHelp(/*showRootDescription*/ true)) // Suppress the default error message.
.argv;
function createCommand(): cli.ICommand {
var cmd: cli.ICommand;
if (!wasHelpShown && argv._ && argv._.length > 0) {
// Create a command object
var arg0: any = argv._[0];
var arg1: any = argv._[1];
var arg2: any = argv._[2];
var arg3: any = argv._[3];
var arg4: any = argv._[4];
switch (arg0) {
case "access-key":
switch (arg1) {
case "add":
if (arg2) {
cmd = { type: cli.CommandType.accessKeyAdd };
(<cli.IAccessKeyAddCommand>cmd).description = arg2;
}
break;
case "list":
case "ls":
cmd = { type: cli.CommandType.accessKeyList };
(<cli.IAccessKeyListCommand>cmd).format = argv["format"];
break;
case "remove":
case "rm":
if (arg2) {
cmd = { type: cli.CommandType.accessKeyRemove };
(<cli.IAccessKeyRemoveCommand>cmd).accessKey = arg2;
}
break;
}
break;
case "app":
switch (arg1) {
case "add":
if (arg2) {
cmd = { type: cli.CommandType.appAdd };
(<cli.IAppAddCommand>cmd).appName = arg2;
}
break;
case "list":
case "ls":
cmd = { type: cli.CommandType.appList };
(<cli.IAppListCommand>cmd).format = argv["format"];
break;
case "remove":
case "rm":
if (arg2) {
cmd = { type: cli.CommandType.appRemove };
(<cli.IAppRemoveCommand>cmd).appName = arg2;
}
break;
case "rename":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.appRename };
var appRenameCommand = <cli.IAppRenameCommand>cmd;
appRenameCommand.currentAppName = arg2;
appRenameCommand.newAppName = arg3;
}
break;
case "transfer":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.appTransfer };
var appTransferCommand = <cli.IAppTransferCommand>cmd;
appTransferCommand.appName = arg2;
appTransferCommand.email = arg3;
}
break;
}
break;
case "collaborator":
switch (arg1) {
case "add":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.collaboratorAdd };
(<cli.ICollaboratorAddCommand>cmd).appName = arg2;
(<cli.ICollaboratorAddCommand>cmd).email = arg3;
}
break;
case "list":
case "ls":
if (arg2) {
cmd = { type: cli.CommandType.collaboratorList };
(<cli.ICollaboratorListCommand>cmd).appName = arg2;
(<cli.ICollaboratorListCommand>cmd).format = argv["format"];
}
break;
case "remove":
case "rm":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.collaboratorRemove };
(<cli.ICollaboratorRemoveCommand>cmd).appName = arg2;
(<cli.ICollaboratorAddCommand>cmd).email = arg3;
}
break;
}
break;
case "deployment":
switch (arg1) {
case "add":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.deploymentAdd };
var deploymentAddCommand = <cli.IDeploymentAddCommand>cmd;
deploymentAddCommand.appName = arg2;
deploymentAddCommand.deploymentName = arg3;
}
break;
case "clear":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.deploymentHistoryClear };
var deploymentHistoryClearCommand = <cli.IDeploymentHistoryClearCommand>cmd;
deploymentHistoryClearCommand.appName = arg2;
deploymentHistoryClearCommand.deploymentName = arg3;
}
break;
case "list":
case "ls":
if (arg2) {
cmd = { type: cli.CommandType.deploymentList };
var deploymentListCommand = <cli.IDeploymentListCommand>cmd;
deploymentListCommand.appName = arg2;
deploymentListCommand.format = argv["format"];
deploymentListCommand.displayKeys = argv["displayKeys"];
}
break;
case "remove":
case "rm":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.deploymentRemove };
var deploymentRemoveCommand = <cli.IDeploymentRemoveCommand>cmd;
deploymentRemoveCommand.appName = arg2;
deploymentRemoveCommand.deploymentName = arg3;
}
break;
case "rename":
if (arg2 && arg3 && arg4) {
cmd = { type: cli.CommandType.deploymentRename };
var deploymentRenameCommand = <cli.IDeploymentRenameCommand>cmd;
deploymentRenameCommand.appName = arg2;
deploymentRenameCommand.currentDeploymentName = arg3;
deploymentRenameCommand.newDeploymentName = arg4;
}
break;
case "history":
case "h":
if (arg2 && arg3) {
cmd = { type: cli.CommandType.deploymentHistory };
var deploymentHistoryCommand = <cli.IDeploymentHistoryCommand>cmd;
deploymentHistoryCommand.appName = arg2;
deploymentHistoryCommand.deploymentName = arg3;
deploymentHistoryCommand.format = argv["format"];
deploymentHistoryCommand.displayAuthor = argv["displayAuthor"];
}
break;
}
break;
case "login":
cmd = { type: cli.CommandType.login };
var loginCommand = <cli.ILoginCommand>cmd;
loginCommand.serverUrl = getServerUrl(arg1);
loginCommand.accessKey = argv["accessKey"];
break;
case "logout":
cmd = { type: cli.CommandType.logout };
break;
case "promote":
if (arg1 && arg2 && arg3) {
cmd = { type: cli.CommandType.promote };
var deploymentPromoteCommand = <cli.IPromoteCommand>cmd;
deploymentPromoteCommand.appName = arg1;
deploymentPromoteCommand.sourceDeploymentName = arg2;
deploymentPromoteCommand.destDeploymentName = arg3;
}
break;
case "register":
cmd = { type: cli.CommandType.register };
var registerCommand = <cli.IRegisterCommand>cmd;
registerCommand.serverUrl = getServerUrl(arg1);
break;
case "release":
if (arg1 && arg2 && arg3) {
cmd = { type: cli.CommandType.release };
var releaseCommand = <cli.IReleaseCommand>cmd;
releaseCommand.appName = arg1;
releaseCommand.package = arg2;
// Floating points e.g. "1.2" gets parsed as a number by default, but semver requires strings.
releaseCommand.appStoreVersion = arg3.toString();
releaseCommand.deploymentName = argv["deploymentName"];
releaseCommand.description = argv["description"] ? backslash(argv["description"]) : "";
releaseCommand.mandatory = argv["mandatory"];
}
break;
case "release-react":
if (arg1 && arg2) {
cmd = { type: cli.CommandType.releaseReact };
var releaseReactCommand = <cli.IReleaseReactCommand>cmd;
releaseReactCommand.appName = arg1;
releaseReactCommand.platform = arg2;
releaseReactCommand.bundleName = argv["bundleName"];
releaseReactCommand.deploymentName = argv["deploymentName"];
releaseReactCommand.description = argv["description"] ? backslash(argv["description"]) : "";
releaseReactCommand.development = argv["development"];
releaseReactCommand.entryFile = argv["entryFile"];
releaseReactCommand.mandatory = argv["mandatory"];
releaseReactCommand.sourcemapOutput = argv["sourcemapOutput"];
releaseReactCommand.appStoreVersion = argv["targetBinaryVersion"];
}
break;
case "rollback":
if (arg1 && arg2) {
cmd = { type: cli.CommandType.rollback };
var rollbackCommand = <cli.IRollbackCommand>cmd;
rollbackCommand.appName = arg1;
rollbackCommand.deploymentName = arg2;
rollbackCommand.targetRelease = argv["targetRelease"];
}
break;
}
return cmd;
}
}
function getServerUrl(url: string): string {
if (!url) return null;
// Trim whitespace and a trailing slash (/) character.
url = url.trim();
if (url[url.length - 1] === "/") {
url = url.substring(0, url.length - 1);
}
return url;
}
export var command = createCommand();