-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (25 loc) · 613 Bytes
/
script.js
File metadata and controls
28 lines (25 loc) · 613 Bytes
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
const readline = require("readline")
const parseCommand = require("./parseCommand")
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
async function start() {
while (true) {
try {
const commandString = await waitForCommand()
printFormattedJSON(await parseCommand(commandString))
} catch (e) {
console.error(`${e.name}: ${e.message}`)
}
}
}
start()
function waitForCommand() {
return new Promise(resolve => {
rl.question("> ", resolve)
})
}
function printFormattedJSON(string) {
console.log(JSON.stringify(string, null, 2))
}