-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
115 lines (100 loc) · 2.34 KB
/
index.js
File metadata and controls
115 lines (100 loc) · 2.34 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* This script is to help in common tasks
* This include: Checking OS info ...etc
*
*/
var readline = require('readline')
var os = require('os')
var fs = require('fs')
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const username = os.userInfo().username
/**
* ===========================
* System info
* ===========================
*/
const getSystemInfo = () => {
console.log(`Let me give you some info: \n
Processors: \n\
${os.cpus().map(cpu => {
return `Model ${cpu.model} Speed: ${cpu.speed}\n`
})}
Memory: ${os.totalmem} \n\
Architecture: ${os.arch()} \n\
Platform: ${os.platform()} \n\
Release: ${os.release} \n\
Current User: ${username} \n\
Shell: ${os.userInfo().shell} \n\
Type: ${os.type} \n\
Home: ${os.homedir()} \n\
Uptime: ${os.uptime()} \n\
Host: ${os.hostname()}
`)
}
/**
* ============================
* Display Help
* ============================
*/
const displayHelp = () => {
console.log(
`Help menu \n
*Press Enter after every command* \n\
Press: \n
1 to get information about your system \n\
help to show this menu`
)
}
/**
* ============================
* Filesystem
* ============================
*/
const filesystem = () => {
console.log(
`Welcome to the file Manager menu 😎`
)
rl.question('Please type the path you want: \n\
', (answer) => {
fs.readdir(answer, (err, files) => {
if (err) {
console.error(err)
}
console.table(files)
filesystem()
})
})
}
/**
* ============================
* Main Menu
* ============================
*/
rl.write(`Welcome Awesome ${username} 😊\n
What do you want to do? type help for more info \n\
1) View Sytem info \n\
2) File Manager \n\
`)
rl.on('line', (line) => {
switch (line.toLowerCase()) {
case 'exit':
console.warn(`Good bye ${username} 👋 \n`)
rl.close()
break;
case 'help':
displayHelp()
break;
case '1':
getSystemInfo()
break;
case '2':
filesystem()
break;
default:
console.log(`${line} is not a recognized command. Type Help for more info😢`)
break;
}
})