1 |
|
2 | exports.load = function(sg, _) {
|
3 |
|
4 | var setFlag = function(self, name, value) {
|
5 | if (arguments.length < 3) { value = true; }
|
6 |
|
7 | self[name] = value;
|
8 | self['_'+name] = function() { return value; }
|
9 | };
|
10 |
|
11 | var deleteFlag = function(self, name) {
|
12 |
|
13 | delete self[name];
|
14 | self['_'+name] = function() { return ; }
|
15 | };
|
16 |
|
17 | var parseCmdArgs = sg._parseCmdArgs = function(self, argv) {
|
18 |
|
19 | self.executable = argv[0];
|
20 | self.script = argv[1];
|
21 |
|
22 | var curr, next;
|
23 | for (var i = 2; i < argv.length; i++) {
|
24 | next = i+1 < argv.length ? argv[i+1] : null;
|
25 | curr = argv[i];
|
26 |
|
27 |
|
28 | if ((m = /^--([a-zA-Z_0-9\-]+)=([^ ]+)$/.exec(curr)) && m.length === 3) {
|
29 | setFlag(self, m[1], m[2]);
|
30 | }
|
31 |
|
32 |
|
33 | else if ((m = /^--([a-zA-Z_0-9\-]+)=$/.exec(curr))) {
|
34 | deleteFlag(self, m[1]);
|
35 | }
|
36 |
|
37 |
|
38 | else if ((m = /^--([^ ]+)-$/.exec(curr))) {
|
39 | setFlag(self, m[1], false);
|
40 | }
|
41 |
|
42 |
|
43 | else if ((m = /^--([^ ]+)$/.exec(curr))) {
|
44 | setFlag(self, m[1]);
|
45 | }
|
46 |
|
47 | }
|
48 |
|
49 | };
|
50 |
|
51 | return sg;
|
52 | };
|
53 |
|