-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathTwilioRunCommand.js
49 lines (37 loc) · 1.31 KB
/
TwilioRunCommand.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
const {
convertYargsOptionsToOclifFlags,
normalizeFlags,
createExternalCliOptions,
getRegionAndEdge,
} = require('./utils');
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
function createTwilioRunCommand(name, path, inheritedFlags = []) {
const { handler, cliInfo, describe } = require(path);
const { flags, aliasMap } = convertYargsOptionsToOclifFlags(cliInfo.options);
const commandClass = class extends TwilioClientCommand {
async run() {
await super.run();
const flags = normalizeFlags(this.flags, aliasMap, process.argv);
const externalOptions = createExternalCliOptions(
flags,
this.twilioClient
);
const { edge, region } = getRegionAndEdge(flags, this);
flags.region = region;
flags.edge = edge;
const opts = Object.assign({}, flags, this.args);
return handler(opts, externalOptions);
}
};
const inheritedFlagObject = inheritedFlags.reduce((current, flag) => {
return {
...current,
[flag]: TwilioClientCommand.flags[flag],
};
}, {});
Object.defineProperty(commandClass, 'name', { value: name });
commandClass.description = describe;
commandClass.flags = Object.assign(flags, inheritedFlagObject);
return commandClass;
}
module.exports = { createTwilioRunCommand };