-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (41 loc) · 1.18 KB
/
index.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 { program } = require('commander');
const Commands = require('./src/commands/index');
/**
*
* Method use to set the custom Commands into Commander.
* Argument must be the program object from the commander package.
*
* @param {Command} program
*/
const initCommands = (program) => {
Commands.forEach((command) => {
const { commandName, argument, action, requiredOptions, options } = command;
let newCommand =
program
.command(commandName)
.argument(argument.type, argument.description)
.action(action);
// Set required options
if (requiredOptions.length > 0) {
requiredOptions.forEach((requiredOption) => {
const { optionStr, optionDesc } = requiredOption;
newCommand.requiredOption(optionStr, optionDesc);
});
}
// Set options
if (options.length > 0) {
options.forEach((option) => {
const { optionStr, optionDesc } = option;
newCommand.option(optionStr, optionDesc);
});
}
});
}
program
.name('rue')
.description('CLI to help recall information')
.version('1.0.4');
// Set custom commands
initCommands(program);
program.parseAsync();