1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const packageJson = require('../package.json');
|
6 | const slsArt = require('../lib/');
|
7 | const yargs = require('yargs')
|
8 | .help()
|
9 | .version(packageJson.version)
|
10 | .options({
|
11 | D: {
|
12 | alias: 'debug',
|
13 | description: 'Execute the command in debug mode. It will be chatty about what it is happening in the code.',
|
14 | requiresArg: false,
|
15 | },
|
16 | V: {
|
17 | alias: 'verbose',
|
18 | description: 'Execute the command in verbose mode. It will be chatty about what it is attempting to accomplish.',
|
19 | requiresArg: false,
|
20 | },
|
21 | })
|
22 | .global('D', 'V')
|
23 | .command('deploy', 'Deploy a default version of the function that will execute your Artillery scripts.', {
|
24 | r: {
|
25 | alias: 'region',
|
26 | description: 'The region where the function will be deployed',
|
27 | requiresArg: true,
|
28 | type: 'string',
|
29 | },
|
30 | })
|
31 | .command('invoke', 'Invoke your function with your Artillery script. Will prefer a script given by `-s` over a ' +
|
32 | '`script.[yml|json]` in the current directory over the preexisting default script.',
|
33 | {
|
34 | s: {
|
35 | alias: 'script',
|
36 | description: 'The Artillery script to execute.',
|
37 | requiresArg: true,
|
38 | type: 'string',
|
39 | },
|
40 | r: {
|
41 | alias: 'region',
|
42 | description: 'The region in which the function will be executed',
|
43 | requiresArg: true,
|
44 | type: 'string',
|
45 | },
|
46 | })
|
47 | .command('remove', 'Remove the function and the associated resources created for or by it.', {
|
48 | r: {
|
49 | alias: 'region',
|
50 | description: 'The region from which the function will be removed',
|
51 | requiresArg: true,
|
52 | type: 'string',
|
53 | },
|
54 | })
|
55 | .command('script', 'Create a local Artillery script so that you can customize it for your specific load ' +
|
56 | 'requirements. See https://artillery.io for documentation.',
|
57 | {
|
58 | e: {
|
59 | alias: 'endpoint',
|
60 | description: 'The endpoint to load with traffic.',
|
61 | requiresArg: true,
|
62 | type: 'string',
|
63 | },
|
64 | d: {
|
65 | alias: 'duration',
|
66 | description: 'The duration, in seconds, to load the given endpoint.',
|
67 | requiresArg: true,
|
68 | type: 'number',
|
69 | },
|
70 | r: {
|
71 | alias: 'rate',
|
72 | description: 'The rate, in requests per second, at which to load the given endpoint.',
|
73 | requiresArg: true,
|
74 | type: 'number',
|
75 | },
|
76 | t: {
|
77 | alias: 'rampTo',
|
78 | description: 'The rate to adjust towards away from the given rate, in requests per second at which to load ' +
|
79 | 'the given endpoint.',
|
80 | requiresArg: true,
|
81 | type: 'number',
|
82 | },
|
83 | o: {
|
84 | alias: 'out',
|
85 | description: 'The file to output the generated script in to.',
|
86 | requiresArg: true,
|
87 | type: 'string',
|
88 | },
|
89 | })
|
90 | .command('configure', 'Create a local copy of the deployment assets for modification and deployment. See ' +
|
91 | 'https://docs.serverless.com for documentation.', {})
|
92 | .demand(1)
|
93 | .strict()
|
94 | .argv;
|
95 |
|
96 | const command = yargs._[0];
|
97 |
|
98 | if (yargs.debug) {
|
99 | console.log(`options were:\n${JSON.stringify(yargs, null, 2)}`);
|
100 | console.log(`command that will be executed: slsArt[${command}](${yargs})`);
|
101 | }
|
102 |
|
103 | slsArt[command](yargs)
|
104 | .catch((ex) => {
|
105 | console.log(ex.message);
|
106 | if (yargs.verbose) {
|
107 | console.log(ex.stack);
|
108 | }
|
109 | });
|