forked from infinitex-tech/infeos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·50 lines (42 loc) · 1.15 KB
/
cli.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
50
#!/usr/bin/env node
const commands = require('./cli-commands/commands');
const { exec } = require('child_process');
const globalExceptionHandling = require('./utils/global-exception-handling');
run = () => {
let menu = require('yargs');
for (const command of commands) {
menu.command(command.command, command.description, command.argumentsProcessor, command.commandProcessor);
}
menu.command({
command: '*',
handler(args) {
exec(`${args['$0']} help`, (err, stdout, stderr) => {
if (err) {
throw new Error('Could not execute help');
return;
}
console.log(`${stdout}`);
console.error(`${stderr}`);
});
}
});
menu.help('help');
menu.option('silent', {
alias: 's',
default: false
});
menu.version();
menu.demandCommand();
menu.recommendCommands();
menu.showHelpOnFail();
menu.argv;
globalExceptionHandling.handleException(err => {
console.error(`${(new Date).toUTCString()} unhandledException:`, err.message)
console.error(err.stack)
})
globalExceptionHandling.handleRejection(err => {
console.error(`${(new Date).toUTCString()} unhandledRejection:`, err.message)
console.error(err.stack)
})
};
run();