-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.js
100 lines (90 loc) · 3.08 KB
/
parser.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
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
var prompt = require('prompt');
import {config} from './config';
import debug from './debug';
import {DEV} from './header';
import {listConnections} from './connection';
import {Actions} from './actions';
import {EventHandler} from './eventHandler';
import {singleTransfer} from './connection';
import {sendMessage, sendFile, requestFile} from './connection';
import {syncFiles} from './utility';
export const getAnotherCommand = () => {
prompt.get( config.prompt, function(err, result) {
if (err) console.error(err);
else {
// console.log(result);
var statement = result.question.split(" ");
var command = statement[0];
var trunc = result.question.indexOf(' ');
statement = result.question.substr(trunc+1);
if(command == 'ls'){
debug.log("Another Command: ls", DEV)
Actions.listFiles();
}
else if(command == 'mkdir'){
debug.log("Another Command: mkdir", DEV)
Actions.createDirectory(statement);
}
else if(command == 'pwd'){
debug.log("Another Command: pwd", DEV)
Actions.currentDirectory();
}
else if(command == 'cd'){
debug.log("Another Command: cd", DEV)
Actions.changeDirectory(statement);
}
else if(command == 'touch'){
debug.log("Another Command: touch", DEV);
Actions.createFile(statement);
}
else if(command == 'rm'){
debug.log("Another Command: remove", DEV)
Actions.deleteFile(statement);
}
else if(command == 'exit'){
process.exit(0);
console.log("Exited");
}
else{
if(DEV){
statement = statement.split(" ");
// console.log(statement);
if(command == 'FILE_TABLE'){
Actions.showFileTable();
}
if(command == 'upload'){
// EventHandler.handleEvent('UPLOAD_FILE',{'f_name':'hello.txt'});
singleTransfer('./root/hello/', 'hello', '172.15.45.124');
// getIO().emit('event', {'event':'UPLOAD_FILE', 'f_name':'hello.txt'});
}
if(command == 'message'){
EventHandler.broadcastEvent('USR_MSG',{'message':statement[0]});
}
if(command == 'LS_CONN'){
listConnections();
}
if(command == 'single_message'){
sendMessage(statement[0], statement[1]);
}
if(command == 'send_file'){
sendFile(statement[0], statement[1]);
}
if(command == 'request_file'){
requestFile(statement[0], statement[1]);
}
if(command == 'sync_files'){
syncFiles();
}
if(command == 'request_file_table'){
EventHandler.broadcastEvent('REQ_FILE_TABLE',{});
}
if(command == 'execute'){
EventHandler.broadcastEvent('EXECUTE',{});
}
}
}
//invalidCommand();
}
getAnotherCommand();
});
}