oebot
Version:
OEBot 命令行工具
50 lines (49 loc) • 1.83 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.exitHandler = void 0;
const minimist_1 = __importDefault(require("minimist"));
const node_path_1 = __importDefault(require("node:path"));
const colors_1 = require("./utils/colors");
const commands_1 = require("./commands");
const versionCheck_1 = require("./utils/versionCheck");
const notice_1 = require("./utils/notice");
const pkg = require(node_path_1.default.join(__dirname, '../package.json'));
const args = (0, minimist_1.default)(process.argv.slice(2));
const cmd = args._[0];
const Head = `OEBot CLI v${pkg.version}\n\n`;
const HelpHead = `用法:oe <命令> [选项]\n\n命令列表:`;
const exitHandler = () => {
process.stdout.write(colors_1.colors.yellow('\n已退出 OEBot CLI'));
process.exit(0);
};
exports.exitHandler = exitHandler;
const cli = async () => {
/** 捕获 Ctrl C 中断退出 */
process.on('SIGINT', exports.exitHandler);
if (args.v || args.version) {
return console.log(pkg.version);
}
if (!cmd || !Object.keys(commands_1.cmds).includes(cmd)) {
const helps = Object.values(commands_1.cmds).map((e) => e.help);
console.log('\n' + Head + HelpHead + helps.join('') + '\n');
}
else {
try {
args._.shift();
if (args.debug) {
(0, versionCheck_1.versionCheck)();
}
const res = commands_1.cmds[cmd](args);
if (res instanceof Promise)
await res;
}
catch (e) {
console.log(e);
notice_1.notice.error('CLI 执行遇到错误,参考上面输出的日志');
}
}
};
cli();