-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
98 lines (69 loc) · 2.13 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const readline = require('readline');
const model = require('./model');
const {log, biglog, errorlog, colorize} = require("./out");
const cmds = require("./cmds");
// Mensaje inicial
biglog ('CORE Quiz', 'green');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: colorize("quiz > ", 'blue'),
completer: (line) => {
const completions = 'h help add delete edit list test p play credits q quit'.split(' ');
const hits = completions.filter((c) => c.startsWith(line));
// show all completions if none found
return [hits.length ? hits : completions, line];
}
});
rl.prompt();
rl.on('line', (line) => {
let args = line.split(" ");
let cmd =args[0].toLowerCase().trim();
switch (cmd) {
case '':
rl.prompt();
break;
case 'help':
case 'h':
cmds.helpCmd(rl);
break;
case 'quit':
case 'q':
cmds.quitCmd(rl);
break;
case 'add':
cmds.addCmd(rl);
break;
case 'list':
cmds.listCmd(rl);
break;
case 'show':
cmds.showCmd(rl, args[1]);
break;
case 'test':
cmds.testCmd(rl, args[1]);
break;
case 'play':
case 'p':
cmds.playCmd(rl);
break;
case 'delete':
cmds.deleteCmd(rl, args[1]);
break;
case 'edit':
cmds.editCmd(rl, args[1]);
break;
case 'credits':
cmds.creditsCmd(rl);
break;
default:
log(`Comando desconocido: '${colorize(cmd, 'red')}'`);
log(`Use ${colorize('help', 'green')}' para ver todos los comandos disponibles.`);
rl.prompt();
break;
}
})
.on('close', () => {
log('Adios!');
process.exit(0);
});