@makano/rew 1.1.81 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/coffeescript/browser.js +144 -139
- package/lib/coffeescript/cake.js +132 -133
- package/lib/coffeescript/coffeescript.js +437 -381
- package/lib/coffeescript/command.js +806 -724
- package/lib/coffeescript/grammar.js +1908 -2474
- package/lib/coffeescript/helpers.js +509 -473
- package/lib/coffeescript/index.js +228 -215
- package/lib/coffeescript/lexer.js +2282 -1909
- package/lib/coffeescript/nodes.js +9782 -9202
- package/lib/coffeescript/optparse.js +255 -227
- package/lib/coffeescript/parser.js +20305 -1265
- package/lib/coffeescript/register.js +107 -87
- package/lib/coffeescript/repl.js +307 -284
- package/lib/coffeescript/rewriter.js +1389 -1079
- package/lib/coffeescript/scope.js +176 -172
- package/lib/coffeescript/sourcemap.js +242 -227
- package/lib/rew/cli/cli.js +296 -239
- package/lib/rew/cli/log.js +27 -27
- package/lib/rew/cli/run.js +8 -8
- package/lib/rew/cli/utils.js +353 -199
- package/lib/rew/const/config_path.js +2 -2
- package/lib/rew/const/default.js +38 -53
- package/lib/rew/const/files.js +11 -14
- package/lib/rew/const/opt.js +6 -6
- package/lib/rew/css/theme.css +1 -1
- package/lib/rew/functions/core.js +55 -55
- package/lib/rew/functions/curl.js +23 -0
- package/lib/rew/functions/emitter.js +52 -55
- package/lib/rew/functions/exec.js +25 -25
- package/lib/rew/functions/export.js +17 -17
- package/lib/rew/functions/fs.js +57 -59
- package/lib/rew/functions/future.js +29 -21
- package/lib/rew/functions/id.js +8 -9
- package/lib/rew/functions/import.js +106 -122
- package/lib/rew/functions/map.js +10 -10
- package/lib/rew/functions/match.js +35 -42
- package/lib/rew/functions/path.js +8 -8
- package/lib/rew/functions/require.js +32 -36
- package/lib/rew/functions/sleep.js +2 -2
- package/lib/rew/functions/stdout.js +18 -18
- package/lib/rew/functions/types.js +82 -106
- package/lib/rew/html/ui.html +12 -12
- package/lib/rew/html/ui.js +196 -201
- package/lib/rew/main.js +14 -14
- package/lib/rew/misc/bin.js +37 -0
- package/lib/rew/misc/findAppInfo.js +13 -13
- package/lib/rew/misc/findAppPath.js +15 -15
- package/lib/rew/misc/req.js +7 -0
- package/lib/rew/misc/seededid.js +8 -8
- package/lib/rew/models/enum.js +12 -12
- package/lib/rew/models/struct.js +30 -32
- package/lib/rew/modules/compiler.js +237 -209
- package/lib/rew/modules/fs.js +10 -10
- package/lib/rew/modules/runtime.js +17 -21
- package/lib/rew/modules/yaml.js +27 -30
- package/lib/rew/pkgs/conf.js +82 -92
- package/lib/rew/pkgs/data.js +10 -10
- package/lib/rew/pkgs/date.js +27 -27
- package/lib/rew/pkgs/env.js +5 -5
- package/lib/rew/pkgs/modules/data/bintree.js +51 -51
- package/lib/rew/pkgs/modules/data/doublylinked.js +84 -84
- package/lib/rew/pkgs/modules/data/linkedList.js +72 -72
- package/lib/rew/pkgs/modules/data/queue.js +18 -18
- package/lib/rew/pkgs/modules/data/stack.js +18 -18
- package/lib/rew/pkgs/modules/threads/worker.js +36 -36
- package/lib/rew/pkgs/modules/ui/classes.js +181 -184
- package/lib/rew/pkgs/pkgs.js +9 -9
- package/lib/rew/pkgs/rune.js +373 -410
- package/lib/rew/pkgs/threads.js +62 -66
- package/lib/rew/pkgs/ui.js +148 -160
- package/lib/rew/qrew/compile.js +12 -0
- package/package.json +4 -3
@@ -1,230 +1,258 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
|
-
(function() {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
// The first non-option is considered to be the start of the file (and file
|
15
|
-
// option) list, and all subsequent arguments are left unparsed.
|
16
|
-
|
17
|
-
// The `coffee` command uses an instance of **OptionParser** to parse its
|
18
|
-
// command-line arguments in `src/command.coffee`.
|
19
|
-
exports.OptionParser = OptionParser = class OptionParser {
|
20
|
-
// Initialize with a list of valid options, in the form:
|
21
|
-
|
22
|
-
// [short-flag, long-flag, description]
|
23
|
-
|
24
|
-
// Along with an optional banner for the usage help.
|
25
|
-
constructor(ruleDeclarations, banner) {
|
26
|
-
this.banner = banner;
|
27
|
-
this.rules = buildRules(ruleDeclarations);
|
28
|
-
}
|
29
|
-
|
30
|
-
// Parse the list of arguments, populating an `options` object with all of the
|
31
|
-
// specified options, and return it. Options after the first non-option
|
32
|
-
// argument are treated as arguments. `options.arguments` will be an array
|
33
|
-
// containing the remaining arguments. This is a simpler API than many option
|
34
|
-
// parsers that allow you to attach callback actions for every flag. Instead,
|
35
|
-
// you're responsible for interpreting the options object.
|
36
|
-
parse(args) {
|
37
|
-
var argument, hasArgument, i, isList, len, name, options, positional, rules;
|
38
|
-
// The CoffeeScript option parser is a little odd; options after the first
|
39
|
-
// non-option argument are treated as non-option arguments themselves.
|
40
|
-
// Optional arguments are normalized by expanding merged flags into multiple
|
41
|
-
// flags. This allows you to have `-wl` be the same as `--watch --lint`.
|
42
|
-
// Note that executable scripts with a shebang (`#!`) line should use the
|
43
|
-
// line `#!/usr/bin/env coffee`, or `#!/absolute/path/to/coffee`, without a
|
44
|
-
// `--` argument after, because that will fail on Linux (see #3946).
|
45
|
-
({rules, positional} = normalizeArguments(args, this.rules.flagDict));
|
46
|
-
options = {};
|
47
|
-
// The `argument` field is added to the rule instance non-destructively by
|
48
|
-
// `normalizeArguments`.
|
49
|
-
for (i = 0, len = rules.length; i < len; i++) {
|
50
|
-
({hasArgument, argument, isList, name} = rules[i]);
|
51
|
-
if (hasArgument) {
|
52
|
-
if (isList) {
|
53
|
-
if (options[name] == null) {
|
54
|
-
options[name] = [];
|
55
|
-
}
|
56
|
-
options[name].push(argument);
|
57
|
-
} else {
|
58
|
-
options[name] = argument;
|
59
|
-
}
|
60
|
-
} else {
|
61
|
-
options[name] = true;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
if (positional[0] === '--') {
|
65
|
-
options.doubleDashed = true;
|
66
|
-
positional = positional.slice(1);
|
67
|
-
}
|
68
|
-
options.arguments = positional;
|
69
|
-
return options;
|
70
|
-
}
|
71
|
-
|
72
|
-
// Return the help text for this **OptionParser**, listing and describing all
|
73
|
-
// of the valid options, for `--help` and such.
|
74
|
-
help() {
|
75
|
-
var i, len, letPart, lines, ref, rule, spaces;
|
76
|
-
lines = [];
|
77
|
-
if (this.banner) {
|
78
|
-
lines.unshift(`${this.banner}\n`);
|
79
|
-
}
|
80
|
-
ref = this.rules.ruleList;
|
81
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
82
|
-
rule = ref[i];
|
83
|
-
spaces = 15 - rule.longFlag.length;
|
84
|
-
spaces = spaces > 0 ? repeat(' ', spaces) : '';
|
85
|
-
letPart = rule.shortFlag ? rule.shortFlag + ', ' : ' ';
|
86
|
-
lines.push(' ' + letPart + rule.longFlag + spaces + rule.description);
|
87
|
-
}
|
88
|
-
return `\n${lines.join('\n')}\n`;
|
89
|
-
}
|
90
|
-
|
91
|
-
};
|
92
|
-
|
93
|
-
// Helpers
|
94
|
-
// -------
|
95
|
-
|
96
|
-
// Regex matchers for option flags on the command line and their rules.
|
97
|
-
LONG_FLAG = /^(--\w[\w\-]*)/;
|
98
|
-
|
99
|
-
SHORT_FLAG = /^(-\w)$/;
|
100
|
-
|
101
|
-
MULTI_FLAG = /^-(\w{2,})/;
|
102
|
-
|
103
|
-
// Matches the long flag part of a rule for an option with an argument. Not
|
104
|
-
// applied to anything in process.argv.
|
105
|
-
OPTIONAL = /\[(\w+(\*?))\]/;
|
106
|
-
|
107
|
-
// Build and return the list of option rules. If the optional *short-flag* is
|
108
|
-
// unspecified, leave it out by padding with `null`.
|
109
|
-
buildRules = function(ruleDeclarations) {
|
110
|
-
var flag, flagDict, i, j, len, len1, ref, rule, ruleList, tuple;
|
111
|
-
ruleList = (function() {
|
112
|
-
var i, len, results;
|
113
|
-
results = [];
|
114
|
-
for (i = 0, len = ruleDeclarations.length; i < len; i++) {
|
115
|
-
tuple = ruleDeclarations[i];
|
116
|
-
if (tuple.length < 3) {
|
117
|
-
tuple.unshift(null);
|
118
|
-
}
|
119
|
-
results.push(buildRule(...tuple));
|
120
|
-
}
|
121
|
-
return results;
|
122
|
-
})();
|
123
|
-
flagDict = {};
|
124
|
-
for (i = 0, len = ruleList.length; i < len; i++) {
|
125
|
-
rule = ruleList[i];
|
126
|
-
ref = [rule.shortFlag, rule.longFlag];
|
127
|
-
// `shortFlag` is null if not provided in the rule.
|
128
|
-
for (j = 0, len1 = ref.length; j < len1; j++) {
|
129
|
-
flag = ref[j];
|
130
|
-
if (!(flag != null)) {
|
131
|
-
continue;
|
132
|
-
}
|
133
|
-
if (flagDict[flag] != null) {
|
134
|
-
throw new Error(`flag ${flag} for switch ${rule.name} was already declared for switch ${flagDict[flag].name}`);
|
135
|
-
}
|
136
|
-
flagDict[flag] = rule;
|
137
|
-
}
|
138
|
-
}
|
139
|
-
return {ruleList, flagDict};
|
140
|
-
};
|
141
|
-
|
142
|
-
// Build a rule from a `-o` short flag, a `--output [DIR]` long flag, and the
|
143
|
-
// description of what the option does.
|
144
|
-
buildRule = function(shortFlag, longFlag, description) {
|
145
|
-
var match;
|
146
|
-
match = longFlag.match(OPTIONAL);
|
147
|
-
shortFlag = shortFlag != null ? shortFlag.match(SHORT_FLAG)[1] : void 0;
|
148
|
-
longFlag = longFlag.match(LONG_FLAG)[1];
|
149
|
-
return {
|
150
|
-
name: longFlag.replace(/^--/, ''),
|
151
|
-
shortFlag: shortFlag,
|
152
|
-
longFlag: longFlag,
|
153
|
-
description: description,
|
154
|
-
hasArgument: !!(match && match[1]),
|
155
|
-
isList: !!(match && match[2])
|
156
|
-
};
|
157
|
-
};
|
158
|
-
|
159
|
-
normalizeArguments = function(args, flagDict) {
|
160
|
-
var arg, argIndex, flag, i, innerOpts, j, lastOpt, len, len1, multiFlags, multiOpts, needsArgOpt, positional, ref, rule, rules, singleRule, withArg;
|
161
|
-
rules = [];
|
162
|
-
positional = [];
|
163
|
-
needsArgOpt = null;
|
164
|
-
for (argIndex = i = 0, len = args.length; i < len; argIndex = ++i) {
|
165
|
-
arg = args[argIndex];
|
166
|
-
// If the previous argument given to the script was an option that uses the
|
167
|
-
// next command-line argument as its argument, create copy of the option’s
|
168
|
-
// rule with an `argument` field.
|
169
|
-
if (needsArgOpt != null) {
|
170
|
-
withArg = Object.assign({}, needsArgOpt.rule, {
|
171
|
-
argument: arg
|
172
|
-
});
|
173
|
-
rules.push(withArg);
|
174
|
-
needsArgOpt = null;
|
175
|
-
continue;
|
176
|
-
}
|
177
|
-
multiFlags = (ref = arg.match(MULTI_FLAG)) != null ? ref[1].split('').map(function(flagName) {
|
178
|
-
return `-${flagName}`;
|
179
|
-
}) : void 0;
|
180
|
-
if (multiFlags != null) {
|
181
|
-
multiOpts = multiFlags.map(function(flag) {
|
182
|
-
var rule;
|
183
|
-
rule = flagDict[flag];
|
184
|
-
if (rule == null) {
|
185
|
-
throw new Error(`unrecognized option ${flag} in multi-flag ${arg}`);
|
186
|
-
}
|
187
|
-
return {rule, flag};
|
188
|
-
});
|
189
|
-
// Only the last flag in a multi-flag may have an argument.
|
190
|
-
[...innerOpts] = multiOpts, [lastOpt] = splice.call(innerOpts, -1);
|
191
|
-
for (j = 0, len1 = innerOpts.length; j < len1; j++) {
|
192
|
-
({rule, flag} = innerOpts[j]);
|
193
|
-
if (rule.hasArgument) {
|
194
|
-
throw new Error(`cannot use option ${flag} in multi-flag ${arg} except as the last option, because it needs an argument`);
|
195
|
-
}
|
196
|
-
rules.push(rule);
|
197
|
-
}
|
198
|
-
if (lastOpt.rule.hasArgument) {
|
199
|
-
needsArgOpt = lastOpt;
|
200
|
-
} else {
|
201
|
-
rules.push(lastOpt.rule);
|
202
|
-
}
|
203
|
-
} else if ([LONG_FLAG, SHORT_FLAG].some(function(pat) {
|
204
|
-
return arg.match(pat) != null;
|
205
|
-
})) {
|
206
|
-
singleRule = flagDict[arg];
|
207
|
-
if (singleRule == null) {
|
208
|
-
throw new Error(`unrecognized option ${arg}`);
|
209
|
-
}
|
210
|
-
if (singleRule.hasArgument) {
|
211
|
-
needsArgOpt = {
|
212
|
-
rule: singleRule,
|
213
|
-
flag: arg
|
214
|
-
};
|
215
|
-
} else {
|
216
|
-
rules.push(singleRule);
|
217
|
-
}
|
218
|
-
} else {
|
219
|
-
// This is a positional argument.
|
220
|
-
positional = args.slice(argIndex);
|
221
|
-
break;
|
222
|
-
}
|
223
|
-
}
|
224
|
-
if (needsArgOpt != null) {
|
225
|
-
throw new Error(`value required for ${needsArgOpt.flag}, but it was the last argument provided`);
|
226
|
-
}
|
227
|
-
return {rules, positional};
|
228
|
-
};
|
2
|
+
(function () {
|
3
|
+
var LONG_FLAG,
|
4
|
+
MULTI_FLAG,
|
5
|
+
OPTIONAL,
|
6
|
+
OptionParser,
|
7
|
+
SHORT_FLAG,
|
8
|
+
buildRule,
|
9
|
+
buildRules,
|
10
|
+
normalizeArguments,
|
11
|
+
repeat,
|
12
|
+
splice = [].splice;
|
229
13
|
|
14
|
+
({ repeat } = require('./helpers'));
|
15
|
+
|
16
|
+
// A simple **OptionParser** class to parse option flags from the command-line.
|
17
|
+
// Use it like so:
|
18
|
+
|
19
|
+
// parser = new OptionParser switches, helpBanner
|
20
|
+
// options = parser.parse process.argv
|
21
|
+
|
22
|
+
// The first non-option is considered to be the start of the file (and file
|
23
|
+
// option) list, and all subsequent arguments are left unparsed.
|
24
|
+
|
25
|
+
// The `coffee` command uses an instance of **OptionParser** to parse its
|
26
|
+
// command-line arguments in `src/command.coffee`.
|
27
|
+
exports.OptionParser = OptionParser = class OptionParser {
|
28
|
+
// Initialize with a list of valid options, in the form:
|
29
|
+
|
30
|
+
// [short-flag, long-flag, description]
|
31
|
+
|
32
|
+
// Along with an optional banner for the usage help.
|
33
|
+
constructor(ruleDeclarations, banner) {
|
34
|
+
this.banner = banner;
|
35
|
+
this.rules = buildRules(ruleDeclarations);
|
36
|
+
}
|
37
|
+
|
38
|
+
// Parse the list of arguments, populating an `options` object with all of the
|
39
|
+
// specified options, and return it. Options after the first non-option
|
40
|
+
// argument are treated as arguments. `options.arguments` will be an array
|
41
|
+
// containing the remaining arguments. This is a simpler API than many option
|
42
|
+
// parsers that allow you to attach callback actions for every flag. Instead,
|
43
|
+
// you're responsible for interpreting the options object.
|
44
|
+
parse(args) {
|
45
|
+
var argument, hasArgument, i, isList, len, name, options, positional, rules;
|
46
|
+
// The CoffeeScript option parser is a little odd; options after the first
|
47
|
+
// non-option argument are treated as non-option arguments themselves.
|
48
|
+
// Optional arguments are normalized by expanding merged flags into multiple
|
49
|
+
// flags. This allows you to have `-wl` be the same as `--watch --lint`.
|
50
|
+
// Note that executable scripts with a shebang (`#!`) line should use the
|
51
|
+
// line `#!/usr/bin/env coffee`, or `#!/absolute/path/to/coffee`, without a
|
52
|
+
// `--` argument after, because that will fail on Linux (see #3946).
|
53
|
+
({ rules, positional } = normalizeArguments(args, this.rules.flagDict));
|
54
|
+
options = {};
|
55
|
+
// The `argument` field is added to the rule instance non-destructively by
|
56
|
+
// `normalizeArguments`.
|
57
|
+
for (i = 0, len = rules.length; i < len; i++) {
|
58
|
+
({ hasArgument, argument, isList, name } = rules[i]);
|
59
|
+
if (hasArgument) {
|
60
|
+
if (isList) {
|
61
|
+
if (options[name] == null) {
|
62
|
+
options[name] = [];
|
63
|
+
}
|
64
|
+
options[name].push(argument);
|
65
|
+
} else {
|
66
|
+
options[name] = argument;
|
67
|
+
}
|
68
|
+
} else {
|
69
|
+
options[name] = true;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
if (positional[0] === '--') {
|
73
|
+
options.doubleDashed = true;
|
74
|
+
positional = positional.slice(1);
|
75
|
+
}
|
76
|
+
options.arguments = positional;
|
77
|
+
return options;
|
78
|
+
}
|
79
|
+
|
80
|
+
// Return the help text for this **OptionParser**, listing and describing all
|
81
|
+
// of the valid options, for `--help` and such.
|
82
|
+
help() {
|
83
|
+
var i, len, letPart, lines, ref, rule, spaces;
|
84
|
+
lines = [];
|
85
|
+
if (this.banner) {
|
86
|
+
lines.unshift(`${this.banner}\n`);
|
87
|
+
}
|
88
|
+
ref = this.rules.ruleList;
|
89
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
90
|
+
rule = ref[i];
|
91
|
+
spaces = 15 - rule.longFlag.length;
|
92
|
+
spaces = spaces > 0 ? repeat(' ', spaces) : '';
|
93
|
+
letPart = rule.shortFlag ? rule.shortFlag + ', ' : ' ';
|
94
|
+
lines.push(' ' + letPart + rule.longFlag + spaces + rule.description);
|
95
|
+
}
|
96
|
+
return `\n${lines.join('\n')}\n`;
|
97
|
+
}
|
98
|
+
};
|
99
|
+
|
100
|
+
// Helpers
|
101
|
+
// -------
|
102
|
+
|
103
|
+
// Regex matchers for option flags on the command line and their rules.
|
104
|
+
LONG_FLAG = /^(--\w[\w\-]*)/;
|
105
|
+
|
106
|
+
SHORT_FLAG = /^(-\w)$/;
|
107
|
+
|
108
|
+
MULTI_FLAG = /^-(\w{2,})/;
|
109
|
+
|
110
|
+
// Matches the long flag part of a rule for an option with an argument. Not
|
111
|
+
// applied to anything in process.argv.
|
112
|
+
OPTIONAL = /\[(\w+(\*?))\]/;
|
113
|
+
|
114
|
+
// Build and return the list of option rules. If the optional *short-flag* is
|
115
|
+
// unspecified, leave it out by padding with `null`.
|
116
|
+
buildRules = function (ruleDeclarations) {
|
117
|
+
var flag, flagDict, i, j, len, len1, ref, rule, ruleList, tuple;
|
118
|
+
ruleList = (function () {
|
119
|
+
var i, len, results;
|
120
|
+
results = [];
|
121
|
+
for (i = 0, len = ruleDeclarations.length; i < len; i++) {
|
122
|
+
tuple = ruleDeclarations[i];
|
123
|
+
if (tuple.length < 3) {
|
124
|
+
tuple.unshift(null);
|
125
|
+
}
|
126
|
+
results.push(buildRule(...tuple));
|
127
|
+
}
|
128
|
+
return results;
|
129
|
+
})();
|
130
|
+
flagDict = {};
|
131
|
+
for (i = 0, len = ruleList.length; i < len; i++) {
|
132
|
+
rule = ruleList[i];
|
133
|
+
ref = [rule.shortFlag, rule.longFlag];
|
134
|
+
// `shortFlag` is null if not provided in the rule.
|
135
|
+
for (j = 0, len1 = ref.length; j < len1; j++) {
|
136
|
+
flag = ref[j];
|
137
|
+
if (!(flag != null)) {
|
138
|
+
continue;
|
139
|
+
}
|
140
|
+
if (flagDict[flag] != null) {
|
141
|
+
throw new Error(`flag ${flag} for switch ${rule.name} was already declared for switch ${flagDict[flag].name}`);
|
142
|
+
}
|
143
|
+
flagDict[flag] = rule;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
return { ruleList, flagDict };
|
147
|
+
};
|
148
|
+
|
149
|
+
// Build a rule from a `-o` short flag, a `--output [DIR]` long flag, and the
|
150
|
+
// description of what the option does.
|
151
|
+
buildRule = function (shortFlag, longFlag, description) {
|
152
|
+
var match;
|
153
|
+
match = longFlag.match(OPTIONAL);
|
154
|
+
shortFlag = shortFlag != null ? shortFlag.match(SHORT_FLAG)[1] : void 0;
|
155
|
+
longFlag = longFlag.match(LONG_FLAG)[1];
|
156
|
+
return {
|
157
|
+
name: longFlag.replace(/^--/, ''),
|
158
|
+
shortFlag: shortFlag,
|
159
|
+
longFlag: longFlag,
|
160
|
+
description: description,
|
161
|
+
hasArgument: !!(match && match[1]),
|
162
|
+
isList: !!(match && match[2]),
|
163
|
+
};
|
164
|
+
};
|
165
|
+
|
166
|
+
normalizeArguments = function (args, flagDict) {
|
167
|
+
var arg,
|
168
|
+
argIndex,
|
169
|
+
flag,
|
170
|
+
i,
|
171
|
+
innerOpts,
|
172
|
+
j,
|
173
|
+
lastOpt,
|
174
|
+
len,
|
175
|
+
len1,
|
176
|
+
multiFlags,
|
177
|
+
multiOpts,
|
178
|
+
needsArgOpt,
|
179
|
+
positional,
|
180
|
+
ref,
|
181
|
+
rule,
|
182
|
+
rules,
|
183
|
+
singleRule,
|
184
|
+
withArg;
|
185
|
+
rules = [];
|
186
|
+
positional = [];
|
187
|
+
needsArgOpt = null;
|
188
|
+
for (argIndex = i = 0, len = args.length; i < len; argIndex = ++i) {
|
189
|
+
arg = args[argIndex];
|
190
|
+
// If the previous argument given to the script was an option that uses the
|
191
|
+
// next command-line argument as its argument, create copy of the option’s
|
192
|
+
// rule with an `argument` field.
|
193
|
+
if (needsArgOpt != null) {
|
194
|
+
withArg = Object.assign({}, needsArgOpt.rule, {
|
195
|
+
argument: arg,
|
196
|
+
});
|
197
|
+
rules.push(withArg);
|
198
|
+
needsArgOpt = null;
|
199
|
+
continue;
|
200
|
+
}
|
201
|
+
multiFlags =
|
202
|
+
(ref = arg.match(MULTI_FLAG)) != null
|
203
|
+
? ref[1].split('').map(function (flagName) {
|
204
|
+
return `-${flagName}`;
|
205
|
+
})
|
206
|
+
: void 0;
|
207
|
+
if (multiFlags != null) {
|
208
|
+
multiOpts = multiFlags.map(function (flag) {
|
209
|
+
var rule;
|
210
|
+
rule = flagDict[flag];
|
211
|
+
if (rule == null) {
|
212
|
+
throw new Error(`unrecognized option ${flag} in multi-flag ${arg}`);
|
213
|
+
}
|
214
|
+
return { rule, flag };
|
215
|
+
});
|
216
|
+
// Only the last flag in a multi-flag may have an argument.
|
217
|
+
([...innerOpts] = multiOpts), ([lastOpt] = splice.call(innerOpts, -1));
|
218
|
+
for (j = 0, len1 = innerOpts.length; j < len1; j++) {
|
219
|
+
({ rule, flag } = innerOpts[j]);
|
220
|
+
if (rule.hasArgument) {
|
221
|
+
throw new Error(`cannot use option ${flag} in multi-flag ${arg} except as the last option, because it needs an argument`);
|
222
|
+
}
|
223
|
+
rules.push(rule);
|
224
|
+
}
|
225
|
+
if (lastOpt.rule.hasArgument) {
|
226
|
+
needsArgOpt = lastOpt;
|
227
|
+
} else {
|
228
|
+
rules.push(lastOpt.rule);
|
229
|
+
}
|
230
|
+
} else if (
|
231
|
+
[LONG_FLAG, SHORT_FLAG].some(function (pat) {
|
232
|
+
return arg.match(pat) != null;
|
233
|
+
})
|
234
|
+
) {
|
235
|
+
singleRule = flagDict[arg];
|
236
|
+
if (singleRule == null) {
|
237
|
+
throw new Error(`unrecognized option ${arg}`);
|
238
|
+
}
|
239
|
+
if (singleRule.hasArgument) {
|
240
|
+
needsArgOpt = {
|
241
|
+
rule: singleRule,
|
242
|
+
flag: arg,
|
243
|
+
};
|
244
|
+
} else {
|
245
|
+
rules.push(singleRule);
|
246
|
+
}
|
247
|
+
} else {
|
248
|
+
// This is a positional argument.
|
249
|
+
positional = args.slice(argIndex);
|
250
|
+
break;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
if (needsArgOpt != null) {
|
254
|
+
throw new Error(`value required for ${needsArgOpt.flag}, but it was the last argument provided`);
|
255
|
+
}
|
256
|
+
return { rules, positional };
|
257
|
+
};
|
230
258
|
}).call(this);
|