-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (43 loc) · 1.25 KB
/
index.js
File metadata and controls
55 lines (43 loc) · 1.25 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
49
50
51
52
53
54
55
'use strict';
class ArgsManager {
constructor(args) {
this.args = args;
}
static removeQuotes(string) {
return string.replace(/"/g, '').replace(/'/g, '');
}
/**
* look up the argument in the argument list
* @param {string} argName the name of the argument
* @returns {boolean} true of argument found, false otherwise
*/
findArg(argName) {
let found = false;
for (let i = 0; i < this.args.length; i++) {
if (this.args[i].includes('=')) { //if --blala=pathto format
found = this.args[i].includes(argName) || found;
} else {
found = this.args[i].trim() === argName || found;
}
}
return found;
}
findKey(argName) {
for (let i = 0; i < this.args.length; i++) {
if (this.args[i].includes('=') && this.args[i].includes(argName)) {
let arg = this.args[i].replace(argName + '=', '');
return ArgsManager.removeQuotes(arg);
} else if (this.args[i] === argName) {
if (i + 1 === this.args.length) {
return undefined;
} else {
if (this.args[i + 1].includes('--')) {
return undefined;
}
return ArgsManager.removeQuotes(this.args[i + 1]);
}
}
}
}
}
module.exports = ArgsManager;