argue-cli 1.2.0 → 2.0.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +5 -5
- package/README.md +133 -68
- package/dist/args.d.ts +17 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/argv.d.ts +14 -0
- package/dist/argv.d.ts.map +1 -0
- package/dist/core.d.ts +19 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/index.cjs +223 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +210 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +9 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +24 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +34 -47
- package/CHANGELOG.md +0 -10
- package/lib/index.es.js +0 -391
- package/lib/index.es.js.map +0 -1
- package/lib/index.js +0 -403
- package/lib/index.js.map +0 -1
package/lib/index.es.js
DELETED
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
2
|
-
|
|
3
|
-
const argvStartIndex = 2;
|
|
4
|
-
const shirtArgLength = 2;
|
|
5
|
-
|
|
6
|
-
const argv = process.argv.slice(argvStartIndex, process.argv.length);
|
|
7
|
-
|
|
8
|
-
function findName(name, names) {
|
|
9
|
-
|
|
10
|
-
let findedName = false,
|
|
11
|
-
array = false;
|
|
12
|
-
|
|
13
|
-
names.some(fullNameOrigin => {
|
|
14
|
-
|
|
15
|
-
let keys = null,
|
|
16
|
-
fullName = fullNameOrigin,
|
|
17
|
-
shirtName = null;
|
|
18
|
-
|
|
19
|
-
if (typeof fullName == 'string') {
|
|
20
|
-
|
|
21
|
-
if (fullName == name) {
|
|
22
|
-
findedName = fullName;
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const proto = Object.getPrototypeOf(fullName); // eslint-disable-line
|
|
30
|
-
|
|
31
|
-
if (proto == Object.prototype) {
|
|
32
|
-
|
|
33
|
-
keys = fullName;
|
|
34
|
-
fullName = Object.keys(keys)[0];
|
|
35
|
-
shirtName = keys[fullName];
|
|
36
|
-
|
|
37
|
-
if (fullName == name || shirtName == name) {
|
|
38
|
-
findedName = fullName;
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (proto == Array.prototype) {
|
|
46
|
-
var _fullName = fullName;
|
|
47
|
-
|
|
48
|
-
var _fullName2 = _slicedToArray(_fullName, 2);
|
|
49
|
-
|
|
50
|
-
fullName = _fullName2[0];
|
|
51
|
-
shirtName = _fullName2[1];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (fullName == name || shirtName == name) {
|
|
55
|
-
array = true;
|
|
56
|
-
findedName = fullName;
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return false;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return findedName ? { name: findedName, isArray: array } : false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function setArguments(...newArguments) {
|
|
70
|
-
argv.splice(0, argv.length);
|
|
71
|
-
argv.push(...newArguments);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Strict expectation one of given commands.
|
|
76
|
-
*
|
|
77
|
-
* command-line-app install
|
|
78
|
-
*
|
|
79
|
-
* expect(
|
|
80
|
-
* {"install": "i"}, - fullname and shirtname
|
|
81
|
-
* ["update", "u"], - also fullname and shirtname
|
|
82
|
-
* "info" - only one variant of name
|
|
83
|
-
* )
|
|
84
|
-
*
|
|
85
|
-
* @param {...Object} names array of expected tokens
|
|
86
|
-
* @return {String} fullname
|
|
87
|
-
*/
|
|
88
|
-
function expect(...names) {
|
|
89
|
-
|
|
90
|
-
if (!argv.length) {
|
|
91
|
-
throw new Error('Unexpected end of arguments.');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const sourceKey = argv.shift(),
|
|
95
|
-
argument = findName(sourceKey, names);
|
|
96
|
-
|
|
97
|
-
if (!argument) {
|
|
98
|
-
throw new Error(`Unexpected argument "${sourceKey}".`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return argument.name;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Strict reading of argument.
|
|
106
|
-
*
|
|
107
|
-
* command-line-app some-value
|
|
108
|
-
*
|
|
109
|
-
* @return {String} argument
|
|
110
|
-
*/
|
|
111
|
-
function read() {
|
|
112
|
-
|
|
113
|
-
if (!argv.length) {
|
|
114
|
-
throw new Error('Unexpected end of arguments.');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return argv.shift();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Strict expectation of end.
|
|
122
|
-
* @returns {void}
|
|
123
|
-
*/
|
|
124
|
-
function end() {
|
|
125
|
-
|
|
126
|
-
if (argv.length) {
|
|
127
|
-
throw new Error(`Unexpected argument "${argv[0]}".`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Strict reading of flags and options.
|
|
133
|
-
*
|
|
134
|
-
* command-line-app --output test -p es2015,react --verbose
|
|
135
|
-
*
|
|
136
|
-
* strictOptions([
|
|
137
|
-
* ["another"] - for flags array is same as object notation
|
|
138
|
-
* "verbose" - only one variant of name
|
|
139
|
-
* ], [
|
|
140
|
-
* {"output": "o"}, - fullname and shirtname
|
|
141
|
-
* ["plugins", "p"] - fullname and shirtname for array
|
|
142
|
-
* ])
|
|
143
|
-
*
|
|
144
|
-
* @param {...Object} flagsNames array of tokens
|
|
145
|
-
* @param {...Object} optionsNames array of tokens
|
|
146
|
-
* @return {Object} fullname-value pairs
|
|
147
|
-
*/
|
|
148
|
-
function strictOptions(flagsNames, optionsNames) {
|
|
149
|
-
|
|
150
|
-
if (!argv.length) {
|
|
151
|
-
return {};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const options = {};
|
|
155
|
-
|
|
156
|
-
let argument = argv[0];
|
|
157
|
-
|
|
158
|
-
while (argv.length && (argument.indexOf('--') == 0 || argument.indexOf('-') == 0 && argument.length == shirtArgLength)) {
|
|
159
|
-
|
|
160
|
-
const sourceKey = argv.shift().replace(/^(--|-)/, ''),
|
|
161
|
-
flagKey = findName(sourceKey, flagsNames),
|
|
162
|
-
optionKey = findName(sourceKey, optionsNames);
|
|
163
|
-
|
|
164
|
-
if (!flagKey && !optionKey) {
|
|
165
|
-
throw new Error(`Unexpected key "${sourceKey}".`);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (!flagKey && optionKey && !argv.length) {
|
|
169
|
-
throw new Error(`Unexpected end of arguments.`);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let value = argv[0];
|
|
173
|
-
|
|
174
|
-
if (optionKey && value.indexOf('--') != 0 && value.indexOf('-') != 0 && value.length != shirtArgLength) {
|
|
175
|
-
|
|
176
|
-
argv.shift();
|
|
177
|
-
|
|
178
|
-
if (optionKey.isArray) {
|
|
179
|
-
value = value.split(',').map(element => element.replace(/^['"]|["']$/g, ''));
|
|
180
|
-
} else {
|
|
181
|
-
value = value.replace(/^['"]|["']$/g, '');
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
options[optionKey.name] = value;
|
|
185
|
-
} else if (flagKey) {
|
|
186
|
-
|
|
187
|
-
options[flagKey.name] = true;
|
|
188
|
-
} else {
|
|
189
|
-
throw new Error(`Unexpected key "${value}".`);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
argument = argv[0];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return options;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Strict reading of options with equal sign.
|
|
200
|
-
* If option is provided without value it will interpreted as `true`.
|
|
201
|
-
*
|
|
202
|
-
* command-line-app --output=test -p=es2015,react --verbose
|
|
203
|
-
*
|
|
204
|
-
* strictOptionsEqual(
|
|
205
|
-
* {"output": "o"}, - fullname and shirtname
|
|
206
|
-
* ["plugins", "p"], - fullname and shirtname for array
|
|
207
|
-
* "verbose" - only one variant of name
|
|
208
|
-
* )
|
|
209
|
-
*
|
|
210
|
-
* @param {...Object} names array of tokens
|
|
211
|
-
* @return {Object} fullname-value pairs
|
|
212
|
-
*/
|
|
213
|
-
function strictOptionsEqual(...names) {
|
|
214
|
-
|
|
215
|
-
if (!argv.length) {
|
|
216
|
-
return {};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const options = {};
|
|
220
|
-
|
|
221
|
-
let argument = argv[0];
|
|
222
|
-
|
|
223
|
-
while (argv.length && (argument.indexOf('--') == 0 || argument.indexOf('-') == 0)) {
|
|
224
|
-
var _argv$shift$replace$s = argv.shift().replace(/^(--|-)/, '').split('='),
|
|
225
|
-
_argv$shift$replace$s2 = _slicedToArray(_argv$shift$replace$s, 2);
|
|
226
|
-
|
|
227
|
-
let sourceKey = _argv$shift$replace$s2[0],
|
|
228
|
-
value = _argv$shift$replace$s2[1];
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const key = findName(sourceKey, names);
|
|
232
|
-
|
|
233
|
-
if (!key) {
|
|
234
|
-
throw new Error(`Unexpected key "${sourceKey}".`);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (typeof value == 'undefined') {
|
|
238
|
-
value = true;
|
|
239
|
-
} else if (key.isArray) {
|
|
240
|
-
value = value.split(',').map(element => element.replace(/^['"]|["']$/g, ''));
|
|
241
|
-
} else {
|
|
242
|
-
value = value.replace(/^['"]|["']$/g, '');
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
options[key.name] = value;
|
|
246
|
-
|
|
247
|
-
argument = argv[0];
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return options;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Unlimited reading of flags and options.
|
|
255
|
-
*
|
|
256
|
-
* command-line-app --output test install -p es2015,react babel --verbose
|
|
257
|
-
*
|
|
258
|
-
* options([
|
|
259
|
-
* ["another"] - for flags array is same as object notation
|
|
260
|
-
* "verbose" - only one variant of name
|
|
261
|
-
* ], [
|
|
262
|
-
* {"output": "o"}, - fullname and shirtname
|
|
263
|
-
* ["plugins", "p"] - fullname and shirtname for array
|
|
264
|
-
* ])
|
|
265
|
-
*
|
|
266
|
-
* @param {...Object} flagsNames array of tokens
|
|
267
|
-
* @param {...Object} optionsNames array of tokens
|
|
268
|
-
* @return {Object} fullname-value pairs
|
|
269
|
-
*/
|
|
270
|
-
function options(flagsNames, optionsNames) {
|
|
271
|
-
|
|
272
|
-
if (!argv.length) {
|
|
273
|
-
return {};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const options = {},
|
|
277
|
-
argvc = argv.slice(),
|
|
278
|
-
argc = argvc.length,
|
|
279
|
-
remove = [];
|
|
280
|
-
|
|
281
|
-
for (let i = 0, argument = argvc[i]; i < argc; argument = argvc[++i]) {
|
|
282
|
-
|
|
283
|
-
if (argument.indexOf('--') != 0 && (argument.indexOf('-') != 0 || argument.length != shirtArgLength)) {
|
|
284
|
-
continue;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const sourceKey = argument.replace(/^(--|-)/, ''),
|
|
288
|
-
flagKey = findName(sourceKey, flagsNames),
|
|
289
|
-
optionKey = findName(sourceKey, optionsNames);
|
|
290
|
-
|
|
291
|
-
if (!flagKey && !optionKey) {
|
|
292
|
-
throw new Error(`Unexpected key "${sourceKey}".`);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (!flagKey && optionKey && i == argc - 1) {
|
|
296
|
-
throw new Error(`Unexpected end of arguments.`);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
let value = argvc[i + 1];
|
|
300
|
-
|
|
301
|
-
if (optionKey && value.indexOf('--') != 0 && value.indexOf('-') != 0 && value.length != shirtArgLength) {
|
|
302
|
-
|
|
303
|
-
remove.unshift(i++);
|
|
304
|
-
|
|
305
|
-
if (optionKey.isArray) {
|
|
306
|
-
value = value.split(',').map(element => element.replace(/^['"]|["']$/g, ''));
|
|
307
|
-
} else {
|
|
308
|
-
value = value.replace(/^['"]|["']$/g, '');
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
options[optionKey.name] = value;
|
|
312
|
-
} else if (flagKey) {
|
|
313
|
-
|
|
314
|
-
options[flagKey.name] = true;
|
|
315
|
-
} else {
|
|
316
|
-
throw new Error(`Unexpected key "${value}".`);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
remove.unshift(i);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
remove.forEach(index => argv.splice(index, 1));
|
|
323
|
-
|
|
324
|
-
return options;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Unlimited reading of with equal sign.
|
|
329
|
-
* If option is provided without value it will interpreted as `true`.
|
|
330
|
-
*
|
|
331
|
-
* command-line-app --output=test install -p=es2015,react babel --verbose
|
|
332
|
-
*
|
|
333
|
-
* optionsEqual(
|
|
334
|
-
* {"output": "o"}, - fullname and shirtname
|
|
335
|
-
* ["plugins", "p"], - fullname and shirtname for array
|
|
336
|
-
* "verbose" - only one variant of name
|
|
337
|
-
* )
|
|
338
|
-
*
|
|
339
|
-
* @param {...Object} names array of tokens
|
|
340
|
-
* @return {Object} fullname-value pairs
|
|
341
|
-
*/
|
|
342
|
-
function optionsEqual(...names) {
|
|
343
|
-
|
|
344
|
-
if (!argv.length) {
|
|
345
|
-
return {};
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
const options = {},
|
|
349
|
-
argvc = argv.slice(),
|
|
350
|
-
argc = argvc.length,
|
|
351
|
-
remove = [];
|
|
352
|
-
|
|
353
|
-
for (let i = 0, argument = argvc[i]; i < argc; argument = argvc[++i]) {
|
|
354
|
-
|
|
355
|
-
if (argument.indexOf('-') != 0) {
|
|
356
|
-
continue;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
var _argument$replace$spl = argument.replace(/^(--|-)/, '').split('='),
|
|
360
|
-
_argument$replace$spl2 = _slicedToArray(_argument$replace$spl, 2);
|
|
361
|
-
|
|
362
|
-
let sourceKey = _argument$replace$spl2[0],
|
|
363
|
-
value = _argument$replace$spl2[1];
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const key = findName(sourceKey, names);
|
|
367
|
-
|
|
368
|
-
remove.unshift(i);
|
|
369
|
-
|
|
370
|
-
if (!key) {
|
|
371
|
-
throw new Error(`Unexpected key "${sourceKey}".`);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
if (typeof value == 'undefined') {
|
|
375
|
-
value = true;
|
|
376
|
-
} else if (key.isArray) {
|
|
377
|
-
value = value.split(',').map(element => element.replace(/^['"]|["']$/g, ''));
|
|
378
|
-
} else {
|
|
379
|
-
value = value.replace(/^['"]|["']$/g, '');
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
options[key.name] = value;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
remove.forEach(index => argv.splice(index, 1));
|
|
386
|
-
|
|
387
|
-
return options;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export { argv, setArguments, expect, read, end, strictOptions, strictOptionsEqual, options, optionsEqual };
|
|
391
|
-
//# sourceMappingURL=index.es.js.map
|
package/lib/index.es.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/index.js"],"sourcesContent":["\nconst argvStartIndex = 2,\n\tshirtArgLength = 2;\n\nexport const argv = process.argv.slice(argvStartIndex, process.argv.length);\n\nfunction findName(name, names) {\n\n\tlet findedName = false,\n\t\tarray = false;\n\n\tnames.some((fullNameOrigin) => {\n\n\t\tlet keys = null,\n\t\t\tfullName = fullNameOrigin,\n\t\t\tshirtName = null;\n\n\t\tif (typeof fullName == 'string') {\n\n\t\t\tif (fullName == name) {\n\t\t\t\tfindedName = fullName;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t}\n\n\t\tconst proto = Object.getPrototypeOf(fullName); // eslint-disable-line\n\n\t\tif (proto == Object.prototype) {\n\n\t\t\tkeys = fullName;\n\t\t\tfullName = Object.keys(keys)[0];\n\t\t\tshirtName = keys[fullName];\n\n\t\t\tif (fullName == name || shirtName == name) {\n\t\t\t\tfindedName = fullName;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t}\n\n\t\tif (proto == Array.prototype) {\n\n\t\t\t[fullName, shirtName] = fullName;\n\n\t\t\tif (fullName == name || shirtName == name) {\n\t\t\t\tarray = true;\n\t\t\t\tfindedName = fullName;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t}\n\n\t\treturn false;\n\t});\n\n\treturn findedName\n\t\t? { name: findedName, isArray: array }\n\t\t: false\n\t;\n}\n\nexport function setArguments(...newArguments) {\n\targv.splice(0, argv.length);\n\targv.push(...newArguments);\n}\n\n/**\n * Strict expectation one of given commands.\n *\n * command-line-app install\n *\n * expect(\n * {\"install\": \"i\"}, - fullname and shirtname\n * [\"update\", \"u\"], - also fullname and shirtname\n * \"info\" - only one variant of name\n * )\n *\n * @param {...Object} names array of expected tokens\n * @return {String} fullname\n */\nexport function expect(...names) {\n\n\tif (!argv.length) {\n\t\tthrow new Error('Unexpected end of arguments.');\n\t}\n\n\tconst sourceKey = argv.shift(),\n\t\targument = findName(sourceKey, names);\n\n\tif (!argument) {\n\t\tthrow new Error(`Unexpected argument \"${sourceKey}\".`);\n\t}\n\n\treturn argument.name;\n}\n\n/**\n * Strict reading of argument.\n *\n * command-line-app some-value\n *\n * @return {String} argument\n */\nexport function read() {\n\n\tif (!argv.length) {\n\t\tthrow new Error('Unexpected end of arguments.');\n\t}\n\n\treturn argv.shift();\n}\n\n/**\n * Strict expectation of end.\n * @returns {void}\n */\nexport function end() {\n\n\tif (argv.length) {\n\t\tthrow new Error(`Unexpected argument \"${argv[0]}\".`);\n\t}\n}\n\n/**\n * Strict reading of flags and options.\n *\n * command-line-app --output test -p es2015,react --verbose\n *\n * strictOptions([\n * [\"another\"] - for flags array is same as object notation\n * \"verbose\" - only one variant of name\n * ], [\n * {\"output\": \"o\"}, - fullname and shirtname\n * [\"plugins\", \"p\"] - fullname and shirtname for array\n * ])\n *\n * @param {...Object} flagsNames array of tokens\n * @param {...Object} optionsNames array of tokens\n * @return {Object} fullname-value pairs\n */\nexport function strictOptions(flagsNames, optionsNames) {\n\n\tif (!argv.length) {\n\t\treturn {};\n\t}\n\n\tconst options = {};\n\n\tlet argument = argv[0];\n\n\twhile (\n\t\targv.length\n\t\t&& (\n\t\t\targument.indexOf('--') == 0\n\t\t\t|| argument.indexOf('-') == 0 && argument.length == shirtArgLength\n\t\t)\n\t) {\n\n\t\tconst sourceKey = argv.shift().replace(/^(--|-)/, ''),\n\t\t\tflagKey = findName(sourceKey, flagsNames),\n\t\t\toptionKey = findName(sourceKey, optionsNames);\n\n\t\tif (!flagKey && !optionKey) {\n\t\t\tthrow new Error(`Unexpected key \"${sourceKey}\".`);\n\t\t}\n\n\t\tif (!flagKey && optionKey && !argv.length) {\n\t\t\tthrow new Error(`Unexpected end of arguments.`);\n\t\t}\n\n\t\tlet value = argv[0];\n\n\t\tif (optionKey && value.indexOf('--') != 0\n\t\t\t&& (value.indexOf('-') != 0 && value.length != shirtArgLength)\n\t\t) {\n\n\t\t\targv.shift();\n\n\t\t\tif (optionKey.isArray) {\n\t\t\t\tvalue = value.split(',').map(element => element.replace(/^['\"]|[\"']$/g, ''));\n\t\t\t} else {\n\t\t\t\tvalue = value.replace(/^['\"]|[\"']$/g, '');\n\t\t\t}\n\n\t\t\toptions[optionKey.name] = value;\n\n\t\t} else\n\t\tif (flagKey) {\n\n\t\t\toptions[flagKey.name] = true;\n\n\t\t} else {\n\t\t\tthrow new Error(`Unexpected key \"${value}\".`);\n\t\t}\n\n\t\targument = argv[0];\n\t}\n\n\treturn options;\n}\n\n/**\n * Strict reading of options with equal sign.\n * If option is provided without value it will interpreted as `true`.\n *\n * command-line-app --output=test -p=es2015,react --verbose\n *\n * strictOptionsEqual(\n * {\"output\": \"o\"}, - fullname and shirtname\n * [\"plugins\", \"p\"], - fullname and shirtname for array\n * \"verbose\" - only one variant of name\n * )\n *\n * @param {...Object} names array of tokens\n * @return {Object} fullname-value pairs\n */\nexport function strictOptionsEqual(...names) {\n\n\tif (!argv.length) {\n\t\treturn {};\n\t}\n\n\tconst options = {};\n\n\tlet argument = argv[0];\n\n\twhile (\n\t\targv.length\n\t\t&& (\n\t\t\targument.indexOf('--') == 0\n\t\t\t|| argument.indexOf('-') == 0\n\t\t)\n\t) {\n\n\t\tlet [sourceKey, value] = argv.shift().replace(/^(--|-)/, '').split('=');\n\n\t\tconst key = findName(sourceKey, names);\n\n\t\tif (!key) {\n\t\t\tthrow new Error(`Unexpected key \"${sourceKey}\".`);\n\t\t}\n\n\t\tif (typeof value == 'undefined') {\n\t\t\tvalue = true;\n\t\t} else\n\t\tif (key.isArray) {\n\t\t\tvalue = value.split(',').map(element => element.replace(/^['\"]|[\"']$/g, ''));\n\t\t} else {\n\t\t\tvalue = value.replace(/^['\"]|[\"']$/g, '');\n\t\t}\n\n\t\toptions[key.name] = value;\n\n\t\targument = argv[0];\n\t}\n\n\treturn options;\n}\n\n/**\n * Unlimited reading of flags and options.\n *\n * command-line-app --output test install -p es2015,react babel --verbose\n *\n * options([\n * [\"another\"] - for flags array is same as object notation\n * \"verbose\" - only one variant of name\n * ], [\n * {\"output\": \"o\"}, - fullname and shirtname\n * [\"plugins\", \"p\"] - fullname and shirtname for array\n * ])\n *\n * @param {...Object} flagsNames array of tokens\n * @param {...Object} optionsNames array of tokens\n * @return {Object} fullname-value pairs\n */\nexport function options(flagsNames, optionsNames) {\n\n\tif (!argv.length) {\n\t\treturn {};\n\t}\n\n\tconst options = {},\n\t\targvc = argv.slice(),\n\t\targc = argvc.length,\n\t\tremove = [];\n\n\tfor (let i = 0, argument = argvc[i]; i < argc; argument = argvc[++i]) {\n\n\t\tif (argument.indexOf('--') != 0\n\t\t\t&& (argument.indexOf('-') != 0 || argument.length != shirtArgLength)\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst sourceKey = argument.replace(/^(--|-)/, ''),\n\t\t\tflagKey = findName(sourceKey, flagsNames),\n\t\t\toptionKey = findName(sourceKey, optionsNames);\n\n\t\tif (!flagKey && !optionKey) {\n\t\t\tthrow new Error(`Unexpected key \"${sourceKey}\".`);\n\t\t}\n\n\t\tif (!flagKey && optionKey && i == argc - 1) {\n\t\t\tthrow new Error(`Unexpected end of arguments.`);\n\t\t}\n\n\t\tlet value = argvc[i + 1];\n\n\t\tif (optionKey && value.indexOf('--') != 0\n\t\t\t&& (value.indexOf('-') != 0 && value.length != shirtArgLength)\n\t\t) {\n\n\t\t\tremove.unshift(i++);\n\n\t\t\tif (optionKey.isArray) {\n\t\t\t\tvalue = value.split(',').map(element => element.replace(/^['\"]|[\"']$/g, ''));\n\t\t\t} else {\n\t\t\t\tvalue = value.replace(/^['\"]|[\"']$/g, '');\n\t\t\t}\n\n\t\t\toptions[optionKey.name] = value;\n\n\t\t} else\n\t\tif (flagKey) {\n\n\t\t\toptions[flagKey.name] = true;\n\n\t\t} else {\n\t\t\tthrow new Error(`Unexpected key \"${value}\".`);\n\t\t}\n\n\t\tremove.unshift(i);\n\t}\n\n\tremove.forEach(index => argv.splice(index, 1));\n\n\treturn options;\n}\n\n/**\n * Unlimited reading of with equal sign.\n * If option is provided without value it will interpreted as `true`.\n *\n * command-line-app --output=test install -p=es2015,react babel --verbose\n *\n * optionsEqual(\n * {\"output\": \"o\"}, - fullname and shirtname\n * [\"plugins\", \"p\"], - fullname and shirtname for array\n * \"verbose\" - only one variant of name\n * )\n *\n * @param {...Object} names array of tokens\n * @return {Object} fullname-value pairs\n */\nexport function optionsEqual(...names) {\n\n\tif (!argv.length) {\n\t\treturn {};\n\t}\n\n\tconst options = {},\n\t\targvc = argv.slice(),\n\t\targc = argvc.length,\n\t\tremove = [];\n\n\tfor (let i = 0, argument = argvc[i]; i < argc; argument = argvc[++i]) {\n\n\t\tif (argument.indexOf('-') != 0) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet [sourceKey, value] = argument.replace(/^(--|-)/, '').split('=');\n\n\t\tconst key = findName(sourceKey, names);\n\n\t\tremove.unshift(i);\n\n\t\tif (!key) {\n\t\t\tthrow new Error(`Unexpected key \"${sourceKey}\".`);\n\t\t}\n\n\t\tif (typeof value == 'undefined') {\n\t\t\tvalue = true;\n\t\t} else\n\t\tif (key.isArray) {\n\t\t\tvalue = value.split(',').map(element => element.replace(/^['\"]|[\"']$/g, ''));\n\t\t} else {\n\t\t\tvalue = value.replace(/^['\"]|[\"']$/g, '');\n\t\t}\n\n\t\toptions[key.name] = value;\n\t}\n\n\tremove.forEach(index => argv.splice(index, 1));\n\n\treturn options;\n}\n"],"names":["argvStartIndex","shirtArgLength","argv","process","slice","length","findName","name","names","findedName","array","some","fullNameOrigin","keys","fullName","shirtName","proto","Object","getPrototypeOf","prototype","Array","isArray","setArguments","newArguments","splice","push","expect","Error","sourceKey","shift","argument","read","end","strictOptions","flagsNames","optionsNames","options","indexOf","replace","flagKey","optionKey","value","split","map","element","strictOptionsEqual","key","argvc","argc","remove","i","unshift","forEach","index","optionsEqual"],"mappings":";;AACA,MAAMA,iBAAiB,CAAvB;MACCC,iBAAiB,CADlB;;AAGA,AAAO,MAAMC,OAAOC,QAAQD,IAAR,CAAaE,KAAb,CAAmBJ,cAAnB,EAAmCG,QAAQD,IAAR,CAAaG,MAAhD,CAAb;;AAEP,SAASC,QAAT,CAAkBC,IAAlB,EAAwBC,KAAxB,EAA+B;;KAE1BC,aAAa,KAAjB;KACCC,QAAa,KADd;;OAGMC,IAAN,CAAYC,cAAD,IAAoB;;MAE1BC,OAAO,IAAX;MACCC,WAAWF,cADZ;MAECG,YAAY,IAFb;;MAII,OAAOD,QAAP,IAAmB,QAAvB,EAAiC;;OAE5BA,YAAYP,IAAhB,EAAsB;iBACRO,QAAb;WACO,IAAP;;;UAGM,KAAP;;;QAGKE,QAAQC,OAAOC,cAAP,CAAsBJ,QAAtB,CAAd,CAhB8B;;MAkB1BE,SAASC,OAAOE,SAApB,EAA+B;;UAEvBL,QAAP;cACWG,OAAOJ,IAAP,CAAYA,IAAZ,EAAkB,CAAlB,CAAX;eACYA,KAAKC,QAAL,CAAZ;;OAEIA,YAAYP,IAAZ,IAAoBQ,aAAaR,IAArC,EAA2C;iBAC7BO,QAAb;WACO,IAAP;;;UAGM,KAAP;;;MAGGE,SAASI,MAAMD,SAAnB,EAA8B;mBAELL,QAFK;;;;WAAA;YAAA;;;OAIzBA,YAAYP,IAAZ,IAAoBQ,aAAaR,IAArC,EAA2C;YAClC,IAAR;iBACaO,QAAb;WACO,IAAP;;;UAGM,KAAP;;;SAGM,KAAP;EA7CD;;QAgDOL,aACJ,EAAEF,MAAME,UAAR,EAAoBY,SAASX,KAA7B,EADI,GAEJ,KAFH;;;AAMD,AAAO,SAASY,YAAT,CAAsB,GAAGC,YAAzB,EAAuC;MACxCC,MAAL,CAAY,CAAZ,EAAetB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