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