forked from zhanghorace1/node-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash.js
35 lines (32 loc) · 942 Bytes
/
bash.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
process.stdout.write('prompt > ');
process.stdin.on("data", (data) => {
const cmd = data.toString().trim(); //pwd curl url
const fncArgs = cmd.split(' ') // ['pwd'] ['curl', 'url']
const importedObj = require(`./${fncArgs[0]}`)
const fn = importedObj[`${fncArgs[0]}`]
if(fncArgs.length > 1) {
fn(fncArgs[1])
} else {
fn()
}
// if (cmd === "pwd") {
// const pwdObject = require('./pwd')
// pwdObject.pwd()
// }
// if (cmd === "ls"){
// const lsObject = require('./ls')
// lsObject.ls()
// }
// //process.stdout.write("You typed: " + cmd);
// //process.stdout.write("\nprompt > ");
// if (cmd.slice(0,3) === 'cat') {
// const catObject = require('./cat')
// const arg = cmd.split(' ')[1]
// catObject.cat(arg)
// }
// if (cmd.slice(0,4) === 'curl') {
// const curlObject = require('./curl')
// const arg = cmd.split(' ')[1]
// curlObject.curl(arg)
// }
})