@master4n/master-cli 1.0.0

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/bin/index.js ADDED
@@ -0,0 +1,1858 @@
1
+ #!/usr/bin/env node
2
+ import yargs from 'yargs';
3
+ import { format, inspect } from 'util';
4
+ import { normalize, resolve, dirname, basename, extname, relative } from 'path';
5
+ import { readFileSync, statSync, readdirSync, writeFile } from 'fs';
6
+ import { notStrictEqual, strictEqual } from 'assert';
7
+ import { fileURLToPath } from 'url';
8
+ import chalk from 'chalk';
9
+
10
+ class YError extends Error {
11
+ constructor(msg) {
12
+ super(msg || 'yargs error');
13
+ this.name = 'YError';
14
+ if (Error.captureStackTrace) {
15
+ Error.captureStackTrace(this, YError);
16
+ }
17
+ }
18
+ }
19
+
20
+ function getProcessArgvBinIndex() {
21
+ if (isBundledElectronApp())
22
+ return 0;
23
+ return 1;
24
+ }
25
+ function isBundledElectronApp() {
26
+ return isElectronApp() && !process.defaultApp;
27
+ }
28
+ function isElectronApp() {
29
+ return !!process.versions.electron;
30
+ }
31
+ function hideBin(argv) {
32
+ return argv.slice(getProcessArgvBinIndex() + 1);
33
+ }
34
+ function getProcessArgvBin() {
35
+ return process.argv[getProcessArgvBinIndex()];
36
+ }
37
+
38
+ /**
39
+ * @license
40
+ * Copyright (c) 2016, Contributors
41
+ * SPDX-License-Identifier: ISC
42
+ */
43
+ function camelCase(str) {
44
+ // Handle the case where an argument is provided as camel case, e.g., fooBar.
45
+ // by ensuring that the string isn't already mixed case:
46
+ const isCamelCase = str !== str.toLowerCase() && str !== str.toUpperCase();
47
+ if (!isCamelCase) {
48
+ str = str.toLowerCase();
49
+ }
50
+ if (str.indexOf('-') === -1 && str.indexOf('_') === -1) {
51
+ return str;
52
+ }
53
+ else {
54
+ let camelcase = '';
55
+ let nextChrUpper = false;
56
+ const leadingHyphens = str.match(/^-+/);
57
+ for (let i = leadingHyphens ? leadingHyphens[0].length : 0; i < str.length; i++) {
58
+ let chr = str.charAt(i);
59
+ if (nextChrUpper) {
60
+ nextChrUpper = false;
61
+ chr = chr.toUpperCase();
62
+ }
63
+ if (i !== 0 && (chr === '-' || chr === '_')) {
64
+ nextChrUpper = true;
65
+ }
66
+ else if (chr !== '-' && chr !== '_') {
67
+ camelcase += chr;
68
+ }
69
+ }
70
+ return camelcase;
71
+ }
72
+ }
73
+ function decamelize(str, joinString) {
74
+ const lowercase = str.toLowerCase();
75
+ joinString = joinString || '-';
76
+ let notCamelcase = '';
77
+ for (let i = 0; i < str.length; i++) {
78
+ const chrLower = lowercase.charAt(i);
79
+ const chrString = str.charAt(i);
80
+ if (chrLower !== chrString && i > 0) {
81
+ notCamelcase += `${joinString}${lowercase.charAt(i)}`;
82
+ }
83
+ else {
84
+ notCamelcase += chrString;
85
+ }
86
+ }
87
+ return notCamelcase;
88
+ }
89
+ function looksLikeNumber(x) {
90
+ if (x === null || x === undefined)
91
+ return false;
92
+ // if loaded from config, may already be a number.
93
+ if (typeof x === 'number')
94
+ return true;
95
+ // hexadecimal.
96
+ if (/^0x[0-9a-f]+$/i.test(x))
97
+ return true;
98
+ // don't treat 0123 as a number; as it drops the leading '0'.
99
+ if (/^0[^.]/.test(x))
100
+ return false;
101
+ return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
102
+ }
103
+
104
+ /**
105
+ * @license
106
+ * Copyright (c) 2016, Contributors
107
+ * SPDX-License-Identifier: ISC
108
+ */
109
+ // take an un-split argv string and tokenize it.
110
+ function tokenizeArgString(argString) {
111
+ if (Array.isArray(argString)) {
112
+ return argString.map(e => typeof e !== 'string' ? e + '' : e);
113
+ }
114
+ argString = argString.trim();
115
+ let i = 0;
116
+ let prevC = null;
117
+ let c = null;
118
+ let opening = null;
119
+ const args = [];
120
+ for (let ii = 0; ii < argString.length; ii++) {
121
+ prevC = c;
122
+ c = argString.charAt(ii);
123
+ // split on spaces unless we're in quotes.
124
+ if (c === ' ' && !opening) {
125
+ if (!(prevC === ' ')) {
126
+ i++;
127
+ }
128
+ continue;
129
+ }
130
+ // don't split the string if we're in matching
131
+ // opening or closing single and double quotes.
132
+ if (c === opening) {
133
+ opening = null;
134
+ }
135
+ else if ((c === "'" || c === '"') && !opening) {
136
+ opening = c;
137
+ }
138
+ if (!args[i])
139
+ args[i] = '';
140
+ args[i] += c;
141
+ }
142
+ return args;
143
+ }
144
+
145
+ /**
146
+ * @license
147
+ * Copyright (c) 2016, Contributors
148
+ * SPDX-License-Identifier: ISC
149
+ */
150
+ var DefaultValuesForTypeKey;
151
+ (function (DefaultValuesForTypeKey) {
152
+ DefaultValuesForTypeKey["BOOLEAN"] = "boolean";
153
+ DefaultValuesForTypeKey["STRING"] = "string";
154
+ DefaultValuesForTypeKey["NUMBER"] = "number";
155
+ DefaultValuesForTypeKey["ARRAY"] = "array";
156
+ })(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {}));
157
+
158
+ /**
159
+ * @license
160
+ * Copyright (c) 2016, Contributors
161
+ * SPDX-License-Identifier: ISC
162
+ */
163
+ let mixin$1;
164
+ class YargsParser {
165
+ constructor(_mixin) {
166
+ mixin$1 = _mixin;
167
+ }
168
+ parse(argsInput, options) {
169
+ const opts = Object.assign({
170
+ alias: undefined,
171
+ array: undefined,
172
+ boolean: undefined,
173
+ config: undefined,
174
+ configObjects: undefined,
175
+ configuration: undefined,
176
+ coerce: undefined,
177
+ count: undefined,
178
+ default: undefined,
179
+ envPrefix: undefined,
180
+ narg: undefined,
181
+ normalize: undefined,
182
+ string: undefined,
183
+ number: undefined,
184
+ __: undefined,
185
+ key: undefined
186
+ }, options);
187
+ // allow a string argument to be passed in rather
188
+ // than an argv array.
189
+ const args = tokenizeArgString(argsInput);
190
+ // tokenizeArgString adds extra quotes to args if argsInput is a string
191
+ // only strip those extra quotes in processValue if argsInput is a string
192
+ const inputIsString = typeof argsInput === 'string';
193
+ // aliases might have transitive relationships, normalize this.
194
+ const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
195
+ const configuration = Object.assign({
196
+ 'boolean-negation': true,
197
+ 'camel-case-expansion': true,
198
+ 'combine-arrays': false,
199
+ 'dot-notation': true,
200
+ 'duplicate-arguments-array': true,
201
+ 'flatten-duplicate-arrays': true,
202
+ 'greedy-arrays': true,
203
+ 'halt-at-non-option': false,
204
+ 'nargs-eats-options': false,
205
+ 'negation-prefix': 'no-',
206
+ 'parse-numbers': true,
207
+ 'parse-positional-numbers': true,
208
+ 'populate--': false,
209
+ 'set-placeholder-key': false,
210
+ 'short-option-groups': true,
211
+ 'strip-aliased': false,
212
+ 'strip-dashed': false,
213
+ 'unknown-options-as-args': false
214
+ }, opts.configuration);
215
+ const defaults = Object.assign(Object.create(null), opts.default);
216
+ const configObjects = opts.configObjects || [];
217
+ const envPrefix = opts.envPrefix;
218
+ const notFlagsOption = configuration['populate--'];
219
+ const notFlagsArgv = notFlagsOption ? '--' : '_';
220
+ const newAliases = Object.create(null);
221
+ const defaulted = Object.create(null);
222
+ // allow a i18n handler to be passed in, default to a fake one (util.format).
223
+ const __ = opts.__ || mixin$1.format;
224
+ const flags = {
225
+ aliases: Object.create(null),
226
+ arrays: Object.create(null),
227
+ bools: Object.create(null),
228
+ strings: Object.create(null),
229
+ numbers: Object.create(null),
230
+ counts: Object.create(null),
231
+ normalize: Object.create(null),
232
+ configs: Object.create(null),
233
+ nargs: Object.create(null),
234
+ coercions: Object.create(null),
235
+ keys: []
236
+ };
237
+ const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
238
+ const negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)');
239
+ [].concat(opts.array || []).filter(Boolean).forEach(function (opt) {
240
+ const key = typeof opt === 'object' ? opt.key : opt;
241
+ // assign to flags[bools|strings|numbers]
242
+ const assignment = Object.keys(opt).map(function (key) {
243
+ const arrayFlagKeys = {
244
+ boolean: 'bools',
245
+ string: 'strings',
246
+ number: 'numbers'
247
+ };
248
+ return arrayFlagKeys[key];
249
+ }).filter(Boolean).pop();
250
+ // assign key to be coerced
251
+ if (assignment) {
252
+ flags[assignment][key] = true;
253
+ }
254
+ flags.arrays[key] = true;
255
+ flags.keys.push(key);
256
+ });
257
+ [].concat(opts.boolean || []).filter(Boolean).forEach(function (key) {
258
+ flags.bools[key] = true;
259
+ flags.keys.push(key);
260
+ });
261
+ [].concat(opts.string || []).filter(Boolean).forEach(function (key) {
262
+ flags.strings[key] = true;
263
+ flags.keys.push(key);
264
+ });
265
+ [].concat(opts.number || []).filter(Boolean).forEach(function (key) {
266
+ flags.numbers[key] = true;
267
+ flags.keys.push(key);
268
+ });
269
+ [].concat(opts.count || []).filter(Boolean).forEach(function (key) {
270
+ flags.counts[key] = true;
271
+ flags.keys.push(key);
272
+ });
273
+ [].concat(opts.normalize || []).filter(Boolean).forEach(function (key) {
274
+ flags.normalize[key] = true;
275
+ flags.keys.push(key);
276
+ });
277
+ if (typeof opts.narg === 'object') {
278
+ Object.entries(opts.narg).forEach(([key, value]) => {
279
+ if (typeof value === 'number') {
280
+ flags.nargs[key] = value;
281
+ flags.keys.push(key);
282
+ }
283
+ });
284
+ }
285
+ if (typeof opts.coerce === 'object') {
286
+ Object.entries(opts.coerce).forEach(([key, value]) => {
287
+ if (typeof value === 'function') {
288
+ flags.coercions[key] = value;
289
+ flags.keys.push(key);
290
+ }
291
+ });
292
+ }
293
+ if (typeof opts.config !== 'undefined') {
294
+ if (Array.isArray(opts.config) || typeof opts.config === 'string') {
295
+ [].concat(opts.config).filter(Boolean).forEach(function (key) {
296
+ flags.configs[key] = true;
297
+ });
298
+ }
299
+ else if (typeof opts.config === 'object') {
300
+ Object.entries(opts.config).forEach(([key, value]) => {
301
+ if (typeof value === 'boolean' || typeof value === 'function') {
302
+ flags.configs[key] = value;
303
+ }
304
+ });
305
+ }
306
+ }
307
+ // create a lookup table that takes into account all
308
+ // combinations of aliases: {f: ['foo'], foo: ['f']}
309
+ extendAliases(opts.key, aliases, opts.default, flags.arrays);
310
+ // apply default values to all aliases.
311
+ Object.keys(defaults).forEach(function (key) {
312
+ (flags.aliases[key] || []).forEach(function (alias) {
313
+ defaults[alias] = defaults[key];
314
+ });
315
+ });
316
+ let error = null;
317
+ checkConfiguration();
318
+ let notFlags = [];
319
+ const argv = Object.assign(Object.create(null), { _: [] });
320
+ // TODO(bcoe): for the first pass at removing object prototype we didn't
321
+ // remove all prototypes from objects returned by this API, we might want
322
+ // to gradually move towards doing so.
323
+ const argvReturn = {};
324
+ for (let i = 0; i < args.length; i++) {
325
+ const arg = args[i];
326
+ const truncatedArg = arg.replace(/^-{3,}/, '---');
327
+ let broken;
328
+ let key;
329
+ let letters;
330
+ let m;
331
+ let next;
332
+ let value;
333
+ // any unknown option (except for end-of-options, "--")
334
+ if (arg !== '--' && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {
335
+ pushPositional(arg);
336
+ // ---, ---=, ----, etc,
337
+ }
338
+ else if (truncatedArg.match(/^---+(=|$)/)) {
339
+ // options without key name are invalid.
340
+ pushPositional(arg);
341
+ continue;
342
+ // -- separated by =
343
+ }
344
+ else if (arg.match(/^--.+=/) || (!configuration['short-option-groups'] && arg.match(/^-.+=/))) {
345
+ // Using [\s\S] instead of . because js doesn't support the
346
+ // 'dotall' regex modifier. See:
347
+ // http://stackoverflow.com/a/1068308/13216
348
+ m = arg.match(/^--?([^=]+)=([\s\S]*)$/);
349
+ // arrays format = '--f=a b c'
350
+ if (m !== null && Array.isArray(m) && m.length >= 3) {
351
+ if (checkAllAliases(m[1], flags.arrays)) {
352
+ i = eatArray(i, m[1], args, m[2]);
353
+ }
354
+ else if (checkAllAliases(m[1], flags.nargs) !== false) {
355
+ // nargs format = '--f=monkey washing cat'
356
+ i = eatNargs(i, m[1], args, m[2]);
357
+ }
358
+ else {
359
+ setArg(m[1], m[2], true);
360
+ }
361
+ }
362
+ }
363
+ else if (arg.match(negatedBoolean) && configuration['boolean-negation']) {
364
+ m = arg.match(negatedBoolean);
365
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
366
+ key = m[1];
367
+ setArg(key, checkAllAliases(key, flags.arrays) ? [false] : false);
368
+ }
369
+ // -- separated by space.
370
+ }
371
+ else if (arg.match(/^--.+/) || (!configuration['short-option-groups'] && arg.match(/^-[^-]+/))) {
372
+ m = arg.match(/^--?(.+)/);
373
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
374
+ key = m[1];
375
+ if (checkAllAliases(key, flags.arrays)) {
376
+ // array format = '--foo a b c'
377
+ i = eatArray(i, key, args);
378
+ }
379
+ else if (checkAllAliases(key, flags.nargs) !== false) {
380
+ // nargs format = '--foo a b c'
381
+ // should be truthy even if: flags.nargs[key] === 0
382
+ i = eatNargs(i, key, args);
383
+ }
384
+ else {
385
+ next = args[i + 1];
386
+ if (next !== undefined && (!next.match(/^-/) ||
387
+ next.match(negative)) &&
388
+ !checkAllAliases(key, flags.bools) &&
389
+ !checkAllAliases(key, flags.counts)) {
390
+ setArg(key, next);
391
+ i++;
392
+ }
393
+ else if (/^(true|false)$/.test(next)) {
394
+ setArg(key, next);
395
+ i++;
396
+ }
397
+ else {
398
+ setArg(key, defaultValue(key));
399
+ }
400
+ }
401
+ }
402
+ // dot-notation flag separated by '='.
403
+ }
404
+ else if (arg.match(/^-.\..+=/)) {
405
+ m = arg.match(/^-([^=]+)=([\s\S]*)$/);
406
+ if (m !== null && Array.isArray(m) && m.length >= 3) {
407
+ setArg(m[1], m[2]);
408
+ }
409
+ // dot-notation flag separated by space.
410
+ }
411
+ else if (arg.match(/^-.\..+/) && !arg.match(negative)) {
412
+ next = args[i + 1];
413
+ m = arg.match(/^-(.\..+)/);
414
+ if (m !== null && Array.isArray(m) && m.length >= 2) {
415
+ key = m[1];
416
+ if (next !== undefined && !next.match(/^-/) &&
417
+ !checkAllAliases(key, flags.bools) &&
418
+ !checkAllAliases(key, flags.counts)) {
419
+ setArg(key, next);
420
+ i++;
421
+ }
422
+ else {
423
+ setArg(key, defaultValue(key));
424
+ }
425
+ }
426
+ }
427
+ else if (arg.match(/^-[^-]+/) && !arg.match(negative)) {
428
+ letters = arg.slice(1, -1).split('');
429
+ broken = false;
430
+ for (let j = 0; j < letters.length; j++) {
431
+ next = arg.slice(j + 2);
432
+ if (letters[j + 1] && letters[j + 1] === '=') {
433
+ value = arg.slice(j + 3);
434
+ key = letters[j];
435
+ if (checkAllAliases(key, flags.arrays)) {
436
+ // array format = '-f=a b c'
437
+ i = eatArray(i, key, args, value);
438
+ }
439
+ else if (checkAllAliases(key, flags.nargs) !== false) {
440
+ // nargs format = '-f=monkey washing cat'
441
+ i = eatNargs(i, key, args, value);
442
+ }
443
+ else {
444
+ setArg(key, value);
445
+ }
446
+ broken = true;
447
+ break;
448
+ }
449
+ if (next === '-') {
450
+ setArg(letters[j], next);
451
+ continue;
452
+ }
453
+ // current letter is an alphabetic character and next value is a number
454
+ if (/[A-Za-z]/.test(letters[j]) &&
455
+ /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next) &&
456
+ checkAllAliases(next, flags.bools) === false) {
457
+ setArg(letters[j], next);
458
+ broken = true;
459
+ break;
460
+ }
461
+ if (letters[j + 1] && letters[j + 1].match(/\W/)) {
462
+ setArg(letters[j], next);
463
+ broken = true;
464
+ break;
465
+ }
466
+ else {
467
+ setArg(letters[j], defaultValue(letters[j]));
468
+ }
469
+ }
470
+ key = arg.slice(-1)[0];
471
+ if (!broken && key !== '-') {
472
+ if (checkAllAliases(key, flags.arrays)) {
473
+ // array format = '-f a b c'
474
+ i = eatArray(i, key, args);
475
+ }
476
+ else if (checkAllAliases(key, flags.nargs) !== false) {
477
+ // nargs format = '-f a b c'
478
+ // should be truthy even if: flags.nargs[key] === 0
479
+ i = eatNargs(i, key, args);
480
+ }
481
+ else {
482
+ next = args[i + 1];
483
+ if (next !== undefined && (!/^(-|--)[^-]/.test(next) ||
484
+ next.match(negative)) &&
485
+ !checkAllAliases(key, flags.bools) &&
486
+ !checkAllAliases(key, flags.counts)) {
487
+ setArg(key, next);
488
+ i++;
489
+ }
490
+ else if (/^(true|false)$/.test(next)) {
491
+ setArg(key, next);
492
+ i++;
493
+ }
494
+ else {
495
+ setArg(key, defaultValue(key));
496
+ }
497
+ }
498
+ }
499
+ }
500
+ else if (arg.match(/^-[0-9]$/) &&
501
+ arg.match(negative) &&
502
+ checkAllAliases(arg.slice(1), flags.bools)) {
503
+ // single-digit boolean alias, e.g: xargs -0
504
+ key = arg.slice(1);
505
+ setArg(key, defaultValue(key));
506
+ }
507
+ else if (arg === '--') {
508
+ notFlags = args.slice(i + 1);
509
+ break;
510
+ }
511
+ else if (configuration['halt-at-non-option']) {
512
+ notFlags = args.slice(i);
513
+ break;
514
+ }
515
+ else {
516
+ pushPositional(arg);
517
+ }
518
+ }
519
+ // order of precedence:
520
+ // 1. command line arg
521
+ // 2. value from env var
522
+ // 3. value from config file
523
+ // 4. value from config objects
524
+ // 5. configured default value
525
+ applyEnvVars(argv, true); // special case: check env vars that point to config file
526
+ applyEnvVars(argv, false);
527
+ setConfig(argv);
528
+ setConfigObjects();
529
+ applyDefaultsAndAliases(argv, flags.aliases, defaults, true);
530
+ applyCoercions(argv);
531
+ if (configuration['set-placeholder-key'])
532
+ setPlaceholderKeys(argv);
533
+ // for any counts either not in args or without an explicit default, set to 0
534
+ Object.keys(flags.counts).forEach(function (key) {
535
+ if (!hasKey(argv, key.split('.')))
536
+ setArg(key, 0);
537
+ });
538
+ // '--' defaults to undefined.
539
+ if (notFlagsOption && notFlags.length)
540
+ argv[notFlagsArgv] = [];
541
+ notFlags.forEach(function (key) {
542
+ argv[notFlagsArgv].push(key);
543
+ });
544
+ if (configuration['camel-case-expansion'] && configuration['strip-dashed']) {
545
+ Object.keys(argv).filter(key => key !== '--' && key.includes('-')).forEach(key => {
546
+ delete argv[key];
547
+ });
548
+ }
549
+ if (configuration['strip-aliased']) {
550
+ [].concat(...Object.keys(aliases).map(k => aliases[k])).forEach(alias => {
551
+ if (configuration['camel-case-expansion'] && alias.includes('-')) {
552
+ delete argv[alias.split('.').map(prop => camelCase(prop)).join('.')];
553
+ }
554
+ delete argv[alias];
555
+ });
556
+ }
557
+ // Push argument into positional array, applying numeric coercion:
558
+ function pushPositional(arg) {
559
+ const maybeCoercedNumber = maybeCoerceNumber('_', arg);
560
+ if (typeof maybeCoercedNumber === 'string' || typeof maybeCoercedNumber === 'number') {
561
+ argv._.push(maybeCoercedNumber);
562
+ }
563
+ }
564
+ // how many arguments should we consume, based
565
+ // on the nargs option?
566
+ function eatNargs(i, key, args, argAfterEqualSign) {
567
+ let ii;
568
+ let toEat = checkAllAliases(key, flags.nargs);
569
+ // NaN has a special meaning for the array type, indicating that one or
570
+ // more values are expected.
571
+ toEat = typeof toEat !== 'number' || isNaN(toEat) ? 1 : toEat;
572
+ if (toEat === 0) {
573
+ if (!isUndefined(argAfterEqualSign)) {
574
+ error = Error(__('Argument unexpected for: %s', key));
575
+ }
576
+ setArg(key, defaultValue(key));
577
+ return i;
578
+ }
579
+ let available = isUndefined(argAfterEqualSign) ? 0 : 1;
580
+ if (configuration['nargs-eats-options']) {
581
+ // classic behavior, yargs eats positional and dash arguments.
582
+ if (args.length - (i + 1) + available < toEat) {
583
+ error = Error(__('Not enough arguments following: %s', key));
584
+ }
585
+ available = toEat;
586
+ }
587
+ else {
588
+ // nargs will not consume flag arguments, e.g., -abc, --foo,
589
+ // and terminates when one is observed.
590
+ for (ii = i + 1; ii < args.length; ii++) {
591
+ if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii]))
592
+ available++;
593
+ else
594
+ break;
595
+ }
596
+ if (available < toEat)
597
+ error = Error(__('Not enough arguments following: %s', key));
598
+ }
599
+ let consumed = Math.min(available, toEat);
600
+ if (!isUndefined(argAfterEqualSign) && consumed > 0) {
601
+ setArg(key, argAfterEqualSign);
602
+ consumed--;
603
+ }
604
+ for (ii = i + 1; ii < (consumed + i + 1); ii++) {
605
+ setArg(key, args[ii]);
606
+ }
607
+ return (i + consumed);
608
+ }
609
+ // if an option is an array, eat all non-hyphenated arguments
610
+ // following it... YUM!
611
+ // e.g., --foo apple banana cat becomes ["apple", "banana", "cat"]
612
+ function eatArray(i, key, args, argAfterEqualSign) {
613
+ let argsToSet = [];
614
+ let next = argAfterEqualSign || args[i + 1];
615
+ // If both array and nargs are configured, enforce the nargs count:
616
+ const nargsCount = checkAllAliases(key, flags.nargs);
617
+ if (checkAllAliases(key, flags.bools) && !(/^(true|false)$/.test(next))) {
618
+ argsToSet.push(true);
619
+ }
620
+ else if (isUndefined(next) ||
621
+ (isUndefined(argAfterEqualSign) && /^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))) {
622
+ // for keys without value ==> argsToSet remains an empty []
623
+ // set user default value, if available
624
+ if (defaults[key] !== undefined) {
625
+ const defVal = defaults[key];
626
+ argsToSet = Array.isArray(defVal) ? defVal : [defVal];
627
+ }
628
+ }
629
+ else {
630
+ // value in --option=value is eaten as is
631
+ if (!isUndefined(argAfterEqualSign)) {
632
+ argsToSet.push(processValue(key, argAfterEqualSign, true));
633
+ }
634
+ for (let ii = i + 1; ii < args.length; ii++) {
635
+ if ((!configuration['greedy-arrays'] && argsToSet.length > 0) ||
636
+ (nargsCount && typeof nargsCount === 'number' && argsToSet.length >= nargsCount))
637
+ break;
638
+ next = args[ii];
639
+ if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))
640
+ break;
641
+ i = ii;
642
+ argsToSet.push(processValue(key, next, inputIsString));
643
+ }
644
+ }
645
+ // If both array and nargs are configured, create an error if less than
646
+ // nargs positionals were found. NaN has special meaning, indicating
647
+ // that at least one value is required (more are okay).
648
+ if (typeof nargsCount === 'number' && ((nargsCount && argsToSet.length < nargsCount) ||
649
+ (isNaN(nargsCount) && argsToSet.length === 0))) {
650
+ error = Error(__('Not enough arguments following: %s', key));
651
+ }
652
+ setArg(key, argsToSet);
653
+ return i;
654
+ }
655
+ function setArg(key, val, shouldStripQuotes = inputIsString) {
656
+ if (/-/.test(key) && configuration['camel-case-expansion']) {
657
+ const alias = key.split('.').map(function (prop) {
658
+ return camelCase(prop);
659
+ }).join('.');
660
+ addNewAlias(key, alias);
661
+ }
662
+ const value = processValue(key, val, shouldStripQuotes);
663
+ const splitKey = key.split('.');
664
+ setKey(argv, splitKey, value);
665
+ // handle populating aliases of the full key
666
+ if (flags.aliases[key]) {
667
+ flags.aliases[key].forEach(function (x) {
668
+ const keyProperties = x.split('.');
669
+ setKey(argv, keyProperties, value);
670
+ });
671
+ }
672
+ // handle populating aliases of the first element of the dot-notation key
673
+ if (splitKey.length > 1 && configuration['dot-notation']) {
674
+ (flags.aliases[splitKey[0]] || []).forEach(function (x) {
675
+ let keyProperties = x.split('.');
676
+ // expand alias with nested objects in key
677
+ const a = [].concat(splitKey);
678
+ a.shift(); // nuke the old key.
679
+ keyProperties = keyProperties.concat(a);
680
+ // populate alias only if is not already an alias of the full key
681
+ // (already populated above)
682
+ if (!(flags.aliases[key] || []).includes(keyProperties.join('.'))) {
683
+ setKey(argv, keyProperties, value);
684
+ }
685
+ });
686
+ }
687
+ // Set normalize getter and setter when key is in 'normalize' but isn't an array
688
+ if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
689
+ const keys = [key].concat(flags.aliases[key] || []);
690
+ keys.forEach(function (key) {
691
+ Object.defineProperty(argvReturn, key, {
692
+ enumerable: true,
693
+ get() {
694
+ return val;
695
+ },
696
+ set(value) {
697
+ val = typeof value === 'string' ? mixin$1.normalize(value) : value;
698
+ }
699
+ });
700
+ });
701
+ }
702
+ }
703
+ function addNewAlias(key, alias) {
704
+ if (!(flags.aliases[key] && flags.aliases[key].length)) {
705
+ flags.aliases[key] = [alias];
706
+ newAliases[alias] = true;
707
+ }
708
+ if (!(flags.aliases[alias] && flags.aliases[alias].length)) {
709
+ addNewAlias(alias, key);
710
+ }
711
+ }
712
+ function processValue(key, val, shouldStripQuotes) {
713
+ // strings may be quoted, clean this up as we assign values.
714
+ if (shouldStripQuotes) {
715
+ val = stripQuotes(val);
716
+ }
717
+ // handle parsing boolean arguments --foo=true --bar false.
718
+ if (checkAllAliases(key, flags.bools) || checkAllAliases(key, flags.counts)) {
719
+ if (typeof val === 'string')
720
+ val = val === 'true';
721
+ }
722
+ let value = Array.isArray(val)
723
+ ? val.map(function (v) { return maybeCoerceNumber(key, v); })
724
+ : maybeCoerceNumber(key, val);
725
+ // increment a count given as arg (either no value or value parsed as boolean)
726
+ if (checkAllAliases(key, flags.counts) && (isUndefined(value) || typeof value === 'boolean')) {
727
+ value = increment();
728
+ }
729
+ // Set normalized value when key is in 'normalize' and in 'arrays'
730
+ if (checkAllAliases(key, flags.normalize) && checkAllAliases(key, flags.arrays)) {
731
+ if (Array.isArray(val))
732
+ value = val.map((val) => { return mixin$1.normalize(val); });
733
+ else
734
+ value = mixin$1.normalize(val);
735
+ }
736
+ return value;
737
+ }
738
+ function maybeCoerceNumber(key, value) {
739
+ if (!configuration['parse-positional-numbers'] && key === '_')
740
+ return value;
741
+ if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.bools) && !Array.isArray(value)) {
742
+ const shouldCoerceNumber = looksLikeNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(Math.floor(parseFloat(`${value}`))));
743
+ if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) {
744
+ value = Number(value);
745
+ }
746
+ }
747
+ return value;
748
+ }
749
+ // set args from config.json file, this should be
750
+ // applied last so that defaults can be applied.
751
+ function setConfig(argv) {
752
+ const configLookup = Object.create(null);
753
+ // expand defaults/aliases, in-case any happen to reference
754
+ // the config.json file.
755
+ applyDefaultsAndAliases(configLookup, flags.aliases, defaults);
756
+ Object.keys(flags.configs).forEach(function (configKey) {
757
+ const configPath = argv[configKey] || configLookup[configKey];
758
+ if (configPath) {
759
+ try {
760
+ let config = null;
761
+ const resolvedConfigPath = mixin$1.resolve(mixin$1.cwd(), configPath);
762
+ const resolveConfig = flags.configs[configKey];
763
+ if (typeof resolveConfig === 'function') {
764
+ try {
765
+ config = resolveConfig(resolvedConfigPath);
766
+ }
767
+ catch (e) {
768
+ config = e;
769
+ }
770
+ if (config instanceof Error) {
771
+ error = config;
772
+ return;
773
+ }
774
+ }
775
+ else {
776
+ config = mixin$1.require(resolvedConfigPath);
777
+ }
778
+ setConfigObject(config);
779
+ }
780
+ catch (ex) {
781
+ // Deno will receive a PermissionDenied error if an attempt is
782
+ // made to load config without the --allow-read flag:
783
+ if (ex.name === 'PermissionDenied')
784
+ error = ex;
785
+ else if (argv[configKey])
786
+ error = Error(__('Invalid JSON config file: %s', configPath));
787
+ }
788
+ }
789
+ });
790
+ }
791
+ // set args from config object.
792
+ // it recursively checks nested objects.
793
+ function setConfigObject(config, prev) {
794
+ Object.keys(config).forEach(function (key) {
795
+ const value = config[key];
796
+ const fullKey = prev ? prev + '.' + key : key;
797
+ // if the value is an inner object and we have dot-notation
798
+ // enabled, treat inner objects in config the same as
799
+ // heavily nested dot notations (foo.bar.apple).
800
+ if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {
801
+ // if the value is an object but not an array, check nested object
802
+ setConfigObject(value, fullKey);
803
+ }
804
+ else {
805
+ // setting arguments via CLI takes precedence over
806
+ // values within the config file.
807
+ if (!hasKey(argv, fullKey.split('.')) || (checkAllAliases(fullKey, flags.arrays) && configuration['combine-arrays'])) {
808
+ setArg(fullKey, value);
809
+ }
810
+ }
811
+ });
812
+ }
813
+ // set all config objects passed in opts
814
+ function setConfigObjects() {
815
+ if (typeof configObjects !== 'undefined') {
816
+ configObjects.forEach(function (configObject) {
817
+ setConfigObject(configObject);
818
+ });
819
+ }
820
+ }
821
+ function applyEnvVars(argv, configOnly) {
822
+ if (typeof envPrefix === 'undefined')
823
+ return;
824
+ const prefix = typeof envPrefix === 'string' ? envPrefix : '';
825
+ const env = mixin$1.env();
826
+ Object.keys(env).forEach(function (envVar) {
827
+ if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {
828
+ // get array of nested keys and convert them to camel case
829
+ const keys = envVar.split('__').map(function (key, i) {
830
+ if (i === 0) {
831
+ key = key.substring(prefix.length);
832
+ }
833
+ return camelCase(key);
834
+ });
835
+ if (((configOnly && flags.configs[keys.join('.')]) || !configOnly) && !hasKey(argv, keys)) {
836
+ setArg(keys.join('.'), env[envVar]);
837
+ }
838
+ }
839
+ });
840
+ }
841
+ function applyCoercions(argv) {
842
+ let coerce;
843
+ const applied = new Set();
844
+ Object.keys(argv).forEach(function (key) {
845
+ if (!applied.has(key)) { // If we haven't already coerced this option via one of its aliases
846
+ coerce = checkAllAliases(key, flags.coercions);
847
+ if (typeof coerce === 'function') {
848
+ try {
849
+ const value = maybeCoerceNumber(key, coerce(argv[key]));
850
+ ([].concat(flags.aliases[key] || [], key)).forEach(ali => {
851
+ applied.add(ali);
852
+ argv[ali] = value;
853
+ });
854
+ }
855
+ catch (err) {
856
+ error = err;
857
+ }
858
+ }
859
+ }
860
+ });
861
+ }
862
+ function setPlaceholderKeys(argv) {
863
+ flags.keys.forEach((key) => {
864
+ // don't set placeholder keys for dot notation options 'foo.bar'.
865
+ if (~key.indexOf('.'))
866
+ return;
867
+ if (typeof argv[key] === 'undefined')
868
+ argv[key] = undefined;
869
+ });
870
+ return argv;
871
+ }
872
+ function applyDefaultsAndAliases(obj, aliases, defaults, canLog = false) {
873
+ Object.keys(defaults).forEach(function (key) {
874
+ if (!hasKey(obj, key.split('.'))) {
875
+ setKey(obj, key.split('.'), defaults[key]);
876
+ if (canLog)
877
+ defaulted[key] = true;
878
+ (aliases[key] || []).forEach(function (x) {
879
+ if (hasKey(obj, x.split('.')))
880
+ return;
881
+ setKey(obj, x.split('.'), defaults[key]);
882
+ });
883
+ }
884
+ });
885
+ }
886
+ function hasKey(obj, keys) {
887
+ let o = obj;
888
+ if (!configuration['dot-notation'])
889
+ keys = [keys.join('.')];
890
+ keys.slice(0, -1).forEach(function (key) {
891
+ o = (o[key] || {});
892
+ });
893
+ const key = keys[keys.length - 1];
894
+ if (typeof o !== 'object')
895
+ return false;
896
+ else
897
+ return key in o;
898
+ }
899
+ function setKey(obj, keys, value) {
900
+ let o = obj;
901
+ if (!configuration['dot-notation'])
902
+ keys = [keys.join('.')];
903
+ keys.slice(0, -1).forEach(function (key) {
904
+ // TODO(bcoe): in the next major version of yargs, switch to
905
+ // Object.create(null) for dot notation:
906
+ key = sanitizeKey(key);
907
+ if (typeof o === 'object' && o[key] === undefined) {
908
+ o[key] = {};
909
+ }
910
+ if (typeof o[key] !== 'object' || Array.isArray(o[key])) {
911
+ // ensure that o[key] is an array, and that the last item is an empty object.
912
+ if (Array.isArray(o[key])) {
913
+ o[key].push({});
914
+ }
915
+ else {
916
+ o[key] = [o[key], {}];
917
+ }
918
+ // we want to update the empty object at the end of the o[key] array, so set o to that object
919
+ o = o[key][o[key].length - 1];
920
+ }
921
+ else {
922
+ o = o[key];
923
+ }
924
+ });
925
+ // TODO(bcoe): in the next major version of yargs, switch to
926
+ // Object.create(null) for dot notation:
927
+ const key = sanitizeKey(keys[keys.length - 1]);
928
+ const isTypeArray = checkAllAliases(keys.join('.'), flags.arrays);
929
+ const isValueArray = Array.isArray(value);
930
+ let duplicate = configuration['duplicate-arguments-array'];
931
+ // nargs has higher priority than duplicate
932
+ if (!duplicate && checkAllAliases(key, flags.nargs)) {
933
+ duplicate = true;
934
+ if ((!isUndefined(o[key]) && flags.nargs[key] === 1) || (Array.isArray(o[key]) && o[key].length === flags.nargs[key])) {
935
+ o[key] = undefined;
936
+ }
937
+ }
938
+ if (value === increment()) {
939
+ o[key] = increment(o[key]);
940
+ }
941
+ else if (Array.isArray(o[key])) {
942
+ if (duplicate && isTypeArray && isValueArray) {
943
+ o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value]);
944
+ }
945
+ else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
946
+ o[key] = value;
947
+ }
948
+ else {
949
+ o[key] = o[key].concat([value]);
950
+ }
951
+ }
952
+ else if (o[key] === undefined && isTypeArray) {
953
+ o[key] = isValueArray ? value : [value];
954
+ }
955
+ else if (duplicate && !(o[key] === undefined ||
956
+ checkAllAliases(key, flags.counts) ||
957
+ checkAllAliases(key, flags.bools))) {
958
+ o[key] = [o[key], value];
959
+ }
960
+ else {
961
+ o[key] = value;
962
+ }
963
+ }
964
+ // extend the aliases list with inferred aliases.
965
+ function extendAliases(...args) {
966
+ args.forEach(function (obj) {
967
+ Object.keys(obj || {}).forEach(function (key) {
968
+ // short-circuit if we've already added a key
969
+ // to the aliases array, for example it might
970
+ // exist in both 'opts.default' and 'opts.key'.
971
+ if (flags.aliases[key])
972
+ return;
973
+ flags.aliases[key] = [].concat(aliases[key] || []);
974
+ // For "--option-name", also set argv.optionName
975
+ flags.aliases[key].concat(key).forEach(function (x) {
976
+ if (/-/.test(x) && configuration['camel-case-expansion']) {
977
+ const c = camelCase(x);
978
+ if (c !== key && flags.aliases[key].indexOf(c) === -1) {
979
+ flags.aliases[key].push(c);
980
+ newAliases[c] = true;
981
+ }
982
+ }
983
+ });
984
+ // For "--optionName", also set argv['option-name']
985
+ flags.aliases[key].concat(key).forEach(function (x) {
986
+ if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {
987
+ const c = decamelize(x, '-');
988
+ if (c !== key && flags.aliases[key].indexOf(c) === -1) {
989
+ flags.aliases[key].push(c);
990
+ newAliases[c] = true;
991
+ }
992
+ }
993
+ });
994
+ flags.aliases[key].forEach(function (x) {
995
+ flags.aliases[x] = [key].concat(flags.aliases[key].filter(function (y) {
996
+ return x !== y;
997
+ }));
998
+ });
999
+ });
1000
+ });
1001
+ }
1002
+ function checkAllAliases(key, flag) {
1003
+ const toCheck = [].concat(flags.aliases[key] || [], key);
1004
+ const keys = Object.keys(flag);
1005
+ const setAlias = toCheck.find(key => keys.includes(key));
1006
+ return setAlias ? flag[setAlias] : false;
1007
+ }
1008
+ function hasAnyFlag(key) {
1009
+ const flagsKeys = Object.keys(flags);
1010
+ const toCheck = [].concat(flagsKeys.map(k => flags[k]));
1011
+ return toCheck.some(function (flag) {
1012
+ return Array.isArray(flag) ? flag.includes(key) : flag[key];
1013
+ });
1014
+ }
1015
+ function hasFlagsMatching(arg, ...patterns) {
1016
+ const toCheck = [].concat(...patterns);
1017
+ return toCheck.some(function (pattern) {
1018
+ const match = arg.match(pattern);
1019
+ return match && hasAnyFlag(match[1]);
1020
+ });
1021
+ }
1022
+ // based on a simplified version of the short flag group parsing logic
1023
+ function hasAllShortFlags(arg) {
1024
+ // if this is a negative number, or doesn't start with a single hyphen, it's not a short flag group
1025
+ if (arg.match(negative) || !arg.match(/^-[^-]+/)) {
1026
+ return false;
1027
+ }
1028
+ let hasAllFlags = true;
1029
+ let next;
1030
+ const letters = arg.slice(1).split('');
1031
+ for (let j = 0; j < letters.length; j++) {
1032
+ next = arg.slice(j + 2);
1033
+ if (!hasAnyFlag(letters[j])) {
1034
+ hasAllFlags = false;
1035
+ break;
1036
+ }
1037
+ if ((letters[j + 1] && letters[j + 1] === '=') ||
1038
+ next === '-' ||
1039
+ (/[A-Za-z]/.test(letters[j]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) ||
1040
+ (letters[j + 1] && letters[j + 1].match(/\W/))) {
1041
+ break;
1042
+ }
1043
+ }
1044
+ return hasAllFlags;
1045
+ }
1046
+ function isUnknownOptionAsArg(arg) {
1047
+ return configuration['unknown-options-as-args'] && isUnknownOption(arg);
1048
+ }
1049
+ function isUnknownOption(arg) {
1050
+ arg = arg.replace(/^-{3,}/, '--');
1051
+ // ignore negative numbers
1052
+ if (arg.match(negative)) {
1053
+ return false;
1054
+ }
1055
+ // if this is a short option group and all of them are configured, it isn't unknown
1056
+ if (hasAllShortFlags(arg)) {
1057
+ return false;
1058
+ }
1059
+ // e.g. '--count=2'
1060
+ const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/;
1061
+ // e.g. '-a' or '--arg'
1062
+ const normalFlag = /^-+([^=]+?)$/;
1063
+ // e.g. '-a-'
1064
+ const flagEndingInHyphen = /^-+([^=]+?)-$/;
1065
+ // e.g. '-abc123'
1066
+ const flagEndingInDigits = /^-+([^=]+?\d+)$/;
1067
+ // e.g. '-a/usr/local'
1068
+ const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;
1069
+ // check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
1070
+ return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag, flagEndingInHyphen, flagEndingInDigits, flagEndingInNonWordCharacters);
1071
+ }
1072
+ // make a best effort to pick a default value
1073
+ // for an option based on name and type.
1074
+ function defaultValue(key) {
1075
+ if (!checkAllAliases(key, flags.bools) &&
1076
+ !checkAllAliases(key, flags.counts) &&
1077
+ `${key}` in defaults) {
1078
+ return defaults[key];
1079
+ }
1080
+ else {
1081
+ return defaultForType(guessType(key));
1082
+ }
1083
+ }
1084
+ // return a default value, given the type of a flag.,
1085
+ function defaultForType(type) {
1086
+ const def = {
1087
+ [DefaultValuesForTypeKey.BOOLEAN]: true,
1088
+ [DefaultValuesForTypeKey.STRING]: '',
1089
+ [DefaultValuesForTypeKey.NUMBER]: undefined,
1090
+ [DefaultValuesForTypeKey.ARRAY]: []
1091
+ };
1092
+ return def[type];
1093
+ }
1094
+ // given a flag, enforce a default type.
1095
+ function guessType(key) {
1096
+ let type = DefaultValuesForTypeKey.BOOLEAN;
1097
+ if (checkAllAliases(key, flags.strings))
1098
+ type = DefaultValuesForTypeKey.STRING;
1099
+ else if (checkAllAliases(key, flags.numbers))
1100
+ type = DefaultValuesForTypeKey.NUMBER;
1101
+ else if (checkAllAliases(key, flags.bools))
1102
+ type = DefaultValuesForTypeKey.BOOLEAN;
1103
+ else if (checkAllAliases(key, flags.arrays))
1104
+ type = DefaultValuesForTypeKey.ARRAY;
1105
+ return type;
1106
+ }
1107
+ function isUndefined(num) {
1108
+ return num === undefined;
1109
+ }
1110
+ // check user configuration settings for inconsistencies
1111
+ function checkConfiguration() {
1112
+ // count keys should not be set as array/narg
1113
+ Object.keys(flags.counts).find(key => {
1114
+ if (checkAllAliases(key, flags.arrays)) {
1115
+ error = Error(__('Invalid configuration: %s, opts.count excludes opts.array.', key));
1116
+ return true;
1117
+ }
1118
+ else if (checkAllAliases(key, flags.nargs)) {
1119
+ error = Error(__('Invalid configuration: %s, opts.count excludes opts.narg.', key));
1120
+ return true;
1121
+ }
1122
+ return false;
1123
+ });
1124
+ }
1125
+ return {
1126
+ aliases: Object.assign({}, flags.aliases),
1127
+ argv: Object.assign(argvReturn, argv),
1128
+ configuration: configuration,
1129
+ defaulted: Object.assign({}, defaulted),
1130
+ error: error,
1131
+ newAliases: Object.assign({}, newAliases)
1132
+ };
1133
+ }
1134
+ }
1135
+ // if any aliases reference each other, we should
1136
+ // merge them together.
1137
+ function combineAliases(aliases) {
1138
+ const aliasArrays = [];
1139
+ const combined = Object.create(null);
1140
+ let change = true;
1141
+ // turn alias lookup hash {key: ['alias1', 'alias2']} into
1142
+ // a simple array ['key', 'alias1', 'alias2']
1143
+ Object.keys(aliases).forEach(function (key) {
1144
+ aliasArrays.push([].concat(aliases[key], key));
1145
+ });
1146
+ // combine arrays until zero changes are
1147
+ // made in an iteration.
1148
+ while (change) {
1149
+ change = false;
1150
+ for (let i = 0; i < aliasArrays.length; i++) {
1151
+ for (let ii = i + 1; ii < aliasArrays.length; ii++) {
1152
+ const intersect = aliasArrays[i].filter(function (v) {
1153
+ return aliasArrays[ii].indexOf(v) !== -1;
1154
+ });
1155
+ if (intersect.length) {
1156
+ aliasArrays[i] = aliasArrays[i].concat(aliasArrays[ii]);
1157
+ aliasArrays.splice(ii, 1);
1158
+ change = true;
1159
+ break;
1160
+ }
1161
+ }
1162
+ }
1163
+ }
1164
+ // map arrays back to the hash-lookup (de-dupe while
1165
+ // we're at it).
1166
+ aliasArrays.forEach(function (aliasArray) {
1167
+ aliasArray = aliasArray.filter(function (v, i, self) {
1168
+ return self.indexOf(v) === i;
1169
+ });
1170
+ const lastAlias = aliasArray.pop();
1171
+ if (lastAlias !== undefined && typeof lastAlias === 'string') {
1172
+ combined[lastAlias] = aliasArray;
1173
+ }
1174
+ });
1175
+ return combined;
1176
+ }
1177
+ // this function should only be called when a count is given as an arg
1178
+ // it is NOT called to set a default value
1179
+ // thus we can start the count at 1 instead of 0
1180
+ function increment(orig) {
1181
+ return orig !== undefined ? orig + 1 : 1;
1182
+ }
1183
+ // TODO(bcoe): in the next major version of yargs, switch to
1184
+ // Object.create(null) for dot notation:
1185
+ function sanitizeKey(key) {
1186
+ if (key === '__proto__')
1187
+ return '___proto___';
1188
+ return key;
1189
+ }
1190
+ function stripQuotes(val) {
1191
+ return (typeof val === 'string' &&
1192
+ (val[0] === "'" || val[0] === '"') &&
1193
+ val[val.length - 1] === val[0])
1194
+ ? val.substring(1, val.length - 1)
1195
+ : val;
1196
+ }
1197
+
1198
+ /**
1199
+ * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
1200
+ * CJS and ESM environments.
1201
+ *
1202
+ * @license
1203
+ * Copyright (c) 2016, Contributors
1204
+ * SPDX-License-Identifier: ISC
1205
+ */
1206
+ var _a, _b, _c;
1207
+ // See https://github.com/yargs/yargs-parser#supported-nodejs-versions for our
1208
+ // version support policy. The YARGS_MIN_NODE_VERSION is used for testing only.
1209
+ const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
1210
+ ? Number(process.env.YARGS_MIN_NODE_VERSION)
1211
+ : 12;
1212
+ const nodeVersion = (_b = (_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : (_c = process === null || process === void 0 ? void 0 : process.version) === null || _c === void 0 ? void 0 : _c.slice(1);
1213
+ if (nodeVersion) {
1214
+ const major = Number(nodeVersion.match(/^([^.]+)/)[1]);
1215
+ if (major < minNodeVersion) {
1216
+ throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);
1217
+ }
1218
+ }
1219
+ // Creates a yargs-parser instance using Node.js standard libraries:
1220
+ const env = process ? process.env : {};
1221
+ const parser = new YargsParser({
1222
+ cwd: process.cwd,
1223
+ env: () => {
1224
+ return env;
1225
+ },
1226
+ format,
1227
+ normalize,
1228
+ resolve,
1229
+ // TODO: figure out a way to combine ESM and CJS coverage, such that
1230
+ // we can exercise all the lines below:
1231
+ require: (path) => {
1232
+ if (typeof require !== 'undefined') {
1233
+ return require(path);
1234
+ }
1235
+ else if (path.match(/\.json$/)) {
1236
+ // Addresses: https://github.com/yargs/yargs/issues/2040
1237
+ return JSON.parse(readFileSync(path, 'utf8'));
1238
+ }
1239
+ else {
1240
+ throw Error('only .json config files are supported in ESM');
1241
+ }
1242
+ }
1243
+ });
1244
+ const yargsParser = function Parser(args, opts) {
1245
+ const result = parser.parse(args.slice(), opts);
1246
+ return result.argv;
1247
+ };
1248
+ yargsParser.detailed = function (args, opts) {
1249
+ return parser.parse(args.slice(), opts);
1250
+ };
1251
+ yargsParser.camelCase = camelCase;
1252
+ yargsParser.decamelize = decamelize;
1253
+ yargsParser.looksLikeNumber = looksLikeNumber;
1254
+
1255
+ const align = {
1256
+ right: alignRight,
1257
+ center: alignCenter
1258
+ };
1259
+ const top = 0;
1260
+ const right = 1;
1261
+ const bottom = 2;
1262
+ const left = 3;
1263
+ class UI {
1264
+ constructor(opts) {
1265
+ var _a;
1266
+ this.width = opts.width;
1267
+ this.wrap = (_a = opts.wrap) !== null && _a !== void 0 ? _a : true;
1268
+ this.rows = [];
1269
+ }
1270
+ span(...args) {
1271
+ const cols = this.div(...args);
1272
+ cols.span = true;
1273
+ }
1274
+ resetOutput() {
1275
+ this.rows = [];
1276
+ }
1277
+ div(...args) {
1278
+ if (args.length === 0) {
1279
+ this.div('');
1280
+ }
1281
+ if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === 'string') {
1282
+ return this.applyLayoutDSL(args[0]);
1283
+ }
1284
+ const cols = args.map(arg => {
1285
+ if (typeof arg === 'string') {
1286
+ return this.colFromString(arg);
1287
+ }
1288
+ return arg;
1289
+ });
1290
+ this.rows.push(cols);
1291
+ return cols;
1292
+ }
1293
+ shouldApplyLayoutDSL(...args) {
1294
+ return args.length === 1 && typeof args[0] === 'string' &&
1295
+ /[\t\n]/.test(args[0]);
1296
+ }
1297
+ applyLayoutDSL(str) {
1298
+ const rows = str.split('\n').map(row => row.split('\t'));
1299
+ let leftColumnWidth = 0;
1300
+ // simple heuristic for layout, make sure the
1301
+ // second column lines up along the left-hand.
1302
+ // don't allow the first column to take up more
1303
+ // than 50% of the screen.
1304
+ rows.forEach(columns => {
1305
+ if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
1306
+ leftColumnWidth = Math.min(Math.floor(this.width * 0.5), mixin.stringWidth(columns[0]));
1307
+ }
1308
+ });
1309
+ // generate a table:
1310
+ // replacing ' ' with padding calculations.
1311
+ // using the algorithmically generated width.
1312
+ rows.forEach(columns => {
1313
+ this.div(...columns.map((r, i) => {
1314
+ return {
1315
+ text: r.trim(),
1316
+ padding: this.measurePadding(r),
1317
+ width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
1318
+ };
1319
+ }));
1320
+ });
1321
+ return this.rows[this.rows.length - 1];
1322
+ }
1323
+ colFromString(text) {
1324
+ return {
1325
+ text,
1326
+ padding: this.measurePadding(text)
1327
+ };
1328
+ }
1329
+ measurePadding(str) {
1330
+ // measure padding without ansi escape codes
1331
+ const noAnsi = mixin.stripAnsi(str);
1332
+ return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length];
1333
+ }
1334
+ toString() {
1335
+ const lines = [];
1336
+ this.rows.forEach(row => {
1337
+ this.rowToString(row, lines);
1338
+ });
1339
+ // don't display any lines with the
1340
+ // hidden flag set.
1341
+ return lines
1342
+ .filter(line => !line.hidden)
1343
+ .map(line => line.text)
1344
+ .join('\n');
1345
+ }
1346
+ rowToString(row, lines) {
1347
+ this.rasterize(row).forEach((rrow, r) => {
1348
+ let str = '';
1349
+ rrow.forEach((col, c) => {
1350
+ const { width } = row[c]; // the width with padding.
1351
+ const wrapWidth = this.negatePadding(row[c]); // the width without padding.
1352
+ let ts = col; // temporary string used during alignment/padding.
1353
+ if (wrapWidth > mixin.stringWidth(col)) {
1354
+ ts += ' '.repeat(wrapWidth - mixin.stringWidth(col));
1355
+ }
1356
+ // align the string within its column.
1357
+ if (row[c].align && row[c].align !== 'left' && this.wrap) {
1358
+ const fn = align[row[c].align];
1359
+ ts = fn(ts, wrapWidth);
1360
+ if (mixin.stringWidth(ts) < wrapWidth) {
1361
+ ts += ' '.repeat((width || 0) - mixin.stringWidth(ts) - 1);
1362
+ }
1363
+ }
1364
+ // apply border and padding to string.
1365
+ const padding = row[c].padding || [0, 0, 0, 0];
1366
+ if (padding[left]) {
1367
+ str += ' '.repeat(padding[left]);
1368
+ }
1369
+ str += addBorder(row[c], ts, '| ');
1370
+ str += ts;
1371
+ str += addBorder(row[c], ts, ' |');
1372
+ if (padding[right]) {
1373
+ str += ' '.repeat(padding[right]);
1374
+ }
1375
+ // if prior row is span, try to render the
1376
+ // current row on the prior line.
1377
+ if (r === 0 && lines.length > 0) {
1378
+ str = this.renderInline(str, lines[lines.length - 1]);
1379
+ }
1380
+ });
1381
+ // remove trailing whitespace.
1382
+ lines.push({
1383
+ text: str.replace(/ +$/, ''),
1384
+ span: row.span
1385
+ });
1386
+ });
1387
+ return lines;
1388
+ }
1389
+ // if the full 'source' can render in
1390
+ // the target line, do so.
1391
+ renderInline(source, previousLine) {
1392
+ const match = source.match(/^ */);
1393
+ const leadingWhitespace = match ? match[0].length : 0;
1394
+ const target = previousLine.text;
1395
+ const targetTextWidth = mixin.stringWidth(target.trimRight());
1396
+ if (!previousLine.span) {
1397
+ return source;
1398
+ }
1399
+ // if we're not applying wrapping logic,
1400
+ // just always append to the span.
1401
+ if (!this.wrap) {
1402
+ previousLine.hidden = true;
1403
+ return target + source;
1404
+ }
1405
+ if (leadingWhitespace < targetTextWidth) {
1406
+ return source;
1407
+ }
1408
+ previousLine.hidden = true;
1409
+ return target.trimRight() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimLeft();
1410
+ }
1411
+ rasterize(row) {
1412
+ const rrows = [];
1413
+ const widths = this.columnWidths(row);
1414
+ let wrapped;
1415
+ // word wrap all columns, and create
1416
+ // a data-structure that is easy to rasterize.
1417
+ row.forEach((col, c) => {
1418
+ // leave room for left and right padding.
1419
+ col.width = widths[c];
1420
+ if (this.wrap) {
1421
+ wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split('\n');
1422
+ }
1423
+ else {
1424
+ wrapped = col.text.split('\n');
1425
+ }
1426
+ if (col.border) {
1427
+ wrapped.unshift('.' + '-'.repeat(this.negatePadding(col) + 2) + '.');
1428
+ wrapped.push("'" + '-'.repeat(this.negatePadding(col) + 2) + "'");
1429
+ }
1430
+ // add top and bottom padding.
1431
+ if (col.padding) {
1432
+ wrapped.unshift(...new Array(col.padding[top] || 0).fill(''));
1433
+ wrapped.push(...new Array(col.padding[bottom] || 0).fill(''));
1434
+ }
1435
+ wrapped.forEach((str, r) => {
1436
+ if (!rrows[r]) {
1437
+ rrows.push([]);
1438
+ }
1439
+ const rrow = rrows[r];
1440
+ for (let i = 0; i < c; i++) {
1441
+ if (rrow[i] === undefined) {
1442
+ rrow.push('');
1443
+ }
1444
+ }
1445
+ rrow.push(str);
1446
+ });
1447
+ });
1448
+ return rrows;
1449
+ }
1450
+ negatePadding(col) {
1451
+ let wrapWidth = col.width || 0;
1452
+ if (col.padding) {
1453
+ wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0);
1454
+ }
1455
+ if (col.border) {
1456
+ wrapWidth -= 4;
1457
+ }
1458
+ return wrapWidth;
1459
+ }
1460
+ columnWidths(row) {
1461
+ if (!this.wrap) {
1462
+ return row.map(col => {
1463
+ return col.width || mixin.stringWidth(col.text);
1464
+ });
1465
+ }
1466
+ let unset = row.length;
1467
+ let remainingWidth = this.width;
1468
+ // column widths can be set in config.
1469
+ const widths = row.map(col => {
1470
+ if (col.width) {
1471
+ unset--;
1472
+ remainingWidth -= col.width;
1473
+ return col.width;
1474
+ }
1475
+ return undefined;
1476
+ });
1477
+ // any unset widths should be calculated.
1478
+ const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0;
1479
+ return widths.map((w, i) => {
1480
+ if (w === undefined) {
1481
+ return Math.max(unsetWidth, _minWidth(row[i]));
1482
+ }
1483
+ return w;
1484
+ });
1485
+ }
1486
+ }
1487
+ function addBorder(col, ts, style) {
1488
+ if (col.border) {
1489
+ if (/[.']-+[.']/.test(ts)) {
1490
+ return '';
1491
+ }
1492
+ if (ts.trim().length !== 0) {
1493
+ return style;
1494
+ }
1495
+ return ' ';
1496
+ }
1497
+ return '';
1498
+ }
1499
+ // calculates the minimum width of
1500
+ // a column, based on padding preferences.
1501
+ function _minWidth(col) {
1502
+ const padding = col.padding || [];
1503
+ const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0);
1504
+ if (col.border) {
1505
+ return minWidth + 4;
1506
+ }
1507
+ return minWidth;
1508
+ }
1509
+ function getWindowWidth() {
1510
+ /* istanbul ignore next: depends on terminal */
1511
+ if (typeof process === 'object' && process.stdout && process.stdout.columns) {
1512
+ return process.stdout.columns;
1513
+ }
1514
+ return 80;
1515
+ }
1516
+ function alignRight(str, width) {
1517
+ str = str.trim();
1518
+ const strWidth = mixin.stringWidth(str);
1519
+ if (strWidth < width) {
1520
+ return ' '.repeat(width - strWidth) + str;
1521
+ }
1522
+ return str;
1523
+ }
1524
+ function alignCenter(str, width) {
1525
+ str = str.trim();
1526
+ const strWidth = mixin.stringWidth(str);
1527
+ /* istanbul ignore next */
1528
+ if (strWidth >= width) {
1529
+ return str;
1530
+ }
1531
+ return ' '.repeat((width - strWidth) >> 1) + str;
1532
+ }
1533
+ let mixin;
1534
+ function cliui(opts, _mixin) {
1535
+ mixin = _mixin;
1536
+ return new UI({
1537
+ width: (opts === null || opts === void 0 ? void 0 : opts.width) || getWindowWidth(),
1538
+ wrap: opts === null || opts === void 0 ? void 0 : opts.wrap
1539
+ });
1540
+ }
1541
+
1542
+ // Minimal replacement for ansi string helpers "wrap-ansi" and "strip-ansi".
1543
+ // to facilitate ESM and Deno modules.
1544
+ // TODO: look at porting https://www.npmjs.com/package/wrap-ansi to ESM.
1545
+ // The npm application
1546
+ // Copyright (c) npm, Inc. and Contributors
1547
+ // Licensed on the terms of The Artistic License 2.0
1548
+ // See: https://github.com/npm/cli/blob/4c65cd952bc8627811735bea76b9b110cc4fc80e/lib/utils/ansi-trim.js
1549
+ const ansi = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' +
1550
+ '\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g');
1551
+ function stripAnsi(str) {
1552
+ return str.replace(ansi, '');
1553
+ }
1554
+ function wrap(str, width) {
1555
+ const [start, end] = str.match(ansi) || ['', ''];
1556
+ str = stripAnsi(str);
1557
+ let wrapped = '';
1558
+ for (let i = 0; i < str.length; i++) {
1559
+ if (i !== 0 && (i % width) === 0) {
1560
+ wrapped += '\n';
1561
+ }
1562
+ wrapped += str.charAt(i);
1563
+ }
1564
+ if (start && end) {
1565
+ wrapped = `${start}${wrapped}${end}`;
1566
+ }
1567
+ return wrapped;
1568
+ }
1569
+
1570
+ // Bootstrap cliui with CommonJS dependencies:
1571
+
1572
+ function ui (opts) {
1573
+ return cliui(opts, {
1574
+ stringWidth: (str) => {
1575
+ return [...str].length
1576
+ },
1577
+ stripAnsi,
1578
+ wrap
1579
+ })
1580
+ }
1581
+
1582
+ function escalade (start, callback) {
1583
+ let dir = resolve('.', start);
1584
+ let tmp, stats = statSync(dir);
1585
+
1586
+ if (!stats.isDirectory()) {
1587
+ dir = dirname(dir);
1588
+ }
1589
+
1590
+ while (true) {
1591
+ tmp = callback(dir, readdirSync(dir));
1592
+ if (tmp) return resolve(dir, tmp);
1593
+ dir = dirname(tmp = dir);
1594
+ if (tmp === dir) break;
1595
+ }
1596
+ }
1597
+
1598
+ var shim$1 = {
1599
+ fs: {
1600
+ readFileSync,
1601
+ writeFile
1602
+ },
1603
+ format,
1604
+ resolve,
1605
+ exists: (file) => {
1606
+ try {
1607
+ return statSync(file).isFile();
1608
+ }
1609
+ catch (err) {
1610
+ return false;
1611
+ }
1612
+ }
1613
+ };
1614
+
1615
+ let shim;
1616
+ class Y18N {
1617
+ constructor(opts) {
1618
+ // configurable options.
1619
+ opts = opts || {};
1620
+ this.directory = opts.directory || './locales';
1621
+ this.updateFiles = typeof opts.updateFiles === 'boolean' ? opts.updateFiles : true;
1622
+ this.locale = opts.locale || 'en';
1623
+ this.fallbackToLanguage = typeof opts.fallbackToLanguage === 'boolean' ? opts.fallbackToLanguage : true;
1624
+ // internal stuff.
1625
+ this.cache = Object.create(null);
1626
+ this.writeQueue = [];
1627
+ }
1628
+ __(...args) {
1629
+ if (typeof arguments[0] !== 'string') {
1630
+ return this._taggedLiteral(arguments[0], ...arguments);
1631
+ }
1632
+ const str = args.shift();
1633
+ let cb = function () { }; // start with noop.
1634
+ if (typeof args[args.length - 1] === 'function')
1635
+ cb = args.pop();
1636
+ cb = cb || function () { }; // noop.
1637
+ if (!this.cache[this.locale])
1638
+ this._readLocaleFile();
1639
+ // we've observed a new string, update the language file.
1640
+ if (!this.cache[this.locale][str] && this.updateFiles) {
1641
+ this.cache[this.locale][str] = str;
1642
+ // include the current directory and locale,
1643
+ // since these values could change before the
1644
+ // write is performed.
1645
+ this._enqueueWrite({
1646
+ directory: this.directory,
1647
+ locale: this.locale,
1648
+ cb
1649
+ });
1650
+ }
1651
+ else {
1652
+ cb();
1653
+ }
1654
+ return shim.format.apply(shim.format, [this.cache[this.locale][str] || str].concat(args));
1655
+ }
1656
+ __n() {
1657
+ const args = Array.prototype.slice.call(arguments);
1658
+ const singular = args.shift();
1659
+ const plural = args.shift();
1660
+ const quantity = args.shift();
1661
+ let cb = function () { }; // start with noop.
1662
+ if (typeof args[args.length - 1] === 'function')
1663
+ cb = args.pop();
1664
+ if (!this.cache[this.locale])
1665
+ this._readLocaleFile();
1666
+ let str = quantity === 1 ? singular : plural;
1667
+ if (this.cache[this.locale][singular]) {
1668
+ const entry = this.cache[this.locale][singular];
1669
+ str = entry[quantity === 1 ? 'one' : 'other'];
1670
+ }
1671
+ // we've observed a new string, update the language file.
1672
+ if (!this.cache[this.locale][singular] && this.updateFiles) {
1673
+ this.cache[this.locale][singular] = {
1674
+ one: singular,
1675
+ other: plural
1676
+ };
1677
+ // include the current directory and locale,
1678
+ // since these values could change before the
1679
+ // write is performed.
1680
+ this._enqueueWrite({
1681
+ directory: this.directory,
1682
+ locale: this.locale,
1683
+ cb
1684
+ });
1685
+ }
1686
+ else {
1687
+ cb();
1688
+ }
1689
+ // if a %d placeholder is provided, add quantity
1690
+ // to the arguments expanded by util.format.
1691
+ const values = [str];
1692
+ if (~str.indexOf('%d'))
1693
+ values.push(quantity);
1694
+ return shim.format.apply(shim.format, values.concat(args));
1695
+ }
1696
+ setLocale(locale) {
1697
+ this.locale = locale;
1698
+ }
1699
+ getLocale() {
1700
+ return this.locale;
1701
+ }
1702
+ updateLocale(obj) {
1703
+ if (!this.cache[this.locale])
1704
+ this._readLocaleFile();
1705
+ for (const key in obj) {
1706
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1707
+ this.cache[this.locale][key] = obj[key];
1708
+ }
1709
+ }
1710
+ }
1711
+ _taggedLiteral(parts, ...args) {
1712
+ let str = '';
1713
+ parts.forEach(function (part, i) {
1714
+ const arg = args[i + 1];
1715
+ str += part;
1716
+ if (typeof arg !== 'undefined') {
1717
+ str += '%s';
1718
+ }
1719
+ });
1720
+ return this.__.apply(this, [str].concat([].slice.call(args, 1)));
1721
+ }
1722
+ _enqueueWrite(work) {
1723
+ this.writeQueue.push(work);
1724
+ if (this.writeQueue.length === 1)
1725
+ this._processWriteQueue();
1726
+ }
1727
+ _processWriteQueue() {
1728
+ const _this = this;
1729
+ const work = this.writeQueue[0];
1730
+ // destructure the enqueued work.
1731
+ const directory = work.directory;
1732
+ const locale = work.locale;
1733
+ const cb = work.cb;
1734
+ const languageFile = this._resolveLocaleFile(directory, locale);
1735
+ const serializedLocale = JSON.stringify(this.cache[locale], null, 2);
1736
+ shim.fs.writeFile(languageFile, serializedLocale, 'utf-8', function (err) {
1737
+ _this.writeQueue.shift();
1738
+ if (_this.writeQueue.length > 0)
1739
+ _this._processWriteQueue();
1740
+ cb(err);
1741
+ });
1742
+ }
1743
+ _readLocaleFile() {
1744
+ let localeLookup = {};
1745
+ const languageFile = this._resolveLocaleFile(this.directory, this.locale);
1746
+ try {
1747
+ // When using a bundler such as webpack, readFileSync may not be defined:
1748
+ if (shim.fs.readFileSync) {
1749
+ localeLookup = JSON.parse(shim.fs.readFileSync(languageFile, 'utf-8'));
1750
+ }
1751
+ }
1752
+ catch (err) {
1753
+ if (err instanceof SyntaxError) {
1754
+ err.message = 'syntax error in ' + languageFile;
1755
+ }
1756
+ if (err.code === 'ENOENT')
1757
+ localeLookup = {};
1758
+ else
1759
+ throw err;
1760
+ }
1761
+ this.cache[this.locale] = localeLookup;
1762
+ }
1763
+ _resolveLocaleFile(directory, locale) {
1764
+ let file = shim.resolve(directory, './', locale + '.json');
1765
+ if (this.fallbackToLanguage && !this._fileExistsSync(file) && ~locale.lastIndexOf('_')) {
1766
+ // attempt fallback to language only
1767
+ const languageFile = shim.resolve(directory, './', locale.split('_')[0] + '.json');
1768
+ if (this._fileExistsSync(languageFile))
1769
+ file = languageFile;
1770
+ }
1771
+ return file;
1772
+ }
1773
+ _fileExistsSync(file) {
1774
+ return shim.exists(file);
1775
+ }
1776
+ }
1777
+ function y18n$1(opts, _shim) {
1778
+ shim = _shim;
1779
+ const y18n = new Y18N(opts);
1780
+ return {
1781
+ __: y18n.__.bind(y18n),
1782
+ __n: y18n.__n.bind(y18n),
1783
+ setLocale: y18n.setLocale.bind(y18n),
1784
+ getLocale: y18n.getLocale.bind(y18n),
1785
+ updateLocale: y18n.updateLocale.bind(y18n),
1786
+ locale: y18n.locale
1787
+ };
1788
+ }
1789
+
1790
+ const y18n = (opts) => {
1791
+ return y18n$1(opts, shim$1)
1792
+ };
1793
+
1794
+ const REQUIRE_ERROR = 'require is not supported by ESM';
1795
+ const REQUIRE_DIRECTORY_ERROR = 'loading a directory of commands is not supported yet for ESM';
1796
+
1797
+ let __dirname;
1798
+ try {
1799
+ __dirname = fileURLToPath(import.meta.url);
1800
+ } catch (e) {
1801
+ __dirname = process.cwd();
1802
+ }
1803
+ const mainFilename = __dirname.substring(0, __dirname.lastIndexOf('node_modules'));
1804
+
1805
+ ({
1806
+ assert: {
1807
+ notStrictEqual,
1808
+ strictEqual
1809
+ },
1810
+ cliui: ui,
1811
+ findUp: escalade,
1812
+ getEnv: (key) => {
1813
+ return process.env[key]
1814
+ },
1815
+ inspect,
1816
+ getCallerFile: () => {
1817
+ throw new YError(REQUIRE_DIRECTORY_ERROR)
1818
+ },
1819
+ getProcessArgvBin,
1820
+ mainFilename: mainFilename || process.cwd(),
1821
+ Parser: yargsParser,
1822
+ path: {
1823
+ basename,
1824
+ dirname,
1825
+ extname,
1826
+ relative,
1827
+ resolve
1828
+ },
1829
+ process: {
1830
+ argv: () => process.argv,
1831
+ cwd: process.cwd,
1832
+ emitWarning: (warning, type) => process.emitWarning(warning, type),
1833
+ execPath: () => process.execPath,
1834
+ exit: process.exit,
1835
+ nextTick: process.nextTick,
1836
+ stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
1837
+ },
1838
+ readFileSync,
1839
+ require: () => {
1840
+ throw new YError(REQUIRE_ERROR)
1841
+ },
1842
+ requireDirectory: () => {
1843
+ throw new YError(REQUIRE_DIRECTORY_ERROR)
1844
+ },
1845
+ stringWidth: (str) => {
1846
+ return [...str].length
1847
+ },
1848
+ y18n: y18n({
1849
+ directory: resolve(__dirname, '../../../locales'),
1850
+ updateFiles: false
1851
+ })
1852
+ });
1853
+
1854
+ const instance = yargs(hideBin(process.argv));
1855
+ var instance$1 = instance.scriptName(chalk.hex('#44bcd8')('master'));
1856
+
1857
+ instance$1.help(true).parse();
1858
+ //# sourceMappingURL=index.js.map