-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (46 loc) · 1.4 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
#!/usr/bin/env node
import inquirer from 'inquirer';
import { logNetworkInfo } from './features/networkInfo.js'
import { runSpeedTest } from './features/speedTest.js'
// Function to display the interactive menu
async function mainMenu() {
const choices = [
{ name: 'Network Info', value: 'networkInfo' },
{ name: 'Speed Test', value: 'speedTest' },
{ name: 'Exit', value: 'exit' }
];
try {
const answer = await inquirer.prompt([
{
type: 'list',
name: 'selection',
message: 'Select an option:',
choices: choices
}
]);
switch (answer.selection) {
case 'networkInfo':
await logNetworkInfo();
break;
case 'speedTest':
await runSpeedTest();
break;
case 'exit':
console.log('Goodbye!');
return;
default:
console.log('Invalid option!');
}
// // Re-display the menu after the task is done
// await mainMenu();
} catch (error) {
console.error('Prompt was closed unexpectedly');
}
}
// Listen for SIGINT (Ctrl+C)
process.on('SIGINT', () => {
console.log('\nExiting the application... Goodbye!');
process.exit(0); // Exit the application cleanly
});
// Start the CLI app
mainMenu();