-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
49 lines (43 loc) · 1.09 KB
/
index.js
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
'use strict';
const BbPromise = require('bluebird');
class ServerlessCommandLineEventArgs {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.commands = {
invoke: {
options: {
event: {
usage: 'Event JSON passes function (e.g. --event \'{"foo":"var"}\' or -e \'{"foo":"var"}\')',
shortcut: 'e'
}
}
},
};
this.hooks = {
'before:invoke:invoke': this.setEvent.bind(this)
}
}
setEvent() {
if ( this.options.event !== undefined || this.options.event !== true ) {
if ( this.isJson(this.options.event) ) {
this.options.data = JSON.parse(this.options.event)
} else {
this.options.data = this.options.event
}
}
return BbPromise.resolve(this);
}
isJson(arg) {
if (typeof(arg) !== "string") {
return false;
}
try {
var arg = (!JSON) ? eval("(" + arg + ")") : JSON.parse(arg);
return true;
} catch(e) {
return false;
}
}
}
module.exports = ServerlessCommandLineEventArgs;