-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
26 lines (21 loc) · 852 Bytes
/
main.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
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const SkyUtils = require("./utils");
const COMMANDS_PATH = path.join(__dirname, "commands");
const argv = require('yargs')
.usage('Usage: $0 <command> [options]')
const commands = fs.readdirSync(COMMANDS_PATH);
for(let commandFile of commands) {
const commandFilePath = path.join(COMMANDS_PATH, commandFile);
const CommandClass = require(commandFilePath);
const command = new CommandClass();
const commandName = path.basename(commandFile, path.extname(commandFile));
//For each of our commands, load it into yargs
argv.command(commandName, command.description, command.options, async (...args) => { try {
await command.callback(...args);
} catch(e) {
SkyUtils.logError(e);
} });
}
argv.help('h').alias('h', 'help').argv