-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
54 lines (51 loc) · 1.25 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
51
52
53
54
const { parseRegex } = require("./src/components/parseRegex");
const repl = require("repl");
function evaluate(cmd, context, filename, callback) {
callback(null, parseRegex(cmd));
}
const initializeRepl = () => {
const replServer = repl.start({
prompt: "> ",
input: process.stdin,
output: process.stdout,
eval: evaluate,
});
replServer.on("exit", () => {
console.log("Have a nice day!");
process.exit(0);
});
replServer.defineCommand("end", {
help: "Exits the program",
action(name) {
this.clearBufferedCommand();
console.log("Have a nice day!");
process.exit(0);
},
});
replServer.defineCommand("quit", {
help: "Exits the program",
action(name) {
this.clearBufferedCommand();
console.log("Have a nice day!");
process.exit(0);
},
});
replServer.defineCommand("q", {
help: "Exits the program",
action(name) {
this.clearBufferedCommand();
console.log("Have a nice day!");
process.exit(0);
},
});
};
if (require.main == module) {
if (process.argv.length >= 3) {
// Take input from argument
console.log(parseRegex(process.argv[2]));
} else {
// Interactive prompt
initializeRepl();
}
}
module.exports = { initializeRepl };