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 |
|
11 |
|
12 | program
|
13 | .name('fun edge invoke')
|
14 | .description(
|
15 | `Execute your function in a local Link IoT Edge environment which replicates the release
|
16 | environment almost identically. You can pass in the event body via stdin or by using
|
17 | the -e (--event) parameter.`)
|
18 | .usage('[options] <[service/]function>')
|
19 | .option('--debug',
|
20 | `Specify your function executes in debug mode, and listens
|
21 | on port 5700 at localhost for debuggers to connect`)
|
22 | .option('-e, --event <path>',
|
23 | `A file containing event data passed to the function during
|
24 | invoke, If this option is not specified, it defaults to
|
25 | reading event from stdin`)
|
26 | .option('-c, --config <ide/debugger>',
|
27 | `Output configurations for the specified ide/debugger, where
|
28 | the ide/debugger can currently only be vscode`)
|
29 | .option('--output-debugger-configs',
|
30 | `Output configurations for all debuggers. It will override
|
31 | the behavior of --config option`)
|
32 | .parse(process.argv);
|
33 |
|
34 | if (!program.args.length) {
|
35 | console.error();
|
36 | console.error(" error: missing required argument `%s'", '[service/]function');
|
37 | program.help();
|
38 | }
|
39 |
|
40 | if (!program.args.length > 1) {
|
41 | console.error();
|
42 | console.error(" error: unexpected argument `%s'", program.args[1]);
|
43 | program.help();
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | if (program.debug) {
|
50 | program.debugPort = '5700';
|
51 | }
|
52 | if (program.debugPort) {
|
53 | const debugPort = parseInt(program.debugPort);
|
54 | if (Number.isNaN(debugPort)) {
|
55 | throw new Error(`\n error: not a number '${program.debugPort}'\n`);
|
56 | }
|
57 | program.debugPort = debugPort;
|
58 | }
|
59 |
|
60 |
|
61 | if (program.config) {
|
62 | if (program.config !== 'vscode') {
|
63 | throw new Error(`\n error: invalid value '${program.config}'\n`);
|
64 | }
|
65 | program.outputDebuggerConfigs = true;
|
66 | }
|
67 |
|
68 | program.event = program.event || '-';
|
69 |
|
70 | notifier.notify();
|
71 |
|
72 | getVisitor().then(visitor => {
|
73 | visitor.pageview('/fun/edge/invoke').send();
|
74 |
|
75 | require('../lib/commands/edge/invoke')(program.args[0], program)
|
76 | .then(() => {
|
77 | visitor.event({
|
78 | ec: 'edge',
|
79 | ea: 'invoke',
|
80 | el: 'success',
|
81 | dp: '/fun/edge'
|
82 | }).send();
|
83 | })
|
84 | .catch(error => {
|
85 | visitor.event({
|
86 | ec: 'edge',
|
87 | ea: 'invoke',
|
88 | el: 'error',
|
89 | dp: '/fun/edge'
|
90 | }).send();
|
91 |
|
92 | require('../lib/exception-handler')(error);
|
93 | });
|
94 | });
|
95 |
|