-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash.js
More file actions
32 lines (27 loc) · 773 Bytes
/
bash.js
File metadata and controls
32 lines (27 loc) · 773 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
29
30
31
32
const runPwdCmd = require('./pwd');
const lsCmd = require('./ls')
const catCmd = require('./cat')
const curlCmd = require('./curl')
// Done callback function
const done = output => {
process.stdout.write('\n')
process.stdout.write(output)
process.stdout.write("\nprompt > ")
}
// Output a prompt
process.stdout.write('prompt > ')
// The stdin 'data' event fires after a user types in a line
process.stdin.on('data', (data) => {
const inputs = data.toString().trim().split(' ');
const cmd = inputs[0]
process.stdout.write('You typed: ' + cmd);
if (cmd === 'pwd') {
runPwdCmd(done)
} else if (cmd === 'ls') {
lsCmd(done)
} else if (cmd === 'cat') {
catCmd(done, inputs[1])
} else if (cmd === 'curl') {
curlCmd(done, inputs[1])
}
})