UNPKG

1.49 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3/* eslint-disable quotes */
4
5'use strict';
6
7const program = require('commander');
8const getVisitor = require('../lib/visitor').getVisitor;
9const notifier = require('../lib/update-notifier');
10
11program
12 .name('fun invoke')
13 .description('invoke deployed function.')
14 .option('-e, --event [event]', `Event data (strings) passed to the function during invocation,
15 which is empty sting by default if this option is not specified`, '')
16 .option('-f, --event-file <path>', `A file containing event data passed to the function during invoke.`)
17 .option('-s, --event-stdin', 'Read from standard input, to support script pipeline.')
18 .option('-t, --invocation-type <invocationType>', `Invocation type: optional value "async"|"sync", default value "sync"`, 'sync')
19
20 .parse(process.argv);
21
22if (program.args.length > 1) {
23 console.error();
24 console.error(" error: unexpected argument '%s'", program.args[1]);
25 program.help();
26}
27
28notifier.notify();
29
30getVisitor().then(visitor => {
31 visitor.pageview('/fun/invoke').send();
32
33 require('../lib/commands/invoke')(program.args[0], program)
34 .then(() => {
35 visitor.event({
36 ec: 'invoke',
37 ea: 'invoke',
38 el: 'success',
39 dp: '/fun/invoke'
40 }).send();
41 })
42 .catch(error => {
43 visitor.event({
44 ec: 'invoke',
45 ea: 'invoke',
46 el: 'error',
47 dp: '/fun/invoke'
48 }).send();
49
50 require('../lib/exception-handler')(error);
51 });
52});
\No newline at end of file