1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 | 'use strict';
|
6 |
|
7 | const program = require('commander');
|
8 | const getVisitor = require('../lib/visitor').getVisitor;
|
9 | const notifier = require('../lib/update-notifier');
|
10 | const { autoExit } = require('../lib/unref-timeout');
|
11 | const { collectOptions } = require('../lib/options');
|
12 |
|
13 | program
|
14 | .name('fun local invoke')
|
15 | .description(
|
16 | `Execute your function in a local environment which replicates the live environment
|
17 | almost identically. You can pass in the event body via stdin or by using the -e (--event)
|
18 | parameter.`)
|
19 | .usage('[options] <[service/]function>')
|
20 | .option('-t, --template [template]', 'The path of fun template file.', collectOptions)
|
21 | .option('-d, --debug-port <port>',
|
22 | `Specify the sandboxed container starting in debug mode,
|
23 | and exposing this port on localhost`)
|
24 | .option('-c, --config <ide/debugger>',
|
25 | 'Select which IDE to use when debugging and output related debug config tips for the IDE. Options:\'vscode\', \'pycharm\'')
|
26 | .option('-e, --event <path>',
|
27 | `A file containing event data passed to the function during
|
28 | invoke, If this option is not specified, it defaults to
|
29 | reading event from stdin`)
|
30 | .option('--debugger-path <debuggerPath>', 'the path of the debugger on the host')
|
31 | .option('--debug-args <debugArgs>', 'additional parameters that will be passed to the debugger')
|
32 | .option('--tmp-dir <tmpDir>', `The temp directory mounted to /tmp , default to './.fun/tmp/invoke/{service}/{function}/'`)
|
33 | .option('--no-reuse', `Do not reuse the container which was started by the 'fun local start {service}/{function}' command.`)
|
34 | .parse(process.argv);
|
35 |
|
36 | if (program.args.length > 1) {
|
37 | console.error();
|
38 | console.error(" error: unexpected argument '%s'", program.args[1]);
|
39 | program.help();
|
40 | }
|
41 |
|
42 | notifier.notify();
|
43 |
|
44 | getVisitor().then(visitor => {
|
45 | visitor.pageview('/fun/local/invoke').send();
|
46 |
|
47 | require('../lib/commands/local/invoke').invoke(program.args[0], program)
|
48 | .then(() => {
|
49 | visitor.event({
|
50 | ec: 'local invoke',
|
51 | ea: 'invoke',
|
52 | el: 'success',
|
53 | dp: '/fun/local/invoke'
|
54 | }).send();
|
55 |
|
56 | autoExit();
|
57 | })
|
58 | .catch(error => {
|
59 | visitor.event({
|
60 | ec: 'local invoke',
|
61 | ea: 'invoke',
|
62 | el: 'error',
|
63 | dp: '/fun/local/invoke'
|
64 | }).send();
|
65 |
|
66 | require('../lib/exception-handler')(error);
|
67 | });
|
68 | });
|