UNPKG

572 BPlain TextView Raw
1import {resolve as pathResolve} from 'path';
2import usage from './actions/usage';
3
4module.exports = (command, args, options) => {
5 const commandFile = pathResolve(__dirname, `commands/${command}`);
6 let HandlerFunction;
7 try {
8 HandlerFunction = require(commandFile).default;
9 } catch (e) {
10 console.error(`unknown command "${command}"`);
11 console.error(`\t${e.message}`);
12 throw usage();
13 }
14 const ret = HandlerFunction.apply(options, args);
15 if (ret === true || ret === undefined) {
16 return 0;
17 } else if (ret === false) {
18 return 1;
19 } else {
20 return ret;
21 }
22};