-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseInput.js
More file actions
48 lines (42 loc) · 1.6 KB
/
ParseInput.js
File metadata and controls
48 lines (42 loc) · 1.6 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
function readArgs(command) {
if(!command)
return {cmd: "empty", argumentos: {path: "", str_to_find: "", opt: [], args: false} };
let cmd_list = command.trim().split(/\s+(.*)/).filter(Boolean);
if(cmd_list.length === 1)
return {cmd: cmd_list[0], argumentos: {path: "", str_to_find: "", opt: [], args: false} };
let [comando, argumentos] = cmd_list;
argumentos = argumentos.split(" ");
let options = [];
let path = "~";
let str_to_find = "";
for(arg of argumentos) {
if (arg.startsWith('-') && arg.length > 1) { // Check for '-' options
parameters = arg.slice(1, arg.length) // Ficar apenas com '-abc' -> 'abc'
options = [...options, ...parameters] // Fazer append as options de [a ,b, c], Juntar duas listas basicamente
} else { // Vejo o que eu quero procurar tipo 'show RH'
if (!path)
path = arg;
else { // Procurar qual o argumento e o path
str_to_find = path;
str_to_find = str_to_find.replace(/^"+|"+$/g, '');
path = arg;
}
}
}
// Process Path
if(!path.includes('/') && path !== ".")
path = paths.currentPath + '/' + path;
let path_not_parsed = path;
path = pathParser(path);
const input = {
cmd: comando,
argumentos: {
path: path,
str_to_find: str_to_find,
opt: options,
args: true,
path_not_parsed: path_not_parsed
}
};
return input;
}