yargs 16.0.1 → 16.1.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/build/index.cjs CHANGED
@@ -24,24 +24,25 @@ function applyExtends(config, cwd, mergeExtends, _shim) {
24
24
  try {
25
25
  pathToDefault = require.resolve(config.extends);
26
26
  }
27
- catch (err) {
27
+ catch (_err) {
28
+ return config;
28
29
  }
29
30
  }
30
31
  else {
31
32
  pathToDefault = getPathToDefaultConfig(cwd, config.extends);
32
33
  }
33
- if (!pathToDefault && !isPath)
34
- return config;
35
- if (!pathToDefault)
36
- throw new YError(`Unable to find extended config '${config.extends}' in '${cwd}'.`);
37
34
  checkForCircularExtends(pathToDefault);
38
35
  previouslyVisitedConfigs.push(pathToDefault);
39
- defaultConfig = isPath ? JSON.parse(shim.readFileSync(pathToDefault, 'utf8')) : require(config.extends);
36
+ defaultConfig = isPath
37
+ ? JSON.parse(shim.readFileSync(pathToDefault, 'utf8'))
38
+ : require(config.extends);
40
39
  delete config.extends;
41
40
  defaultConfig = applyExtends(defaultConfig, shim.path.dirname(pathToDefault), mergeExtends, shim);
42
41
  }
43
42
  previouslyVisitedConfigs = [];
44
- return mergeExtends ? mergeDeep(defaultConfig, config) : Object.assign({}, defaultConfig, config);
43
+ return mergeExtends
44
+ ? mergeDeep(defaultConfig, config)
45
+ : Object.assign({}, defaultConfig, config);
45
46
  }
46
47
  function checkForCircularExtends(cfgPath) {
47
48
  if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
@@ -78,7 +79,7 @@ function parseCommand(cmd) {
78
79
  const parsedCommand = {
79
80
  cmd: firstCommand.replace(bregex, ''),
80
81
  demanded: [],
81
- optional: []
82
+ optional: [],
82
83
  };
83
84
  splitCommand.forEach((cmd, i) => {
84
85
  let variadic = false;
@@ -88,13 +89,13 @@ function parseCommand(cmd) {
88
89
  if (/^\[/.test(cmd)) {
89
90
  parsedCommand.optional.push({
90
91
  cmd: cmd.replace(bregex, '').split('|'),
91
- variadic
92
+ variadic,
92
93
  });
93
94
  }
94
95
  else {
95
96
  parsedCommand.demanded.push({
96
97
  cmd: cmd.replace(bregex, '').split('|'),
97
- variadic
98
+ variadic,
98
99
  });
99
100
  }
100
101
  });
@@ -106,15 +107,19 @@ function argsert(arg1, arg2, arg3) {
106
107
  function parseArgs() {
107
108
  return typeof arg1 === 'object'
108
109
  ? [{ demanded: [], optional: [] }, arg1, arg2]
109
- : [parseCommand(`cmd ${arg1}`), arg2, arg3];
110
+ : [
111
+ parseCommand(`cmd ${arg1}`),
112
+ arg2,
113
+ arg3,
114
+ ];
110
115
  }
111
116
  try {
112
117
  let position = 0;
113
- let [parsed, callerArguments, length] = parseArgs();
118
+ const [parsed, callerArguments, _length] = parseArgs();
114
119
  const args = [].slice.call(callerArguments);
115
120
  while (args.length && args[args.length - 1] === undefined)
116
121
  args.pop();
117
- length = length || args.length;
122
+ const length = _length || args.length;
118
123
  if (length < parsed.demanded.length) {
119
124
  throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`);
120
125
  }
@@ -122,7 +127,7 @@ function argsert(arg1, arg2, arg3) {
122
127
  if (length > totalCommands) {
123
128
  throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`);
124
129
  }
125
- parsed.demanded.forEach((demanded) => {
130
+ parsed.demanded.forEach(demanded => {
126
131
  const arg = args.shift();
127
132
  const observedType = guessType(arg);
128
133
  const matchingTypes = demanded.cmd.filter(type => type === observedType || type === '*');
@@ -130,7 +135,7 @@ function argsert(arg1, arg2, arg3) {
130
135
  argumentTypeError(observedType, demanded.cmd, position);
131
136
  position += 1;
132
137
  });
133
- parsed.optional.forEach((optional) => {
138
+ parsed.optional.forEach(optional => {
134
139
  if (args.length === 0)
135
140
  return;
136
141
  const arg = args.shift();
@@ -159,9 +164,9 @@ function argumentTypeError(observedType, allowedTypes, position) {
159
164
  }
160
165
 
161
166
  function isPromise(maybePromise) {
162
- return !!maybePromise &&
167
+ return (!!maybePromise &&
163
168
  !!maybePromise.then &&
164
- (typeof maybePromise.then === 'function');
169
+ typeof maybePromise.then === 'function');
165
170
  }
166
171
 
167
172
  function assertNotStrictEqual(actual, expected, shim, message) {
@@ -176,7 +181,7 @@ function objectKeys(object) {
176
181
 
177
182
  function objFilter(original = {}, filter = () => true) {
178
183
  const obj = {};
179
- objectKeys(original).forEach((key) => {
184
+ objectKeys(original).forEach(key => {
180
185
  if (filter(key, original[key])) {
181
186
  obj[key] = original[key];
182
187
  }
@@ -213,14 +218,16 @@ function commandMiddlewareFactory(commandMiddleware) {
213
218
  }
214
219
  function applyMiddleware(argv, yargs, middlewares, beforeValidation) {
215
220
  const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true');
216
- return middlewares
217
- .reduce((acc, middleware) => {
221
+ return middlewares.reduce((acc, middleware) => {
218
222
  if (middleware.applyBeforeValidation !== beforeValidation) {
219
223
  return acc;
220
224
  }
221
225
  if (isPromise(acc)) {
222
226
  return acc
223
- .then(initialObj => Promise.all([initialObj, middleware(initialObj, yargs)]))
227
+ .then(initialObj => Promise.all([
228
+ initialObj,
229
+ middleware(initialObj, yargs),
230
+ ]))
224
231
  .then(([initialObj, middlewareObj]) => Object.assign(initialObj, middlewareObj));
225
232
  }
226
233
  else {
@@ -261,7 +268,7 @@ var processArgv = /*#__PURE__*/Object.freeze({
261
268
  function whichModule(exported) {
262
269
  if (typeof require === 'undefined')
263
270
  return null;
264
- for (var i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) {
271
+ for (let i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) {
265
272
  mod = require.cache[files[i]];
266
273
  if (mod.exports === exported)
267
274
  return mod;
@@ -284,7 +291,9 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
284
291
  cmd = cmd[0];
285
292
  }
286
293
  else if (isCommandHandlerDefinition(cmd)) {
287
- let command = (Array.isArray(cmd.command) || typeof cmd.command === 'string') ? cmd.command : moduleName(cmd);
294
+ let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
295
+ ? cmd.command
296
+ : moduleName(cmd);
288
297
  if (cmd.aliases)
289
298
  command = [].concat(command).concat(cmd.aliases);
290
299
  self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
@@ -297,7 +306,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
297
306
  const parsedCommand = parseCommand(cmd);
298
307
  aliases = aliases.map(alias => parseCommand(alias).cmd);
299
308
  let isDefault = false;
300
- const parsedAliases = [parsedCommand.cmd].concat(aliases).filter((c) => {
309
+ const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
301
310
  if (DEFAULT_MARKER.test(c)) {
302
311
  isDefault = true;
303
312
  return false;
@@ -311,7 +320,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
311
320
  aliases = parsedAliases.slice(1);
312
321
  cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
313
322
  }
314
- aliases.forEach((alias) => {
323
+ aliases.forEach(alias => {
315
324
  aliasMap[alias] = parsedCommand.cmd;
316
325
  });
317
326
  if (description !== false) {
@@ -325,7 +334,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
325
334
  middlewares,
326
335
  deprecated,
327
336
  demanded: parsedCommand.demanded,
328
- optional: parsedCommand.optional
337
+ optional: parsedCommand.optional,
329
338
  };
330
339
  if (isDefault)
331
340
  defaultCommand = handlers[parsedCommand.cmd];
@@ -358,7 +367,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
358
367
  function commandFromFilename(filename) {
359
368
  return shim.path.basename(filename, shim.path.extname(filename));
360
369
  }
361
- function extractDesc({ describe, description, desc }) {
370
+ function extractDesc({ describe, description, desc, }) {
362
371
  for (const test of [describe, description, desc]) {
363
372
  if (typeof test === 'string' || test === false)
364
373
  return test;
@@ -386,7 +395,9 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
386
395
  const builderOutput = builder(yargs.reset(parsed.aliases));
387
396
  const innerYargs = isYargsInstance(builderOutput) ? builderOutput : yargs;
388
397
  if (shouldUpdateUsage(innerYargs)) {
389
- innerYargs.getUsageInstance().usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
398
+ innerYargs
399
+ .getUsageInstance()
400
+ .usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
390
401
  }
391
402
  innerArgv = innerYargs._parseArgs(null, null, true, commandIndex);
392
403
  aliases = innerYargs.parsed.aliases;
@@ -394,9 +405,11 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
394
405
  else if (isCommandBuilderOptionDefinitions(builder)) {
395
406
  const innerYargs = yargs.reset(parsed.aliases);
396
407
  if (shouldUpdateUsage(innerYargs)) {
397
- innerYargs.getUsageInstance().usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
408
+ innerYargs
409
+ .getUsageInstance()
410
+ .usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
398
411
  }
399
- Object.keys(commandHandler.builder).forEach((key) => {
412
+ Object.keys(commandHandler.builder).forEach(key => {
400
413
  innerYargs.option(key, builder[key]);
401
414
  });
402
415
  innerArgv = innerYargs._parseArgs(null, null, true, commandIndex);
@@ -405,7 +418,9 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
405
418
  if (!yargs._hasOutput()) {
406
419
  positionalMap = populatePositionals(commandHandler, innerArgv, currentContext);
407
420
  }
408
- const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares);
421
+ const middlewares = globalMiddleware
422
+ .slice(0)
423
+ .concat(commandHandler.middlewares);
409
424
  applyMiddleware(innerArgv, yargs, middlewares, true);
410
425
  if (!yargs._hasOutput()) {
411
426
  yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error, !command);
@@ -413,8 +428,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
413
428
  if (commandHandler.handler && !yargs._hasOutput()) {
414
429
  yargs._setHasOutput();
415
430
  const populateDoubleDash = !!yargs.getOptions().configuration['populate--'];
416
- if (!populateDoubleDash)
417
- yargs._copyDoubleDash(innerArgv);
431
+ yargs._postProcess(innerArgv, populateDoubleDash);
418
432
  innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false);
419
433
  let handlerResult;
420
434
  if (isPromise(innerArgv)) {
@@ -459,12 +473,16 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
459
473
  return innerArgv;
460
474
  };
461
475
  function shouldUpdateUsage(yargs) {
462
- return !yargs.getUsageInstance().getUsageDisabled() &&
463
- yargs.getUsageInstance().getUsage().length === 0;
476
+ return (!yargs.getUsageInstance().getUsageDisabled() &&
477
+ yargs.getUsageInstance().getUsage().length === 0);
464
478
  }
465
479
  function usageFromParentCommandsCommandHandler(parentCommands, commandHandler) {
466
- const c = DEFAULT_MARKER.test(commandHandler.original) ? commandHandler.original.replace(DEFAULT_MARKER, '').trim() : commandHandler.original;
467
- const pc = parentCommands.filter((c) => { return !DEFAULT_MARKER.test(c); });
480
+ const c = DEFAULT_MARKER.test(commandHandler.original)
481
+ ? commandHandler.original.replace(DEFAULT_MARKER, '').trim()
482
+ : commandHandler.original;
483
+ const pc = parentCommands.filter(c => {
484
+ return !DEFAULT_MARKER.test(c);
485
+ });
468
486
  pc.push(c);
469
487
  return `$0 ${pc.join(' ')}`;
470
488
  }
@@ -472,7 +490,8 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
472
490
  assertNotStrictEqual(defaultCommand, undefined, shim);
473
491
  if (shouldUpdateUsage(yargs)) {
474
492
  const commandString = DEFAULT_MARKER.test(defaultCommand.original)
475
- ? defaultCommand.original : defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ');
493
+ ? defaultCommand.original
494
+ : defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ');
476
495
  yargs.getUsageInstance().usage(commandString, defaultCommand.description);
477
496
  }
478
497
  const builder = defaultCommand.builder;
@@ -480,7 +499,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
480
499
  builder(yargs);
481
500
  }
482
501
  else {
483
- Object.keys(builder).forEach((key) => {
502
+ Object.keys(builder).forEach(key => {
484
503
  yargs.option(key, builder[key]);
485
504
  });
486
505
  }
@@ -522,8 +541,8 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
522
541
  options.array = options.array.concat(parseOptions.array);
523
542
  options.config = {};
524
543
  const unparsed = [];
525
- Object.keys(positionalMap).forEach((key) => {
526
- positionalMap[key].map((value) => {
544
+ Object.keys(positionalMap).forEach(key => {
545
+ positionalMap[key].map(value => {
527
546
  if (options.configuration['unknown-options-as-args'])
528
547
  options.key[key] = true;
529
548
  unparsed.push(`--${key}`);
@@ -533,20 +552,20 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
533
552
  if (!unparsed.length)
534
553
  return;
535
554
  const config = Object.assign({}, options.configuration, {
536
- 'populate--': true
555
+ 'populate--': true,
537
556
  });
538
557
  const parsed = shim.Parser.detailed(unparsed, Object.assign({}, options, {
539
- configuration: config
558
+ configuration: config,
540
559
  }));
541
560
  if (parsed.error) {
542
561
  yargs.getUsageInstance().fail(parsed.error.message, parsed.error);
543
562
  }
544
563
  else {
545
564
  const positionalKeys = Object.keys(positionalMap);
546
- Object.keys(positionalMap).forEach((key) => {
565
+ Object.keys(positionalMap).forEach(key => {
547
566
  positionalKeys.push(...parsed.aliases[key]);
548
567
  });
549
- Object.keys(parsed.argv).forEach((key) => {
568
+ Object.keys(parsed.argv).forEach(key => {
550
569
  if (positionalKeys.indexOf(key) !== -1) {
551
570
  if (!positionalMap[key])
552
571
  positionalMap[key] = parsed.argv[key];
@@ -560,10 +579,10 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
560
579
  array: [],
561
580
  default: {},
562
581
  alias: {},
563
- demand: {}
582
+ demand: {},
564
583
  };
565
584
  const parsed = parseCommand(cmdString);
566
- parsed.demanded.forEach((d) => {
585
+ parsed.demanded.forEach(d => {
567
586
  const [cmd, ...aliases] = d.cmd;
568
587
  if (d.variadic) {
569
588
  parseOptions.array.push(cmd);
@@ -572,7 +591,7 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
572
591
  parseOptions.alias[cmd] = aliases;
573
592
  parseOptions.demand[cmd] = true;
574
593
  });
575
- parsed.optional.forEach((o) => {
594
+ parsed.optional.forEach(o => {
576
595
  const [cmd, ...aliases] = o.cmd;
577
596
  if (o.variadic) {
578
597
  parseOptions.array.push(cmd);
@@ -593,17 +612,13 @@ function command(yargs, usage, validation, globalMiddleware = [], shim) {
593
612
  frozens.push({
594
613
  handlers,
595
614
  aliasMap,
596
- defaultCommand
615
+ defaultCommand,
597
616
  });
598
617
  };
599
618
  self.unfreeze = () => {
600
619
  const frozen = frozens.pop();
601
620
  assertNotStrictEqual(frozen, undefined, shim);
602
- ({
603
- handlers,
604
- aliasMap,
605
- defaultCommand
606
- } = frozen);
621
+ ({ handlers, aliasMap, defaultCommand } = frozen);
607
622
  };
608
623
  return self;
609
624
  }
@@ -611,9 +626,9 @@ function isCommandHandlerDefinition(cmd) {
611
626
  return typeof cmd === 'object';
612
627
  }
613
628
  function isCommandBuilderDefinition(builder) {
614
- return typeof builder === 'object' &&
629
+ return (typeof builder === 'object' &&
615
630
  !!builder.builder &&
616
- typeof builder.handler === 'function';
631
+ typeof builder.handler === 'function');
617
632
  }
618
633
  function isCommandBuilderCallback(builder) {
619
634
  return typeof builder === 'function';
@@ -625,9 +640,11 @@ function isCommandBuilderOptionDefinitions(builder) {
625
640
  function setBlocking(blocking) {
626
641
  if (typeof process === 'undefined')
627
642
  return;
628
- [process.stdout, process.stderr].forEach((_stream) => {
643
+ [process.stdout, process.stderr].forEach(_stream => {
629
644
  const stream = _stream;
630
- if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function') {
645
+ if (stream._handle &&
646
+ stream.isTTY &&
647
+ typeof stream._handle.setBlocking === 'function') {
631
648
  stream._handle.setBlocking(blocking);
632
649
  }
633
650
  });
@@ -716,7 +733,7 @@ function usage(yargs, y18n, shim) {
716
733
  let commands = [];
717
734
  self.command = function command(cmd, description, isDefault, aliases, deprecated = false) {
718
735
  if (isDefault) {
719
- commands = commands.map((cmdArray) => {
736
+ commands = commands.map(cmdArray => {
720
737
  cmdArray[2] = false;
721
738
  return cmdArray;
722
739
  });
@@ -727,12 +744,12 @@ function usage(yargs, y18n, shim) {
727
744
  let descriptions = {};
728
745
  self.describe = function describe(keyOrKeys, desc) {
729
746
  if (Array.isArray(keyOrKeys)) {
730
- keyOrKeys.forEach((k) => {
747
+ keyOrKeys.forEach(k => {
731
748
  self.describe(k, desc);
732
749
  });
733
750
  }
734
751
  else if (typeof keyOrKeys === 'object') {
735
- Object.keys(keyOrKeys).forEach((k) => {
752
+ Object.keys(keyOrKeys).forEach(k => {
736
753
  self.describe(k, keyOrKeys[k]);
737
754
  });
738
755
  }
@@ -742,12 +759,12 @@ function usage(yargs, y18n, shim) {
742
759
  };
743
760
  self.getDescriptions = () => descriptions;
744
761
  let epilogs = [];
745
- self.epilog = (msg) => {
762
+ self.epilog = msg => {
746
763
  epilogs.push(msg);
747
764
  };
748
765
  let wrapSet = false;
749
766
  let wrap;
750
- self.wrap = (cols) => {
767
+ self.wrap = cols => {
751
768
  wrapSet = true;
752
769
  wrap = cols;
753
770
  };
@@ -764,7 +781,9 @@ function usage(yargs, y18n, shim) {
764
781
  if (cachedHelpMessage)
765
782
  return cachedHelpMessage;
766
783
  normalizeAliases();
767
- const base$0 = yargs.customScriptName ? yargs.$0 : shim.path.basename(yargs.$0);
784
+ const base$0 = yargs.customScriptName
785
+ ? yargs.$0
786
+ : shim.path.basename(yargs.$0);
768
787
  const demandedOptions = yargs.getDemandedOptions();
769
788
  const demandedCommands = yargs.getDemandedCommands();
770
789
  const deprecatedOptions = yargs.getDeprecatedOptions();
@@ -784,11 +803,11 @@ function usage(yargs, y18n, shim) {
784
803
  const theWrap = getWrap();
785
804
  const ui = shim.cliui({
786
805
  width: theWrap,
787
- wrap: !!theWrap
806
+ wrap: !!theWrap,
788
807
  });
789
808
  if (!usageDisabled) {
790
809
  if (usages.length) {
791
- usages.forEach((usage) => {
810
+ usages.forEach(usage => {
792
811
  ui.div(`${usage[0].replace(/\$0/g, base$0)}`);
793
812
  if (usage[1]) {
794
813
  ui.div({ text: `${usage[1]}`, padding: [1, 0, 0, 0] });
@@ -810,16 +829,18 @@ function usage(yargs, y18n, shim) {
810
829
  if (commands.length) {
811
830
  ui.div(__('Commands:'));
812
831
  const context = yargs.getContext();
813
- const parentCommands = context.commands.length ? `${context.commands.join(' ')} ` : '';
832
+ const parentCommands = context.commands.length
833
+ ? `${context.commands.join(' ')} `
834
+ : '';
814
835
  if (yargs.getParserConfiguration()['sort-commands'] === true) {
815
836
  commands = commands.sort((a, b) => a[0].localeCompare(b[0]));
816
837
  }
817
- commands.forEach((command) => {
838
+ commands.forEach(command => {
818
839
  const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}`;
819
840
  ui.span({
820
841
  text: commandString,
821
842
  padding: [0, 2, 0, 2],
822
- width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4
843
+ width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4,
823
844
  }, { text: command[1] });
824
845
  const hints = [];
825
846
  if (command[2])
@@ -836,7 +857,11 @@ function usage(yargs, y18n, shim) {
836
857
  }
837
858
  }
838
859
  if (hints.length) {
839
- ui.div({ text: hints.join(' '), padding: [0, 0, 0, 2], align: 'right' });
860
+ ui.div({
861
+ text: hints.join(' '),
862
+ padding: [0, 0, 0, 2],
863
+ align: 'right',
864
+ });
840
865
  }
841
866
  else {
842
867
  ui.div();
@@ -844,9 +869,9 @@ function usage(yargs, y18n, shim) {
844
869
  });
845
870
  ui.div();
846
871
  }
847
- const aliasKeys = (Object.keys(options.alias) || [])
848
- .concat(Object.keys(yargs.parsed.newAliases) || []);
849
- keys = keys.filter(key => !yargs.parsed.newAliases[key] && aliasKeys.every(alias => (options.alias[alias] || []).indexOf(key) === -1));
872
+ const aliasKeys = (Object.keys(options.alias) || []).concat(Object.keys(yargs.parsed.newAliases) || []);
873
+ keys = keys.filter(key => !yargs.parsed.newAliases[key] &&
874
+ aliasKeys.every(alias => (options.alias[alias] || []).indexOf(key) === -1));
850
875
  const defaultGroup = __('Options:');
851
876
  if (!groups[defaultGroup])
852
877
  groups[defaultGroup] = [];
@@ -855,7 +880,9 @@ function usage(yargs, y18n, shim) {
855
880
  const displayedGroups = Object.keys(groups)
856
881
  .filter(groupName => groups[groupName].length > 0)
857
882
  .map(groupName => {
858
- const normalizedKeys = groups[groupName].filter(filterHiddenOptions).map((key) => {
883
+ const normalizedKeys = groups[groupName]
884
+ .filter(filterHiddenOptions)
885
+ .map(key => {
859
886
  if (~aliasKeys.indexOf(key))
860
887
  return key;
861
888
  for (let i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
@@ -869,17 +896,26 @@ function usage(yargs, y18n, shim) {
869
896
  .filter(({ normalizedKeys }) => normalizedKeys.length > 0)
870
897
  .map(({ groupName, normalizedKeys }) => {
871
898
  const switches = normalizedKeys.reduce((acc, key) => {
872
- acc[key] = [key].concat(options.alias[key] || [])
899
+ acc[key] = [key]
900
+ .concat(options.alias[key] || [])
873
901
  .map(sw => {
874
902
  if (groupName === self.getPositionalGroupName())
875
903
  return sw;
876
904
  else {
877
- return (/^[0-9]$/.test(sw)
878
- ? ~options.boolean.indexOf(key) ? '-' : '--'
879
- : sw.length > 1 ? '--' : '-') + sw;
905
+ return ((/^[0-9]$/.test(sw)
906
+ ? ~options.boolean.indexOf(key)
907
+ ? '-'
908
+ : '--'
909
+ : sw.length > 1
910
+ ? '--'
911
+ : '-') + sw);
880
912
  }
881
913
  })
882
- .sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2) ? 0 : (isLongSwitch(sw1) ? 1 : -1))
914
+ .sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2)
915
+ ? 0
916
+ : isLongSwitch(sw1)
917
+ ? 1
918
+ : -1)
883
919
  .join(', ');
884
920
  return acc;
885
921
  }, {});
@@ -901,7 +937,7 @@ function usage(yargs, y18n, shim) {
901
937
  }
902
938
  displayedGroups.forEach(({ groupName, normalizedKeys, switches }) => {
903
939
  ui.div(groupName);
904
- normalizedKeys.forEach((key) => {
940
+ normalizedKeys.forEach(key => {
905
941
  const kswitch = switches[key];
906
942
  let desc = descriptions[key] || '';
907
943
  let type = null;
@@ -923,13 +959,23 @@ function usage(yargs, y18n, shim) {
923
959
  ? `[${__('deprecated: %s', deprecated)}]`
924
960
  : `[${__('deprecated')}]`;
925
961
  const extra = [
926
- (key in deprecatedOptions) ? deprecatedExtra(deprecatedOptions[key]) : null,
962
+ key in deprecatedOptions
963
+ ? deprecatedExtra(deprecatedOptions[key])
964
+ : null,
927
965
  type,
928
- (key in demandedOptions) ? `[${__('required')}]` : null,
929
- options.choices && options.choices[key] ? `[${__('choices:')} ${self.stringifiedValues(options.choices[key])}]` : null,
930
- defaultString(options.default[key], options.defaultDescription[key])
931
- ].filter(Boolean).join(' ');
932
- ui.span({ text: getText(kswitch), padding: [0, 2, 0, 2 + getIndentation(kswitch)], width: maxWidth(switches, theWrap) + 4 }, desc);
966
+ key in demandedOptions ? `[${__('required')}]` : null,
967
+ options.choices && options.choices[key]
968
+ ? `[${__('choices:')} ${self.stringifiedValues(options.choices[key])}]`
969
+ : null,
970
+ defaultString(options.default[key], options.defaultDescription[key]),
971
+ ]
972
+ .filter(Boolean)
973
+ .join(' ');
974
+ ui.span({
975
+ text: getText(kswitch),
976
+ padding: [0, 2, 0, 2 + getIndentation(kswitch)],
977
+ width: maxWidth(switches, theWrap) + 4,
978
+ }, desc);
933
979
  if (extra)
934
980
  ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' });
935
981
  else
@@ -939,30 +985,32 @@ function usage(yargs, y18n, shim) {
939
985
  });
940
986
  if (examples.length) {
941
987
  ui.div(__('Examples:'));
942
- examples.forEach((example) => {
988
+ examples.forEach(example => {
943
989
  example[0] = example[0].replace(/\$0/g, base$0);
944
990
  });
945
- examples.forEach((example) => {
991
+ examples.forEach(example => {
946
992
  if (example[1] === '') {
947
993
  ui.div({
948
994
  text: example[0],
949
- padding: [0, 2, 0, 2]
995
+ padding: [0, 2, 0, 2],
950
996
  });
951
997
  }
952
998
  else {
953
999
  ui.div({
954
1000
  text: example[0],
955
1001
  padding: [0, 2, 0, 2],
956
- width: maxWidth(examples, theWrap) + 4
1002
+ width: maxWidth(examples, theWrap) + 4,
957
1003
  }, {
958
- text: example[1]
1004
+ text: example[1],
959
1005
  });
960
1006
  }
961
1007
  });
962
1008
  ui.div();
963
1009
  }
964
1010
  if (epilogs.length > 0) {
965
- const e = epilogs.map(epilog => epilog.replace(/\$0/g, base$0)).join('\n');
1011
+ const e = epilogs
1012
+ .map(epilog => epilog.replace(/\$0/g, base$0))
1013
+ .join('\n');
966
1014
  ui.div(`${e}\n`);
967
1015
  }
968
1016
  return ui.toString().replace(/\s*$/, '');
@@ -972,7 +1020,7 @@ function usage(yargs, y18n, shim) {
972
1020
  if (!Array.isArray(table)) {
973
1021
  table = Object.values(table).map(v => [v]);
974
1022
  }
975
- table.forEach((v) => {
1023
+ table.forEach(v => {
976
1024
  width = Math.max(shim.stringWidth(modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])) + getIndentation(v[0]), width);
977
1025
  });
978
1026
  if (theWrap)
@@ -982,8 +1030,8 @@ function usage(yargs, y18n, shim) {
982
1030
  function normalizeAliases() {
983
1031
  const demandedOptions = yargs.getDemandedOptions();
984
1032
  const options = yargs.getOptions();
985
- (Object.keys(options.alias) || []).forEach((key) => {
986
- options.alias[key].forEach((alias) => {
1033
+ (Object.keys(options.alias) || []).forEach(key => {
1034
+ options.alias[key].forEach(alias => {
987
1035
  if (descriptions[alias])
988
1036
  self.describe(key, descriptions[alias]);
989
1037
  if (alias in demandedOptions)
@@ -1013,10 +1061,10 @@ function usage(yargs, y18n, shim) {
1013
1061
  function addUngroupedKeys(keys, aliases, groups, defaultGroup) {
1014
1062
  let groupedKeys = [];
1015
1063
  let toCheck = null;
1016
- Object.keys(groups).forEach((group) => {
1064
+ Object.keys(groups).forEach(group => {
1017
1065
  groupedKeys = groupedKeys.concat(groups[group]);
1018
1066
  });
1019
- keys.forEach((key) => {
1067
+ keys.forEach(key => {
1020
1068
  toCheck = [key].concat(aliases[key]);
1021
1069
  if (!toCheck.some(k => groupedKeys.indexOf(k) !== -1)) {
1022
1070
  groups[defaultGroup].push(key);
@@ -1025,7 +1073,8 @@ function usage(yargs, y18n, shim) {
1025
1073
  return groupedKeys;
1026
1074
  }
1027
1075
  function filterHiddenOptions(key) {
1028
- return yargs.getOptions().hiddenOptions.indexOf(key) < 0 || yargs.parsed.argv[yargs.getOptions().showHiddenOpt];
1076
+ return (yargs.getOptions().hiddenOptions.indexOf(key) < 0 ||
1077
+ yargs.parsed.argv[yargs.getOptions().showHiddenOpt]);
1029
1078
  }
1030
1079
  self.showHelp = (level) => {
1031
1080
  const logger = yargs._getLoggerInstance();
@@ -1034,8 +1083,10 @@ function usage(yargs, y18n, shim) {
1034
1083
  const emit = typeof level === 'function' ? level : logger[level];
1035
1084
  emit(self.help());
1036
1085
  };
1037
- self.functionDescription = (fn) => {
1038
- const description = fn.name ? shim.Parser.decamelize(fn.name, '-') : __('generated-value');
1086
+ self.functionDescription = fn => {
1087
+ const description = fn.name
1088
+ ? shim.Parser.decamelize(fn.name, '-')
1089
+ : __('generated-value');
1039
1090
  return ['(', description, ')'].join('');
1040
1091
  };
1041
1092
  self.stringifiedValues = function stringifiedValues(values, separator) {
@@ -1044,7 +1095,7 @@ function usage(yargs, y18n, shim) {
1044
1095
  const array = [].concat(values);
1045
1096
  if (!values || !array.length)
1046
1097
  return string;
1047
- array.forEach((value) => {
1098
+ array.forEach(value => {
1048
1099
  if (string.length)
1049
1100
  string += sep;
1050
1101
  string += JSON.stringify(value);
@@ -1082,7 +1133,7 @@ function usage(yargs, y18n, shim) {
1082
1133
  }
1083
1134
  }
1084
1135
  let version = null;
1085
- self.version = (ver) => {
1136
+ self.version = ver => {
1086
1137
  version = ver;
1087
1138
  };
1088
1139
  self.showVersion = () => {
@@ -1110,7 +1161,7 @@ function usage(yargs, y18n, shim) {
1110
1161
  epilogs,
1111
1162
  examples,
1112
1163
  commands,
1113
- descriptions
1164
+ descriptions,
1114
1165
  });
1115
1166
  };
1116
1167
  self.unfreeze = function unfreeze() {
@@ -1124,7 +1175,7 @@ function usage(yargs, y18n, shim) {
1124
1175
  epilogs,
1125
1176
  examples,
1126
1177
  commands,
1127
- descriptions
1178
+ descriptions,
1128
1179
  } = frozen);
1129
1180
  };
1130
1181
  return self;
@@ -1194,7 +1245,7 @@ compdef _{{app_name}}_yargs_completions {{app_name}}
1194
1245
 
1195
1246
  function completion(yargs, usage, command, shim) {
1196
1247
  const self = {
1197
- completionKey: 'get-yargs-completions'
1248
+ completionKey: 'get-yargs-completions',
1198
1249
  };
1199
1250
  let aliases;
1200
1251
  self.setParsed = function setParsed(parsed) {
@@ -1212,22 +1263,30 @@ function completion(yargs, usage, command, shim) {
1212
1263
  if (isSyncCompletionFunction(completionFunction)) {
1213
1264
  const result = completionFunction(current, argv);
1214
1265
  if (isPromise(result)) {
1215
- return result.then((list) => {
1216
- shim.process.nextTick(() => { done(list); });
1217
- }).catch((err) => {
1218
- shim.process.nextTick(() => { throw err; });
1266
+ return result
1267
+ .then(list => {
1268
+ shim.process.nextTick(() => {
1269
+ done(list);
1270
+ });
1271
+ })
1272
+ .catch(err => {
1273
+ shim.process.nextTick(() => {
1274
+ throw err;
1275
+ });
1219
1276
  });
1220
1277
  }
1221
1278
  return done(result);
1222
1279
  }
1223
1280
  else {
1224
- return completionFunction(current, argv, (completions) => {
1281
+ return completionFunction(current, argv, completions => {
1225
1282
  done(completions);
1226
1283
  });
1227
1284
  }
1228
1285
  }
1229
1286
  if (completionFunction) {
1230
- return isPromise(argv) ? argv.then(runCompletionFunction) : runCompletionFunction(argv);
1287
+ return isPromise(argv)
1288
+ ? argv.then(runCompletionFunction)
1289
+ : runCompletionFunction(argv);
1231
1290
  }
1232
1291
  const handlers = command.getCommandHandlers();
1233
1292
  for (let i = 0, ii = args.length; i < ii; ++i) {
@@ -1240,8 +1299,9 @@ function completion(yargs, usage, command, shim) {
1240
1299
  }
1241
1300
  }
1242
1301
  }
1243
- if (!current.match(/^-/) && parentCommands[parentCommands.length - 1] !== current) {
1244
- usage.getCommands().forEach((usageCommand) => {
1302
+ if (!current.match(/^-/) &&
1303
+ parentCommands[parentCommands.length - 1] !== current) {
1304
+ usage.getCommands().forEach(usageCommand => {
1245
1305
  const commandName = parseCommand(usageCommand[0]).cmd;
1246
1306
  if (args.indexOf(commandName) === -1) {
1247
1307
  if (!zshShell) {
@@ -1257,8 +1317,9 @@ function completion(yargs, usage, command, shim) {
1257
1317
  if (current.match(/^-/) || (current === '' && completions.length === 0)) {
1258
1318
  const descs = usage.getDescriptions();
1259
1319
  const options = yargs.getOptions();
1260
- Object.keys(options.key).forEach((key) => {
1261
- const negable = !!options.configuration['boolean-negation'] && options.boolean.includes(key);
1320
+ Object.keys(options.key).forEach(key => {
1321
+ const negable = !!options.configuration['boolean-negation'] &&
1322
+ options.boolean.includes(key);
1262
1323
  let keyAndAliases = [key].concat(aliases[key] || []);
1263
1324
  if (negable)
1264
1325
  keyAndAliases = keyAndAliases.concat(keyAndAliases.map(key => `no-${key}`));
@@ -1273,7 +1334,8 @@ function completion(yargs, usage, command, shim) {
1273
1334
  }
1274
1335
  else {
1275
1336
  const desc = descs[key] || '';
1276
- completions.push(dashes + `${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`);
1337
+ completions.push(dashes +
1338
+ `${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`);
1277
1339
  }
1278
1340
  }
1279
1341
  }
@@ -1285,7 +1347,9 @@ function completion(yargs, usage, command, shim) {
1285
1347
  done(completions);
1286
1348
  };
1287
1349
  self.generateCompletionScript = function generateCompletionScript($0, cmd) {
1288
- let script = zshShell ? completionZshTemplate : completionShTemplate;
1350
+ let script = zshShell
1351
+ ? completionZshTemplate
1352
+ : completionShTemplate;
1289
1353
  const name = shim.path.basename($0);
1290
1354
  if ($0.match(/\.js$/))
1291
1355
  $0 = `./${$0}`;
@@ -1294,7 +1358,7 @@ function completion(yargs, usage, command, shim) {
1294
1358
  return script.replace(/{{app_path}}/g, $0);
1295
1359
  };
1296
1360
  let completionFunction = null;
1297
- self.registerFunction = (fn) => {
1361
+ self.registerFunction = fn => {
1298
1362
  completionFunction = fn;
1299
1363
  };
1300
1364
  return self;
@@ -1337,12 +1401,16 @@ function validation(yargs, usage, y18n, shim) {
1337
1401
  const self = {};
1338
1402
  self.nonOptionCount = function nonOptionCount(argv) {
1339
1403
  const demandedCommands = yargs.getDemandedCommands();
1340
- const _s = argv._.length - yargs.getContext().commands.length;
1341
- if (demandedCommands._ && (_s < demandedCommands._.min || _s > demandedCommands._.max)) {
1404
+ const positionalCount = argv._.length + (argv['--'] ? argv['--'].length : 0);
1405
+ const _s = positionalCount - yargs.getContext().commands.length;
1406
+ if (demandedCommands._ &&
1407
+ (_s < demandedCommands._.min || _s > demandedCommands._.max)) {
1342
1408
  if (_s < demandedCommands._.min) {
1343
1409
  if (demandedCommands._.minMsg !== undefined) {
1344
1410
  usage.fail(demandedCommands._.minMsg
1345
- ? demandedCommands._.minMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.min.toString())
1411
+ ? demandedCommands._.minMsg
1412
+ .replace(/\$0/g, _s.toString())
1413
+ .replace(/\$1/, demandedCommands._.min.toString())
1346
1414
  : null);
1347
1415
  }
1348
1416
  else {
@@ -1352,7 +1420,9 @@ function validation(yargs, usage, y18n, shim) {
1352
1420
  else if (_s > demandedCommands._.max) {
1353
1421
  if (demandedCommands._.maxMsg !== undefined) {
1354
1422
  usage.fail(demandedCommands._.maxMsg
1355
- ? demandedCommands._.maxMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.max.toString())
1423
+ ? demandedCommands._.maxMsg
1424
+ .replace(/\$0/g, _s.toString())
1425
+ .replace(/\$1/, demandedCommands._.max.toString())
1356
1426
  : null);
1357
1427
  }
1358
1428
  else {
@@ -1370,7 +1440,8 @@ function validation(yargs, usage, y18n, shim) {
1370
1440
  const demandedOptions = yargs.getDemandedOptions();
1371
1441
  let missing = null;
1372
1442
  for (const key of Object.keys(demandedOptions)) {
1373
- if (!Object.prototype.hasOwnProperty.call(argv, key) || typeof argv[key] === 'undefined') {
1443
+ if (!Object.prototype.hasOwnProperty.call(argv, key) ||
1444
+ typeof argv[key] === 'undefined') {
1374
1445
  missing = missing || {};
1375
1446
  missing[key] = demandedOptions[key];
1376
1447
  }
@@ -1391,7 +1462,7 @@ function validation(yargs, usage, y18n, shim) {
1391
1462
  const commandKeys = yargs.getCommandInstance().getCommands();
1392
1463
  const unknown = [];
1393
1464
  const currentContext = yargs.getContext();
1394
- Object.keys(argv).forEach((key) => {
1465
+ Object.keys(argv).forEach(key => {
1395
1466
  if (specialKeys.indexOf(key) === -1 &&
1396
1467
  !Object.prototype.hasOwnProperty.call(positionalMap, key) &&
1397
1468
  !Object.prototype.hasOwnProperty.call(yargs._getParseContext(), key) &&
@@ -1399,8 +1470,11 @@ function validation(yargs, usage, y18n, shim) {
1399
1470
  unknown.push(key);
1400
1471
  }
1401
1472
  });
1402
- if (checkPositionals && ((currentContext.commands.length > 0) || (commandKeys.length > 0) || isDefaultCommand)) {
1403
- argv._.slice(currentContext.commands.length).forEach((key) => {
1473
+ if (checkPositionals &&
1474
+ (currentContext.commands.length > 0 ||
1475
+ commandKeys.length > 0 ||
1476
+ isDefaultCommand)) {
1477
+ argv._.slice(currentContext.commands.length).forEach(key => {
1404
1478
  if (commandKeys.indexOf('' + key) === -1) {
1405
1479
  unknown.push('' + key);
1406
1480
  }
@@ -1414,8 +1488,8 @@ function validation(yargs, usage, y18n, shim) {
1414
1488
  const commandKeys = yargs.getCommandInstance().getCommands();
1415
1489
  const unknown = [];
1416
1490
  const currentContext = yargs.getContext();
1417
- if ((currentContext.commands.length > 0) || (commandKeys.length > 0)) {
1418
- argv._.slice(currentContext.commands.length).forEach((key) => {
1491
+ if (currentContext.commands.length > 0 || commandKeys.length > 0) {
1492
+ argv._.slice(currentContext.commands.length).forEach(key => {
1419
1493
  if (commandKeys.indexOf('' + key) === -1) {
1420
1494
  unknown.push('' + key);
1421
1495
  }
@@ -1435,7 +1509,8 @@ function validation(yargs, usage, y18n, shim) {
1435
1509
  }
1436
1510
  const newAliases = yargs.parsed.newAliases;
1437
1511
  for (const a of [key, ...aliases[key]]) {
1438
- if (!Object.prototype.hasOwnProperty.call(newAliases, a) || !newAliases[key]) {
1512
+ if (!Object.prototype.hasOwnProperty.call(newAliases, a) ||
1513
+ !newAliases[key]) {
1439
1514
  return true;
1440
1515
  }
1441
1516
  }
@@ -1446,10 +1521,10 @@ function validation(yargs, usage, y18n, shim) {
1446
1521
  const invalid = {};
1447
1522
  if (!Object.keys(options.choices).length)
1448
1523
  return;
1449
- Object.keys(argv).forEach((key) => {
1524
+ Object.keys(argv).forEach(key => {
1450
1525
  if (specialKeys.indexOf(key) === -1 &&
1451
1526
  Object.prototype.hasOwnProperty.call(options.choices, key)) {
1452
- [].concat(argv[key]).forEach((value) => {
1527
+ [].concat(argv[key]).forEach(value => {
1453
1528
  if (options.choices[key].indexOf(value) === -1 &&
1454
1529
  value !== undefined) {
1455
1530
  invalid[key] = (invalid[key] || []).concat(value);
@@ -1461,7 +1536,7 @@ function validation(yargs, usage, y18n, shim) {
1461
1536
  if (!invalidKeys.length)
1462
1537
  return;
1463
1538
  let msg = __('Invalid values:');
1464
- invalidKeys.forEach((key) => {
1539
+ invalidKeys.forEach(key => {
1465
1540
  msg += `\n ${__('Argument: %s, Given: %s, Choices: %s', key, usage.stringifiedValues(invalid[key]), usage.stringifiedValues(options.choices[key]))}`;
1466
1541
  });
1467
1542
  usage.fail(msg);
@@ -1470,7 +1545,7 @@ function validation(yargs, usage, y18n, shim) {
1470
1545
  self.check = function check(f, global) {
1471
1546
  checks.push({
1472
1547
  func: f,
1473
- global
1548
+ global,
1474
1549
  });
1475
1550
  };
1476
1551
  self.customChecks = function customChecks(argv, aliases) {
@@ -1496,7 +1571,7 @@ function validation(yargs, usage, y18n, shim) {
1496
1571
  self.implies = function implies(key, value) {
1497
1572
  argsert('<string|object> [array|number|string]', [key, value], arguments.length);
1498
1573
  if (typeof key === 'object') {
1499
- Object.keys(key).forEach((k) => {
1574
+ Object.keys(key).forEach(k => {
1500
1575
  self.implies(k, key[k]);
1501
1576
  });
1502
1577
  }
@@ -1506,7 +1581,7 @@ function validation(yargs, usage, y18n, shim) {
1506
1581
  implied[key] = [];
1507
1582
  }
1508
1583
  if (Array.isArray(value)) {
1509
- value.forEach((i) => self.implies(key, i));
1584
+ value.forEach(i => self.implies(key, i));
1510
1585
  }
1511
1586
  else {
1512
1587
  assertNotStrictEqual(value, undefined, shim);
@@ -1534,9 +1609,9 @@ function validation(yargs, usage, y18n, shim) {
1534
1609
  }
1535
1610
  self.implications = function implications(argv) {
1536
1611
  const implyFail = [];
1537
- Object.keys(implied).forEach((key) => {
1612
+ Object.keys(implied).forEach(key => {
1538
1613
  const origKey = key;
1539
- (implied[key] || []).forEach((value) => {
1614
+ (implied[key] || []).forEach(value => {
1540
1615
  let key = origKey;
1541
1616
  const origValue = value;
1542
1617
  key = keyExists(argv, key);
@@ -1548,8 +1623,8 @@ function validation(yargs, usage, y18n, shim) {
1548
1623
  });
1549
1624
  if (implyFail.length) {
1550
1625
  let msg = `${__('Implications failed:')}\n`;
1551
- implyFail.forEach((value) => {
1552
- msg += (value);
1626
+ implyFail.forEach(value => {
1627
+ msg += value;
1553
1628
  });
1554
1629
  usage.fail(msg);
1555
1630
  }
@@ -1558,7 +1633,7 @@ function validation(yargs, usage, y18n, shim) {
1558
1633
  self.conflicts = function conflicts(key, value) {
1559
1634
  argsert('<string|object> [array|string]', [key, value], arguments.length);
1560
1635
  if (typeof key === 'object') {
1561
- Object.keys(key).forEach((k) => {
1636
+ Object.keys(key).forEach(k => {
1562
1637
  self.conflicts(k, key[k]);
1563
1638
  });
1564
1639
  }
@@ -1568,7 +1643,7 @@ function validation(yargs, usage, y18n, shim) {
1568
1643
  conflicting[key] = [];
1569
1644
  }
1570
1645
  if (Array.isArray(value)) {
1571
- value.forEach((i) => self.conflicts(key, i));
1646
+ value.forEach(i => self.conflicts(key, i));
1572
1647
  }
1573
1648
  else {
1574
1649
  conflicting[key].push(value);
@@ -1577,9 +1652,9 @@ function validation(yargs, usage, y18n, shim) {
1577
1652
  };
1578
1653
  self.getConflicting = () => conflicting;
1579
1654
  self.conflicting = function conflictingFn(argv) {
1580
- Object.keys(argv).forEach((key) => {
1655
+ Object.keys(argv).forEach(key => {
1581
1656
  if (conflicting[key]) {
1582
- conflicting[key].forEach((value) => {
1657
+ conflicting[key].forEach(value => {
1583
1658
  if (value && argv[key] !== undefined && argv[value] !== undefined) {
1584
1659
  usage.fail(__('Arguments %s and %s are mutually exclusive', key, value));
1585
1660
  }
@@ -1613,17 +1688,13 @@ function validation(yargs, usage, y18n, shim) {
1613
1688
  frozens.push({
1614
1689
  implied,
1615
1690
  checks,
1616
- conflicting
1691
+ conflicting,
1617
1692
  });
1618
1693
  };
1619
1694
  self.unfreeze = function unfreeze() {
1620
1695
  const frozen = frozens.pop();
1621
1696
  assertNotStrictEqual(frozen, undefined, shim);
1622
- ({
1623
- implied,
1624
- checks,
1625
- conflicting
1626
- } = frozen);
1697
+ ({ implied, checks, conflicting } = frozen);
1627
1698
  };
1628
1699
  return self;
1629
1700
  }
@@ -1663,23 +1734,52 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1663
1734
  const b = rebase(cwd, x);
1664
1735
  return x.match(/^(\/|([a-zA-Z]:)?\\)/) && b.length < x.length ? b : x;
1665
1736
  })
1666
- .join(' ').trim();
1737
+ .join(' ')
1738
+ .trim();
1667
1739
  if (shim$1.getEnv('_') && shim$1.getProcessArgvBin() === shim$1.getEnv('_')) {
1668
- self.$0 = shim$1.getEnv('_').replace(`${shim$1.path.dirname(shim$1.process.execPath())}/`, '');
1740
+ self.$0 = shim$1
1741
+ .getEnv('_')
1742
+ .replace(`${shim$1.path.dirname(shim$1.process.execPath())}/`, '');
1669
1743
  }
1670
1744
  const context = { resets: -1, commands: [], fullCommands: [], files: [] };
1671
1745
  self.getContext = () => context;
1746
+ let hasOutput = false;
1747
+ let exitError = null;
1748
+ self.exit = (code, err) => {
1749
+ hasOutput = true;
1750
+ exitError = err;
1751
+ if (exitProcess)
1752
+ shim$1.process.exit(code);
1753
+ };
1754
+ let completionCommand = null;
1755
+ self.completion = function (cmd, desc, fn) {
1756
+ argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
1757
+ if (typeof desc === 'function') {
1758
+ fn = desc;
1759
+ desc = undefined;
1760
+ }
1761
+ completionCommand = cmd || completionCommand || 'completion';
1762
+ if (!desc && desc !== false) {
1763
+ desc = 'generate completion script';
1764
+ }
1765
+ self.command(completionCommand, desc);
1766
+ if (fn)
1767
+ completion$1.registerFunction(fn);
1768
+ return self;
1769
+ };
1672
1770
  let options;
1673
1771
  self.resetOptions = self.reset = function resetOptions(aliases = {}) {
1674
1772
  context.resets++;
1675
1773
  options = options || {};
1676
1774
  const tmpOptions = {};
1677
1775
  tmpOptions.local = options.local ? options.local : [];
1678
- tmpOptions.configObjects = options.configObjects ? options.configObjects : [];
1776
+ tmpOptions.configObjects = options.configObjects
1777
+ ? options.configObjects
1778
+ : [];
1679
1779
  const localLookup = {};
1680
- tmpOptions.local.forEach((l) => {
1780
+ tmpOptions.local.forEach(l => {
1681
1781
  localLookup[l] = true;
1682
- (aliases[l] || []).forEach((a) => {
1782
+ (aliases[l] || []).forEach(a => {
1683
1783
  localLookup[a] = true;
1684
1784
  });
1685
1785
  });
@@ -1692,14 +1792,27 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1692
1792
  }, {}));
1693
1793
  groups = {};
1694
1794
  const arrayOptions = [
1695
- 'array', 'boolean', 'string', 'skipValidation',
1696
- 'count', 'normalize', 'number',
1697
- 'hiddenOptions'
1795
+ 'array',
1796
+ 'boolean',
1797
+ 'string',
1798
+ 'skipValidation',
1799
+ 'count',
1800
+ 'normalize',
1801
+ 'number',
1802
+ 'hiddenOptions',
1698
1803
  ];
1699
1804
  const objectOptions = [
1700
- 'narg', 'key', 'alias', 'default', 'defaultDescription',
1701
- 'config', 'choices', 'demandedOptions', 'demandedCommands', 'coerce',
1702
- 'deprecatedOptions'
1805
+ 'narg',
1806
+ 'key',
1807
+ 'alias',
1808
+ 'default',
1809
+ 'defaultDescription',
1810
+ 'config',
1811
+ 'choices',
1812
+ 'demandedOptions',
1813
+ 'demandedCommands',
1814
+ 'coerce',
1815
+ 'deprecatedOptions',
1703
1816
  ];
1704
1817
  arrayOptions.forEach(k => {
1705
1818
  tmpOptions[k] = (options[k] || []).filter((k) => !localLookup[k]);
@@ -1710,8 +1823,12 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1710
1823
  tmpOptions.envPrefix = options.envPrefix;
1711
1824
  options = tmpOptions;
1712
1825
  usage$1 = usage$1 ? usage$1.reset(localLookup) : usage(self, y18n, shim$1);
1713
- validation$1 = validation$1 ? validation$1.reset(localLookup) : validation(self, usage$1, y18n, shim$1);
1714
- command$1 = command$1 ? command$1.reset() : command(self, usage$1, validation$1, globalMiddleware, shim$1);
1826
+ validation$1 = validation$1
1827
+ ? validation$1.reset(localLookup)
1828
+ : validation(self, usage$1, y18n, shim$1);
1829
+ command$1 = command$1
1830
+ ? command$1.reset()
1831
+ : command(self, usage$1, validation$1, globalMiddleware, shim$1);
1715
1832
  if (!completion$1)
1716
1833
  completion$1 = completion(self, usage$1, command$1, shim$1);
1717
1834
  completionCommand = null;
@@ -1739,7 +1856,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1739
1856
  parsed: self.parsed,
1740
1857
  parseFn,
1741
1858
  parseContext,
1742
- handlerFinishCommand
1859
+ handlerFinishCommand,
1743
1860
  });
1744
1861
  usage$1.freeze();
1745
1862
  validation$1.freeze();
@@ -1764,7 +1881,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1764
1881
  completionCommand,
1765
1882
  parseFn,
1766
1883
  parseContext,
1767
- handlerFinishCommand
1884
+ handlerFinishCommand,
1768
1885
  } = frozen);
1769
1886
  options.configObjects = configObjects;
1770
1887
  usage$1.unfreeze();
@@ -1818,7 +1935,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1818
1935
  };
1819
1936
  function populateParserHintArray(type, keys) {
1820
1937
  keys = [].concat(keys);
1821
- keys.forEach((key) => {
1938
+ keys.forEach(key => {
1822
1939
  key = sanitizeKey(key);
1823
1940
  options[type].push(key);
1824
1941
  });
@@ -1886,7 +2003,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1886
2003
  }
1887
2004
  function populateParserHintDictionary(builder, type, key, value, singleKeyHandler) {
1888
2005
  if (Array.isArray(key)) {
1889
- key.forEach((k) => {
2006
+ key.forEach(k => {
1890
2007
  builder(k, value);
1891
2008
  });
1892
2009
  }
@@ -1921,7 +2038,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1921
2038
  }
1922
2039
  self.config = function config(key = 'config', msg, parseFn) {
1923
2040
  argsert('[object|string] [string|function] [function]', [key, msg, parseFn], arguments.length);
1924
- if ((typeof key === 'object') && !Array.isArray(key)) {
2041
+ if (typeof key === 'object' && !Array.isArray(key)) {
1925
2042
  key = applyExtends(key, cwd, self.getParserConfiguration()['deep-merge-config'] || false, shim$1);
1926
2043
  options.configObjects = (options.configObjects || []).concat(key);
1927
2044
  return self;
@@ -1931,7 +2048,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1931
2048
  msg = undefined;
1932
2049
  }
1933
2050
  self.describe(key, msg || usage$1.deferY18nLookup('Path to JSON config file'));
1934
- (Array.isArray(key) ? key : [key]).forEach((k) => {
2051
+ (Array.isArray(key) ? key : [key]).forEach(k => {
1935
2052
  options.config[k] = parseFn || true;
1936
2053
  });
1937
2054
  return self;
@@ -1939,7 +2056,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1939
2056
  self.example = function (cmd, description) {
1940
2057
  argsert('<string|array> [string]', [cmd, description], arguments.length);
1941
2058
  if (Array.isArray(cmd)) {
1942
- cmd.forEach((exampleParams) => self.example(...exampleParams));
2059
+ cmd.forEach(exampleParams => self.example(...exampleParams));
1943
2060
  }
1944
2061
  else {
1945
2062
  usage$1.example(cmd, description);
@@ -1959,7 +2076,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1959
2076
  };
1960
2077
  self.demand = self.required = self.require = function demand(keys, max, msg) {
1961
2078
  if (Array.isArray(max)) {
1962
- max.forEach((key) => {
2079
+ max.forEach(key => {
1963
2080
  assertNotStrictEqual(msg, true, shim$1);
1964
2081
  demandOption(key, msg);
1965
2082
  });
@@ -1974,7 +2091,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
1974
2091
  self.demandCommand(keys, max, msg, msg);
1975
2092
  }
1976
2093
  else if (Array.isArray(keys)) {
1977
- keys.forEach((key) => {
2094
+ keys.forEach(key => {
1978
2095
  assertNotStrictEqual(msg, true, shim$1);
1979
2096
  demandOption(key, msg);
1980
2097
  });
@@ -2000,7 +2117,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2000
2117
  min,
2001
2118
  max,
2002
2119
  minMsg,
2003
- maxMsg
2120
+ maxMsg,
2004
2121
  };
2005
2122
  return self;
2006
2123
  };
@@ -2075,7 +2192,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2075
2192
  options.local = options.local.filter(l => globals.indexOf(l) === -1);
2076
2193
  }
2077
2194
  else {
2078
- globals.forEach((g) => {
2195
+ globals.forEach(g => {
2079
2196
  if (options.local.indexOf(g) === -1)
2080
2197
  options.local.push(g);
2081
2198
  });
@@ -2114,7 +2231,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2114
2231
  assertNotStrictEqual(pkgJsonPath, undefined, shim$1);
2115
2232
  obj = JSON.parse(shim$1.readFileSync(pkgJsonPath, 'utf8'));
2116
2233
  }
2117
- catch (noop) { }
2234
+ catch (_noop) { }
2118
2235
  pkgs[npath] = obj || {};
2119
2236
  return pkgs[npath];
2120
2237
  }
@@ -2154,7 +2271,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2154
2271
  self.option = self.options = function option(key, opt) {
2155
2272
  argsert('<string|object> [object]', [key, opt], arguments.length);
2156
2273
  if (typeof key === 'object') {
2157
- Object.keys(key).forEach((k) => {
2274
+ Object.keys(key).forEach(k => {
2158
2275
  self.options(k, key[k]);
2159
2276
  });
2160
2277
  }
@@ -2252,9 +2369,20 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2252
2369
  if (context.resets === 0) {
2253
2370
  throw new YError(".positional() can only be called in a command's builder function");
2254
2371
  }
2255
- const supportedOpts = ['default', 'defaultDescription', 'implies', 'normalize',
2256
- 'choices', 'conflicts', 'coerce', 'type', 'describe',
2257
- 'desc', 'description', 'alias'];
2372
+ const supportedOpts = [
2373
+ 'default',
2374
+ 'defaultDescription',
2375
+ 'implies',
2376
+ 'normalize',
2377
+ 'choices',
2378
+ 'conflicts',
2379
+ 'coerce',
2380
+ 'type',
2381
+ 'describe',
2382
+ 'desc',
2383
+ 'description',
2384
+ 'alias',
2385
+ ];
2258
2386
  opts = objFilter(opts, (k, v) => {
2259
2387
  let accept = supportedOpts.indexOf(k) !== -1;
2260
2388
  if (k === 'type' && ['string', 'number', 'boolean'].indexOf(v) === -1)
@@ -2262,13 +2390,15 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2262
2390
  return accept;
2263
2391
  });
2264
2392
  const fullCommand = context.fullCommands[context.fullCommands.length - 1];
2265
- const parseOptions = fullCommand ? command$1.cmdToParseOptions(fullCommand) : {
2266
- array: [],
2267
- alias: {},
2268
- default: {},
2269
- demand: {}
2270
- };
2271
- objectKeys(parseOptions).forEach((pk) => {
2393
+ const parseOptions = fullCommand
2394
+ ? command$1.cmdToParseOptions(fullCommand)
2395
+ : {
2396
+ array: [],
2397
+ alias: {},
2398
+ default: {},
2399
+ demand: {},
2400
+ };
2401
+ objectKeys(parseOptions).forEach(pk => {
2272
2402
  const parseOption = parseOptions[pk];
2273
2403
  if (Array.isArray(parseOption)) {
2274
2404
  if (parseOption.indexOf(key) !== -1)
@@ -2289,7 +2419,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2289
2419
  delete preservedGroups[groupName];
2290
2420
  }
2291
2421
  const seen = {};
2292
- groups[groupName] = (existing || []).concat(opts).filter((key) => {
2422
+ groups[groupName] = (existing || []).concat(opts).filter(key => {
2293
2423
  if (seen[key])
2294
2424
  return false;
2295
2425
  return (seen[key] = true);
@@ -2425,29 +2555,13 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2425
2555
  usage$1.showHelpOnFail(enabled, message);
2426
2556
  return self;
2427
2557
  };
2428
- var exitProcess = true;
2558
+ let exitProcess = true;
2429
2559
  self.exitProcess = function (enabled = true) {
2430
2560
  argsert('[boolean]', [enabled], arguments.length);
2431
2561
  exitProcess = enabled;
2432
2562
  return self;
2433
2563
  };
2434
2564
  self.getExitProcess = () => exitProcess;
2435
- var completionCommand = null;
2436
- self.completion = function (cmd, desc, fn) {
2437
- argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
2438
- if (typeof desc === 'function') {
2439
- fn = desc;
2440
- desc = undefined;
2441
- }
2442
- completionCommand = cmd || completionCommand || 'completion';
2443
- if (!desc && desc !== false) {
2444
- desc = 'generate completion script';
2445
- }
2446
- self.command(completionCommand, desc);
2447
- if (fn)
2448
- completion$1.registerFunction(fn);
2449
- return self;
2450
- };
2451
2565
  self.showCompletionScript = function ($0, cmd) {
2452
2566
  argsert('[string] [string]', [$0, cmd], arguments.length);
2453
2567
  $0 = $0 || self.$0;
@@ -2481,14 +2595,6 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2481
2595
  return self;
2482
2596
  };
2483
2597
  self.getDetectLocale = () => detectLocale;
2484
- var hasOutput = false;
2485
- var exitError = null;
2486
- self.exit = (code, err) => {
2487
- hasOutput = true;
2488
- exitError = err;
2489
- if (exitProcess)
2490
- shim$1.process.exit(code);
2491
- };
2492
2598
  const _logger = {
2493
2599
  log(...args) {
2494
2600
  if (!self._hasParseCallback())
@@ -2505,7 +2611,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2505
2611
  if (output.length)
2506
2612
  output += '\n';
2507
2613
  output += args.join(' ');
2508
- }
2614
+ },
2509
2615
  };
2510
2616
  self._getLoggerInstance = () => _logger;
2511
2617
  self._hasOutput = () => hasOutput;
@@ -2527,7 +2633,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2527
2633
  };
2528
2634
  Object.defineProperty(self, 'argv', {
2529
2635
  get: () => self._parseArgs(processArgs),
2530
- enumerable: true
2636
+ enumerable: true,
2531
2637
  });
2532
2638
  self._parseArgs = function parseArgs(args, shortCircuit, _calledFromCommand, commandIndex) {
2533
2639
  let skipValidation = !!_calledFromCommand;
@@ -2536,10 +2642,10 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2536
2642
  options.configuration = self.getParserConfiguration();
2537
2643
  const populateDoubleDash = !!options.configuration['populate--'];
2538
2644
  const config = Object.assign({}, options.configuration, {
2539
- 'populate--': true
2645
+ 'populate--': true,
2540
2646
  });
2541
2647
  const parsed = shim$1.Parser.detailed(args, Object.assign({}, options, {
2542
- configuration: config
2648
+ configuration: Object.assign({ 'parse-positional-numbers': false }, config),
2543
2649
  }));
2544
2650
  let argv = parsed.argv;
2545
2651
  if (parseContext)
@@ -2550,7 +2656,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2550
2656
  try {
2551
2657
  guessLocale();
2552
2658
  if (shortCircuit) {
2553
- return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv);
2659
+ return self._postProcess(argv, populateDoubleDash, _calledFromCommand);
2554
2660
  }
2555
2661
  if (helpOpt) {
2556
2662
  const helpCmds = [helpOpt]
@@ -2564,15 +2670,16 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2564
2670
  const handlerKeys = command$1.getCommands();
2565
2671
  const requestCompletions = completion$1.completionKey in argv;
2566
2672
  const skipRecommendation = argv[helpOpt] || requestCompletions;
2567
- const skipDefaultCommand = skipRecommendation && (handlerKeys.length > 1 || handlerKeys[0] !== '$0');
2673
+ const skipDefaultCommand = skipRecommendation &&
2674
+ (handlerKeys.length > 1 || handlerKeys[0] !== '$0');
2568
2675
  if (argv._.length) {
2569
2676
  if (handlerKeys.length) {
2570
2677
  let firstUnknownCommand;
2571
- for (let i = (commandIndex || 0), cmd; argv._[i] !== undefined; i++) {
2678
+ for (let i = commandIndex || 0, cmd; argv._[i] !== undefined; i++) {
2572
2679
  cmd = String(argv._[i]);
2573
2680
  if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) {
2574
2681
  const innerArgv = command$1.runCommand(cmd, self, parsed, i + 1);
2575
- return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv);
2682
+ return self._postProcess(innerArgv, populateDoubleDash);
2576
2683
  }
2577
2684
  else if (!firstUnknownCommand && cmd !== completionCommand) {
2578
2685
  firstUnknownCommand = cmd;
@@ -2581,13 +2688,15 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2581
2688
  }
2582
2689
  if (command$1.hasDefaultCommand() && !skipDefaultCommand) {
2583
2690
  const innerArgv = command$1.runCommand(null, self, parsed);
2584
- return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv);
2691
+ return self._postProcess(innerArgv, populateDoubleDash);
2585
2692
  }
2586
2693
  if (recommendCommands && firstUnknownCommand && !skipRecommendation) {
2587
2694
  validation$1.recommendCommands(firstUnknownCommand, handlerKeys);
2588
2695
  }
2589
2696
  }
2590
- if (completionCommand && ~argv._.indexOf(completionCommand) && !requestCompletions) {
2697
+ if (completionCommand &&
2698
+ ~argv._.indexOf(completionCommand) &&
2699
+ !requestCompletions) {
2591
2700
  if (exitProcess)
2592
2701
  setBlocking(true);
2593
2702
  self.showCompletionScript();
@@ -2596,24 +2705,23 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2596
2705
  }
2597
2706
  else if (command$1.hasDefaultCommand() && !skipDefaultCommand) {
2598
2707
  const innerArgv = command$1.runCommand(null, self, parsed);
2599
- return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv);
2708
+ return self._postProcess(innerArgv, populateDoubleDash);
2600
2709
  }
2601
2710
  if (requestCompletions) {
2602
2711
  if (exitProcess)
2603
2712
  setBlocking(true);
2604
2713
  args = [].concat(args);
2605
2714
  const completionArgs = args.slice(args.indexOf(`--${completion$1.completionKey}`) + 1);
2606
- completion$1.getCompletion(completionArgs, (completions) => {
2607
- ;
2608
- (completions || []).forEach((completion) => {
2715
+ completion$1.getCompletion(completionArgs, completions => {
2716
+ (completions || []).forEach(completion => {
2609
2717
  _logger.log(completion);
2610
2718
  });
2611
2719
  self.exit(0);
2612
2720
  });
2613
- return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv);
2721
+ return self._postProcess(argv, !populateDoubleDash, _calledFromCommand);
2614
2722
  }
2615
2723
  if (!hasOutput) {
2616
- Object.keys(argv).forEach((key) => {
2724
+ Object.keys(argv).forEach(key => {
2617
2725
  if (key === helpOpt && argv[key]) {
2618
2726
  if (exitProcess)
2619
2727
  setBlocking(true);
@@ -2647,10 +2755,25 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2647
2755
  else
2648
2756
  throw err;
2649
2757
  }
2650
- return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv);
2758
+ return self._postProcess(argv, populateDoubleDash, _calledFromCommand);
2759
+ };
2760
+ self._postProcess = function (argv, populateDoubleDash, calledFromCommand = false) {
2761
+ if (isPromise(argv))
2762
+ return argv;
2763
+ if (calledFromCommand)
2764
+ return argv;
2765
+ if (!populateDoubleDash) {
2766
+ argv = self._copyDoubleDash(argv);
2767
+ }
2768
+ const parsePositionalNumbers = self.getParserConfiguration()['parse-positional-numbers'] ||
2769
+ self.getParserConfiguration()['parse-positional-numbers'] === undefined;
2770
+ if (parsePositionalNumbers) {
2771
+ argv = self._parsePositionalNumbers(argv);
2772
+ }
2773
+ return argv;
2651
2774
  };
2652
2775
  self._copyDoubleDash = function (argv) {
2653
- if (isPromise(argv) || !argv._ || !argv['--'])
2776
+ if (!argv._ || !argv['--'])
2654
2777
  return argv;
2655
2778
  argv._.push.apply(argv._, argv['--']);
2656
2779
  try {
@@ -2659,6 +2782,16 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2659
2782
  catch (_err) { }
2660
2783
  return argv;
2661
2784
  };
2785
+ self._parsePositionalNumbers = function (argv) {
2786
+ const args = argv['--'] ? argv['--'] : argv._;
2787
+ for (let i = 0, arg; (arg = args[i]) !== undefined; i++) {
2788
+ if (shim$1.Parser.looksLikeNumber(arg) &&
2789
+ Number.isSafeInteger(Math.floor(parseFloat(`${arg}`)))) {
2790
+ args[i] = Number(arg);
2791
+ }
2792
+ }
2793
+ return argv;
2794
+ };
2662
2795
  self._runValidation = function runValidation(argv, aliases, positionalMap, parseErrors, isDefaultCommand = false) {
2663
2796
  if (parseErrors)
2664
2797
  throw new YError(parseErrors.message);
@@ -2682,7 +2815,11 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2682
2815
  function guessLocale() {
2683
2816
  if (!detectLocale)
2684
2817
  return;
2685
- const locale = shim$1.getEnv('LC_ALL') || shim$1.getEnv('LC_MESSAGES') || shim$1.getEnv('LANG') || shim$1.getEnv('LANGUAGE') || 'en_US';
2818
+ const locale = shim$1.getEnv('LC_ALL') ||
2819
+ shim$1.getEnv('LC_MESSAGES') ||
2820
+ shim$1.getEnv('LANG') ||
2821
+ shim$1.getEnv('LANGUAGE') ||
2822
+ 'en_US';
2686
2823
  self.locale(locale.replace(/[.:].*/, ''));
2687
2824
  }
2688
2825
  self.help();
@@ -2691,7 +2828,7 @@ function Yargs(processArgs = [], cwd = shim$1.process.cwd(), parentRequire) {
2691
2828
  }
2692
2829
  const rebase = (base, dir) => shim$1.path.relative(base, dir);
2693
2830
  function isYargsInstance(y) {
2694
- return !!y && (typeof y._parseArgs === 'function');
2831
+ return !!y && typeof y._parseArgs === 'function';
2695
2832
  }
2696
2833
 
2697
2834
  var _a, _b;
@@ -2703,7 +2840,7 @@ const Parser = require('yargs-parser');
2703
2840
  var cjsPlatformShim = {
2704
2841
  assert: {
2705
2842
  notStrictEqual: assert.notStrictEqual,
2706
- strictEqual: assert.strictEqual
2843
+ strictEqual: assert.strictEqual,
2707
2844
  },
2708
2845
  cliui: require('cliui'),
2709
2846
  findUp: require('escalade/sync'),
@@ -2724,7 +2861,9 @@ var cjsPlatformShim = {
2724
2861
  process.exit(code);
2725
2862
  },
2726
2863
  nextTick: process.nextTick,
2727
- stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
2864
+ stdColumns: typeof process.stdout.columns !== 'undefined'
2865
+ ? process.stdout.columns
2866
+ : null,
2728
2867
  },
2729
2868
  readFileSync,
2730
2869
  require: require,
@@ -2732,12 +2871,13 @@ var cjsPlatformShim = {
2732
2871
  stringWidth: require('string-width'),
2733
2872
  y18n: y18n({
2734
2873
  directory: resolve(__dirname, '../locales'),
2735
- updateFiles: false
2736
- })
2874
+ updateFiles: false,
2875
+ }),
2737
2876
  };
2738
2877
 
2739
- const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION)
2740
- ? Number(process.env.YARGS_MIN_NODE_VERSION) : 10;
2878
+ const minNodeVersion = process && process.env && process.env.YARGS_MIN_NODE_VERSION
2879
+ ? Number(process.env.YARGS_MIN_NODE_VERSION)
2880
+ : 10;
2741
2881
  if (process && process.version) {
2742
2882
  const major = Number(process.version.match(/v([^.]+)/)[1]);
2743
2883
  if (major < minNodeVersion) {
@@ -2758,7 +2898,7 @@ var cjs = {
2758
2898
  Parser: Parser$1,
2759
2899
  processArgv,
2760
2900
  rebase,
2761
- YError
2901
+ YError,
2762
2902
  };
2763
2903
 
2764
2904
  module.exports = cjs;