-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (35 loc) · 1.11 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
import { showGoodbye, showGreeting, showWorkDir, changeWorkDir, getHomeDir, promptForNextCommand, validateInput,
showErrorMessage,
getCommandHandler
} from "./src/helpers/index.js";
const startFileManager = () => {
showGreeting();
changeWorkDir(getHomeDir());
showWorkDir();
promptForNextCommand();
process.on('SIGINT', () => {
showGoodbye();
process.exit(0);
});
const commandsStream = process.stdin;
commandsStream.on('data', async (data) => {
const [command, ...args] = data.toString().trim().split(" ");
const isInputValid = validateInput(command, args);
if (!isInputValid) {
showErrorMessage("Invalid input");
promptForNextCommand();
return;
}
try {
const handleCommand = getCommandHandler(command, args);
await handleCommand(args);
showWorkDir();
promptForNextCommand();
} catch (e) {
showErrorMessage("Operation failed");
console.log(e);
promptForNextCommand();
}
})
}
startFileManager();