1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | process.on('unhandledRejection', e => {
|
12 | throw e;
|
13 | });
|
14 |
|
15 | const sade = require('sade');
|
16 |
|
17 | module.exports.run = (args /*: any*/) => {
|
18 | const data = require('../commands/index.js');
|
19 | const instance = sade('fusion').version(require('../package.json').version);
|
20 | for (const [command, metadata] of Object.entries(data)) {
|
21 | if (metadata instanceof Object) {
|
22 |
|
23 | instance.command(command).describe(metadata.descr);
|
24 |
|
25 |
|
26 | if (metadata.options) {
|
27 |
|
28 | for (const [opt, optmeta] of Object.entries(metadata.options)) {
|
29 | if (optmeta instanceof Object) {
|
30 |
|
31 | instance.option('--' + opt, optmeta.describe, optmeta.default);
|
32 | }
|
33 | }
|
34 | }
|
35 | }
|
36 | instance.action((...args) =>
|
37 |
|
38 | require(`../commands/${command}.js`).run(...args)
|
39 | );
|
40 | }
|
41 | return instance.parse(typeof args === 'string' ? args.split(' ') : args);
|
42 | };
|