-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.js
45 lines (33 loc) · 1.13 KB
/
console.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
const readline = require('readline');
const { createQuery } = require('./nestedQueryParser');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const askQuestion = (query) => {
return new Promise((resolve) => rl.question(query, resolve));
};
const processInput = async () => {
console.log("Press 'quit' to exit at any time.\n");
while (true) {
const queryString = await askQuestion('\nEnter your query string: ');
if (queryString.trim().toLowerCase() === 'quit') break;
try {
const result = createQuery(queryString);
if (result.errorCode) {
console.error(`Error Code: ${result.errorCode}`);
console.error(`Message: ${result.message}`);
} else {
console.log("Parsed JSON:");
console.log(JSON.stringify(result.parsedJSON, null, 2));
console.log("\nElasticsearch Query:");
console.log(JSON.stringify(result.query, null, 2));
console.log("-----------------------------");
}
} catch (error) {
console.error('Error processing input:', error.message);
}
}
rl.close();
};
processInput();