@makano/rew 1.2.55 → 1.2.57

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,258 +0,0 @@
1
- // Generated by CoffeeScript 2.7.0
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;
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
- };
258
- }).call(this);