-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·45 lines (37 loc) · 1.4 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
#!/usr/bin/env node
const josnlib = require("josnlib");
const josncli = require("./dist");
const packageJson = require("./package.json");
function main () {
const [,, ...args] = process.argv;
const [flagArgs, nonFlagArgs] = josnlib.classifyArgs(args);
const cmdOptions = josnlib.getCmdOptions(flagArgs);
const commandFlags = josnlib.flags.filter(flag => flag.isCommand);
const trueCommandFlags = commandFlags.filter(flag => cmdOptions[flag.name] === true);
if (trueCommandFlags.length > 1) {
// Multiple command flags were specified
console.log(`Multiple commands cannot be run at the same time!`);
trueCommandFlags.forEach((c, i) => console.log(`\tcommand #${i+1}: ${c.doubleFlag.padEnd(15)} => ${c.description}`));
return;
}
const { commands } = josncli;
if (cmdOptions.green) {
commands.greenCommand(cmdOptions);
} else if (cmdOptions.help) {
commands.helpCommand(cmdOptions);
} else if (cmdOptions.license) {
commands.licenseCommand(cmdOptions);
} else if (cmdOptions.printArgs) {
commands.printArgsCommand(cmdOptions, args);
} else if (cmdOptions.printDemos) {
commands.printDemosCommand(cmdOptions);
} else if (cmdOptions.printFlags) {
commands.printFlagsCommand(cmdOptions);
} else if (cmdOptions.version) {
commands.versionCommand(cmdOptions, packageJson);
} else {
commands.defaultCommand(cmdOptions, nonFlagArgs);
}
}
// console.log("Thanks for running JOSN.");
main();