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.
@@ -1,13 +1,13 @@
1
- import { command as Command } from './command.js';
2
- import { assertNotStrictEqual, objectKeys, assertSingleKey } from './typings/common-types.js';
1
+ import { command as Command, } from './command.js';
2
+ import { assertNotStrictEqual, objectKeys, assertSingleKey, } from './typings/common-types.js';
3
3
  import { YError } from './yerror.js';
4
4
  import { usage as Usage } from './usage.js';
5
5
  import { argsert } from './argsert.js';
6
- import { completion as Completion } from './completion.js';
7
- import { validation as Validation } from './validation.js';
6
+ import { completion as Completion, } from './completion.js';
7
+ import { validation as Validation, } from './validation.js';
8
8
  import { objFilter } from './utils/obj-filter.js';
9
9
  import { applyExtends } from './utils/apply-extends.js';
10
- import { globalMiddlewareFactory } from './middleware.js';
10
+ import { globalMiddlewareFactory, } from './middleware.js';
11
11
  import { isPromise } from './utils/is-promise.js';
12
12
  import setBlocking from './utils/set-blocking.js';
13
13
  let shim;
@@ -45,23 +45,52 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
45
45
  const b = rebase(cwd, x);
46
46
  return x.match(/^(\/|([a-zA-Z]:)?\\)/) && b.length < x.length ? b : x;
47
47
  })
48
- .join(' ').trim();
48
+ .join(' ')
49
+ .trim();
49
50
  if (shim.getEnv('_') && shim.getProcessArgvBin() === shim.getEnv('_')) {
50
- self.$0 = shim.getEnv('_').replace(`${shim.path.dirname(shim.process.execPath())}/`, '');
51
+ self.$0 = shim
52
+ .getEnv('_')
53
+ .replace(`${shim.path.dirname(shim.process.execPath())}/`, '');
51
54
  }
52
55
  const context = { resets: -1, commands: [], fullCommands: [], files: [] };
53
56
  self.getContext = () => context;
57
+ let hasOutput = false;
58
+ let exitError = null;
59
+ self.exit = (code, err) => {
60
+ hasOutput = true;
61
+ exitError = err;
62
+ if (exitProcess)
63
+ shim.process.exit(code);
64
+ };
65
+ let completionCommand = null;
66
+ self.completion = function (cmd, desc, fn) {
67
+ argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
68
+ if (typeof desc === 'function') {
69
+ fn = desc;
70
+ desc = undefined;
71
+ }
72
+ completionCommand = cmd || completionCommand || 'completion';
73
+ if (!desc && desc !== false) {
74
+ desc = 'generate completion script';
75
+ }
76
+ self.command(completionCommand, desc);
77
+ if (fn)
78
+ completion.registerFunction(fn);
79
+ return self;
80
+ };
54
81
  let options;
55
82
  self.resetOptions = self.reset = function resetOptions(aliases = {}) {
56
83
  context.resets++;
57
84
  options = options || {};
58
85
  const tmpOptions = {};
59
86
  tmpOptions.local = options.local ? options.local : [];
60
- tmpOptions.configObjects = options.configObjects ? options.configObjects : [];
87
+ tmpOptions.configObjects = options.configObjects
88
+ ? options.configObjects
89
+ : [];
61
90
  const localLookup = {};
62
- tmpOptions.local.forEach((l) => {
91
+ tmpOptions.local.forEach(l => {
63
92
  localLookup[l] = true;
64
- (aliases[l] || []).forEach((a) => {
93
+ (aliases[l] || []).forEach(a => {
65
94
  localLookup[a] = true;
66
95
  });
67
96
  });
@@ -74,14 +103,27 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
74
103
  }, {}));
75
104
  groups = {};
76
105
  const arrayOptions = [
77
- 'array', 'boolean', 'string', 'skipValidation',
78
- 'count', 'normalize', 'number',
79
- 'hiddenOptions'
106
+ 'array',
107
+ 'boolean',
108
+ 'string',
109
+ 'skipValidation',
110
+ 'count',
111
+ 'normalize',
112
+ 'number',
113
+ 'hiddenOptions',
80
114
  ];
81
115
  const objectOptions = [
82
- 'narg', 'key', 'alias', 'default', 'defaultDescription',
83
- 'config', 'choices', 'demandedOptions', 'demandedCommands', 'coerce',
84
- 'deprecatedOptions'
116
+ 'narg',
117
+ 'key',
118
+ 'alias',
119
+ 'default',
120
+ 'defaultDescription',
121
+ 'config',
122
+ 'choices',
123
+ 'demandedOptions',
124
+ 'demandedCommands',
125
+ 'coerce',
126
+ 'deprecatedOptions',
85
127
  ];
86
128
  arrayOptions.forEach(k => {
87
129
  tmpOptions[k] = (options[k] || []).filter((k) => !localLookup[k]);
@@ -92,8 +134,12 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
92
134
  tmpOptions.envPrefix = options.envPrefix;
93
135
  options = tmpOptions;
94
136
  usage = usage ? usage.reset(localLookup) : Usage(self, y18n, shim);
95
- validation = validation ? validation.reset(localLookup) : Validation(self, usage, y18n, shim);
96
- command = command ? command.reset() : Command(self, usage, validation, globalMiddleware, shim);
137
+ validation = validation
138
+ ? validation.reset(localLookup)
139
+ : Validation(self, usage, y18n, shim);
140
+ command = command
141
+ ? command.reset()
142
+ : Command(self, usage, validation, globalMiddleware, shim);
97
143
  if (!completion)
98
144
  completion = Completion(self, usage, command, shim);
99
145
  completionCommand = null;
@@ -121,7 +167,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
121
167
  parsed: self.parsed,
122
168
  parseFn,
123
169
  parseContext,
124
- handlerFinishCommand
170
+ handlerFinishCommand,
125
171
  });
126
172
  usage.freeze();
127
173
  validation.freeze();
@@ -146,7 +192,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
146
192
  completionCommand,
147
193
  parseFn,
148
194
  parseContext,
149
- handlerFinishCommand
195
+ handlerFinishCommand,
150
196
  } = frozen);
151
197
  options.configObjects = configObjects;
152
198
  usage.unfreeze();
@@ -200,7 +246,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
200
246
  };
201
247
  function populateParserHintArray(type, keys) {
202
248
  keys = [].concat(keys);
203
- keys.forEach((key) => {
249
+ keys.forEach(key => {
204
250
  key = sanitizeKey(key);
205
251
  options[type].push(key);
206
252
  });
@@ -268,7 +314,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
268
314
  }
269
315
  function populateParserHintDictionary(builder, type, key, value, singleKeyHandler) {
270
316
  if (Array.isArray(key)) {
271
- key.forEach((k) => {
317
+ key.forEach(k => {
272
318
  builder(k, value);
273
319
  });
274
320
  }
@@ -303,7 +349,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
303
349
  }
304
350
  self.config = function config(key = 'config', msg, parseFn) {
305
351
  argsert('[object|string] [string|function] [function]', [key, msg, parseFn], arguments.length);
306
- if ((typeof key === 'object') && !Array.isArray(key)) {
352
+ if (typeof key === 'object' && !Array.isArray(key)) {
307
353
  key = applyExtends(key, cwd, self.getParserConfiguration()['deep-merge-config'] || false, shim);
308
354
  options.configObjects = (options.configObjects || []).concat(key);
309
355
  return self;
@@ -313,7 +359,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
313
359
  msg = undefined;
314
360
  }
315
361
  self.describe(key, msg || usage.deferY18nLookup('Path to JSON config file'));
316
- (Array.isArray(key) ? key : [key]).forEach((k) => {
362
+ (Array.isArray(key) ? key : [key]).forEach(k => {
317
363
  options.config[k] = parseFn || true;
318
364
  });
319
365
  return self;
@@ -321,7 +367,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
321
367
  self.example = function (cmd, description) {
322
368
  argsert('<string|array> [string]', [cmd, description], arguments.length);
323
369
  if (Array.isArray(cmd)) {
324
- cmd.forEach((exampleParams) => self.example(...exampleParams));
370
+ cmd.forEach(exampleParams => self.example(...exampleParams));
325
371
  }
326
372
  else {
327
373
  usage.example(cmd, description);
@@ -341,7 +387,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
341
387
  };
342
388
  self.demand = self.required = self.require = function demand(keys, max, msg) {
343
389
  if (Array.isArray(max)) {
344
- max.forEach((key) => {
390
+ max.forEach(key => {
345
391
  assertNotStrictEqual(msg, true, shim);
346
392
  demandOption(key, msg);
347
393
  });
@@ -356,7 +402,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
356
402
  self.demandCommand(keys, max, msg, msg);
357
403
  }
358
404
  else if (Array.isArray(keys)) {
359
- keys.forEach((key) => {
405
+ keys.forEach(key => {
360
406
  assertNotStrictEqual(msg, true, shim);
361
407
  demandOption(key, msg);
362
408
  });
@@ -382,7 +428,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
382
428
  min,
383
429
  max,
384
430
  minMsg,
385
- maxMsg
431
+ maxMsg,
386
432
  };
387
433
  return self;
388
434
  };
@@ -457,7 +503,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
457
503
  options.local = options.local.filter(l => globals.indexOf(l) === -1);
458
504
  }
459
505
  else {
460
- globals.forEach((g) => {
506
+ globals.forEach(g => {
461
507
  if (options.local.indexOf(g) === -1)
462
508
  options.local.push(g);
463
509
  });
@@ -496,7 +542,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
496
542
  assertNotStrictEqual(pkgJsonPath, undefined, shim);
497
543
  obj = JSON.parse(shim.readFileSync(pkgJsonPath, 'utf8'));
498
544
  }
499
- catch (noop) { }
545
+ catch (_noop) { }
500
546
  pkgs[npath] = obj || {};
501
547
  return pkgs[npath];
502
548
  }
@@ -536,7 +582,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
536
582
  self.option = self.options = function option(key, opt) {
537
583
  argsert('<string|object> [object]', [key, opt], arguments.length);
538
584
  if (typeof key === 'object') {
539
- Object.keys(key).forEach((k) => {
585
+ Object.keys(key).forEach(k => {
540
586
  self.options(k, key[k]);
541
587
  });
542
588
  }
@@ -634,9 +680,20 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
634
680
  if (context.resets === 0) {
635
681
  throw new YError(".positional() can only be called in a command's builder function");
636
682
  }
637
- const supportedOpts = ['default', 'defaultDescription', 'implies', 'normalize',
638
- 'choices', 'conflicts', 'coerce', 'type', 'describe',
639
- 'desc', 'description', 'alias'];
683
+ const supportedOpts = [
684
+ 'default',
685
+ 'defaultDescription',
686
+ 'implies',
687
+ 'normalize',
688
+ 'choices',
689
+ 'conflicts',
690
+ 'coerce',
691
+ 'type',
692
+ 'describe',
693
+ 'desc',
694
+ 'description',
695
+ 'alias',
696
+ ];
640
697
  opts = objFilter(opts, (k, v) => {
641
698
  let accept = supportedOpts.indexOf(k) !== -1;
642
699
  if (k === 'type' && ['string', 'number', 'boolean'].indexOf(v) === -1)
@@ -644,13 +701,15 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
644
701
  return accept;
645
702
  });
646
703
  const fullCommand = context.fullCommands[context.fullCommands.length - 1];
647
- const parseOptions = fullCommand ? command.cmdToParseOptions(fullCommand) : {
648
- array: [],
649
- alias: {},
650
- default: {},
651
- demand: {}
652
- };
653
- objectKeys(parseOptions).forEach((pk) => {
704
+ const parseOptions = fullCommand
705
+ ? command.cmdToParseOptions(fullCommand)
706
+ : {
707
+ array: [],
708
+ alias: {},
709
+ default: {},
710
+ demand: {},
711
+ };
712
+ objectKeys(parseOptions).forEach(pk => {
654
713
  const parseOption = parseOptions[pk];
655
714
  if (Array.isArray(parseOption)) {
656
715
  if (parseOption.indexOf(key) !== -1)
@@ -671,7 +730,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
671
730
  delete preservedGroups[groupName];
672
731
  }
673
732
  const seen = {};
674
- groups[groupName] = (existing || []).concat(opts).filter((key) => {
733
+ groups[groupName] = (existing || []).concat(opts).filter(key => {
675
734
  if (seen[key])
676
735
  return false;
677
736
  return (seen[key] = true);
@@ -807,29 +866,13 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
807
866
  usage.showHelpOnFail(enabled, message);
808
867
  return self;
809
868
  };
810
- var exitProcess = true;
869
+ let exitProcess = true;
811
870
  self.exitProcess = function (enabled = true) {
812
871
  argsert('[boolean]', [enabled], arguments.length);
813
872
  exitProcess = enabled;
814
873
  return self;
815
874
  };
816
875
  self.getExitProcess = () => exitProcess;
817
- var completionCommand = null;
818
- self.completion = function (cmd, desc, fn) {
819
- argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
820
- if (typeof desc === 'function') {
821
- fn = desc;
822
- desc = undefined;
823
- }
824
- completionCommand = cmd || completionCommand || 'completion';
825
- if (!desc && desc !== false) {
826
- desc = 'generate completion script';
827
- }
828
- self.command(completionCommand, desc);
829
- if (fn)
830
- completion.registerFunction(fn);
831
- return self;
832
- };
833
876
  self.showCompletionScript = function ($0, cmd) {
834
877
  argsert('[string] [string]', [$0, cmd], arguments.length);
835
878
  $0 = $0 || self.$0;
@@ -863,14 +906,6 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
863
906
  return self;
864
907
  };
865
908
  self.getDetectLocale = () => detectLocale;
866
- var hasOutput = false;
867
- var exitError = null;
868
- self.exit = (code, err) => {
869
- hasOutput = true;
870
- exitError = err;
871
- if (exitProcess)
872
- shim.process.exit(code);
873
- };
874
909
  const _logger = {
875
910
  log(...args) {
876
911
  if (!self._hasParseCallback())
@@ -887,7 +922,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
887
922
  if (output.length)
888
923
  output += '\n';
889
924
  output += args.join(' ');
890
- }
925
+ },
891
926
  };
892
927
  self._getLoggerInstance = () => _logger;
893
928
  self._hasOutput = () => hasOutput;
@@ -909,7 +944,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
909
944
  };
910
945
  Object.defineProperty(self, 'argv', {
911
946
  get: () => self._parseArgs(processArgs),
912
- enumerable: true
947
+ enumerable: true,
913
948
  });
914
949
  self._parseArgs = function parseArgs(args, shortCircuit, _calledFromCommand, commandIndex) {
915
950
  let skipValidation = !!_calledFromCommand;
@@ -918,10 +953,10 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
918
953
  options.configuration = self.getParserConfiguration();
919
954
  const populateDoubleDash = !!options.configuration['populate--'];
920
955
  const config = Object.assign({}, options.configuration, {
921
- 'populate--': true
956
+ 'populate--': true,
922
957
  });
923
958
  const parsed = shim.Parser.detailed(args, Object.assign({}, options, {
924
- configuration: config
959
+ configuration: Object.assign({ 'parse-positional-numbers': false }, config),
925
960
  }));
926
961
  let argv = parsed.argv;
927
962
  if (parseContext)
@@ -932,7 +967,7 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
932
967
  try {
933
968
  guessLocale();
934
969
  if (shortCircuit) {
935
- return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv);
970
+ return self._postProcess(argv, populateDoubleDash, _calledFromCommand);
936
971
  }
937
972
  if (helpOpt) {
938
973
  const helpCmds = [helpOpt]
@@ -946,15 +981,16 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
946
981
  const handlerKeys = command.getCommands();
947
982
  const requestCompletions = completion.completionKey in argv;
948
983
  const skipRecommendation = argv[helpOpt] || requestCompletions;
949
- const skipDefaultCommand = skipRecommendation && (handlerKeys.length > 1 || handlerKeys[0] !== '$0');
984
+ const skipDefaultCommand = skipRecommendation &&
985
+ (handlerKeys.length > 1 || handlerKeys[0] !== '$0');
950
986
  if (argv._.length) {
951
987
  if (handlerKeys.length) {
952
988
  let firstUnknownCommand;
953
- for (let i = (commandIndex || 0), cmd; argv._[i] !== undefined; i++) {
989
+ for (let i = commandIndex || 0, cmd; argv._[i] !== undefined; i++) {
954
990
  cmd = String(argv._[i]);
955
991
  if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) {
956
992
  const innerArgv = command.runCommand(cmd, self, parsed, i + 1);
957
- return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv);
993
+ return self._postProcess(innerArgv, populateDoubleDash);
958
994
  }
959
995
  else if (!firstUnknownCommand && cmd !== completionCommand) {
960
996
  firstUnknownCommand = cmd;
@@ -963,13 +999,15 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
963
999
  }
964
1000
  if (command.hasDefaultCommand() && !skipDefaultCommand) {
965
1001
  const innerArgv = command.runCommand(null, self, parsed);
966
- return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv);
1002
+ return self._postProcess(innerArgv, populateDoubleDash);
967
1003
  }
968
1004
  if (recommendCommands && firstUnknownCommand && !skipRecommendation) {
969
1005
  validation.recommendCommands(firstUnknownCommand, handlerKeys);
970
1006
  }
971
1007
  }
972
- if (completionCommand && ~argv._.indexOf(completionCommand) && !requestCompletions) {
1008
+ if (completionCommand &&
1009
+ ~argv._.indexOf(completionCommand) &&
1010
+ !requestCompletions) {
973
1011
  if (exitProcess)
974
1012
  setBlocking(true);
975
1013
  self.showCompletionScript();
@@ -978,24 +1016,23 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
978
1016
  }
979
1017
  else if (command.hasDefaultCommand() && !skipDefaultCommand) {
980
1018
  const innerArgv = command.runCommand(null, self, parsed);
981
- return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv);
1019
+ return self._postProcess(innerArgv, populateDoubleDash);
982
1020
  }
983
1021
  if (requestCompletions) {
984
1022
  if (exitProcess)
985
1023
  setBlocking(true);
986
1024
  args = [].concat(args);
987
1025
  const completionArgs = args.slice(args.indexOf(`--${completion.completionKey}`) + 1);
988
- completion.getCompletion(completionArgs, (completions) => {
989
- ;
990
- (completions || []).forEach((completion) => {
1026
+ completion.getCompletion(completionArgs, completions => {
1027
+ (completions || []).forEach(completion => {
991
1028
  _logger.log(completion);
992
1029
  });
993
1030
  self.exit(0);
994
1031
  });
995
- return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv);
1032
+ return self._postProcess(argv, !populateDoubleDash, _calledFromCommand);
996
1033
  }
997
1034
  if (!hasOutput) {
998
- Object.keys(argv).forEach((key) => {
1035
+ Object.keys(argv).forEach(key => {
999
1036
  if (key === helpOpt && argv[key]) {
1000
1037
  if (exitProcess)
1001
1038
  setBlocking(true);
@@ -1029,10 +1066,25 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
1029
1066
  else
1030
1067
  throw err;
1031
1068
  }
1032
- return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv);
1069
+ return self._postProcess(argv, populateDoubleDash, _calledFromCommand);
1070
+ };
1071
+ self._postProcess = function (argv, populateDoubleDash, calledFromCommand = false) {
1072
+ if (isPromise(argv))
1073
+ return argv;
1074
+ if (calledFromCommand)
1075
+ return argv;
1076
+ if (!populateDoubleDash) {
1077
+ argv = self._copyDoubleDash(argv);
1078
+ }
1079
+ const parsePositionalNumbers = self.getParserConfiguration()['parse-positional-numbers'] ||
1080
+ self.getParserConfiguration()['parse-positional-numbers'] === undefined;
1081
+ if (parsePositionalNumbers) {
1082
+ argv = self._parsePositionalNumbers(argv);
1083
+ }
1084
+ return argv;
1033
1085
  };
1034
1086
  self._copyDoubleDash = function (argv) {
1035
- if (isPromise(argv) || !argv._ || !argv['--'])
1087
+ if (!argv._ || !argv['--'])
1036
1088
  return argv;
1037
1089
  argv._.push.apply(argv._, argv['--']);
1038
1090
  try {
@@ -1041,6 +1093,16 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
1041
1093
  catch (_err) { }
1042
1094
  return argv;
1043
1095
  };
1096
+ self._parsePositionalNumbers = function (argv) {
1097
+ const args = argv['--'] ? argv['--'] : argv._;
1098
+ for (let i = 0, arg; (arg = args[i]) !== undefined; i++) {
1099
+ if (shim.Parser.looksLikeNumber(arg) &&
1100
+ Number.isSafeInteger(Math.floor(parseFloat(`${arg}`)))) {
1101
+ args[i] = Number(arg);
1102
+ }
1103
+ }
1104
+ return argv;
1105
+ };
1044
1106
  self._runValidation = function runValidation(argv, aliases, positionalMap, parseErrors, isDefaultCommand = false) {
1045
1107
  if (parseErrors)
1046
1108
  throw new YError(parseErrors.message);
@@ -1064,7 +1126,11 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
1064
1126
  function guessLocale() {
1065
1127
  if (!detectLocale)
1066
1128
  return;
1067
- const locale = shim.getEnv('LC_ALL') || shim.getEnv('LC_MESSAGES') || shim.getEnv('LANG') || shim.getEnv('LANGUAGE') || 'en_US';
1129
+ const locale = shim.getEnv('LC_ALL') ||
1130
+ shim.getEnv('LC_MESSAGES') ||
1131
+ shim.getEnv('LANG') ||
1132
+ shim.getEnv('LANGUAGE') ||
1133
+ 'en_US';
1068
1134
  self.locale(locale.replace(/[.:].*/, ''));
1069
1135
  }
1070
1136
  self.help();
@@ -1073,5 +1139,5 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
1073
1139
  }
1074
1140
  export const rebase = (base, dir) => shim.path.relative(base, dir);
1075
1141
  export function isYargsInstance(y) {
1076
- return !!y && (typeof y._parseArgs === 'function');
1142
+ return !!y && typeof y._parseArgs === 'function';
1077
1143
  }
package/helpers.mjs CHANGED
@@ -1,14 +1,10 @@
1
- import { applyExtends as _applyExtends } from './build/lib/utils/apply-extends.js'
2
- import { hideBin } from './build/lib/utils/process-argv.js'
3
- import Parser from 'yargs-parser'
4
- import shim from './lib/platform-shims/esm.mjs'
1
+ import {applyExtends as _applyExtends} from './build/lib/utils/apply-extends.js';
2
+ import {hideBin} from './build/lib/utils/process-argv.js';
3
+ import Parser from 'yargs-parser';
4
+ import shim from './lib/platform-shims/esm.mjs';
5
5
 
6
6
  const applyExtends = (config, cwd, mergeExtends) => {
7
- return _applyExtends(config, cwd, mergeExtends, shim)
8
- }
7
+ return _applyExtends(config, cwd, mergeExtends, shim);
8
+ };
9
9
 
10
- export {
11
- applyExtends,
12
- hideBin,
13
- Parser,
14
- }
10
+ export {applyExtends, hideBin, Parser};
package/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
- 'use strict'
1
+ 'use strict';
2
2
  // classic singleton yargs API, to use yargs
3
3
  // without running as a singleton do:
4
4
  // require('yargs/yargs')(process.argv.slice(2))
5
- const { Yargs, processArgv } = require('./build/index.cjs')
5
+ const {Yargs, processArgv} = require('./build/index.cjs');
6
6
 
7
- Argv(processArgv.hideBin(process.argv))
7
+ Argv(processArgv.hideBin(process.argv));
8
8
 
9
- module.exports = Argv
9
+ module.exports = Argv;
10
10
 
11
- function Argv (processArgs, cwd) {
12
- const argv = Yargs(processArgs, cwd, require)
13
- singletonify(argv)
14
- return argv
11
+ function Argv(processArgs, cwd) {
12
+ const argv = Yargs(processArgs, cwd, require);
13
+ singletonify(argv);
14
+ return argv;
15
15
  }
16
16
 
17
17
  /* Hack an instance of Argv with process.argv into Argv
@@ -21,19 +21,19 @@ function Argv (processArgs, cwd) {
21
21
  require('yargs').argv
22
22
  to get a parsed version of process.argv.
23
23
  */
24
- function singletonify (inst) {
25
- Object.keys(inst).forEach((key) => {
24
+ function singletonify(inst) {
25
+ Object.keys(inst).forEach(key => {
26
26
  if (key === 'argv') {
27
- Argv.__defineGetter__(key, inst.__lookupGetter__(key))
27
+ Argv.__defineGetter__(key, inst.__lookupGetter__(key));
28
28
  } else if (typeof inst[key] === 'function') {
29
- Argv[key] = inst[key].bind(inst)
29
+ Argv[key] = inst[key].bind(inst);
30
30
  } else {
31
31
  Argv.__defineGetter__('$0', () => {
32
- return inst.$0
33
- })
32
+ return inst.$0;
33
+ });
34
34
  Argv.__defineGetter__('parsed', () => {
35
- return inst.parsed
36
- })
35
+ return inst.parsed;
36
+ });
37
37
  }
38
- })
38
+ });
39
39
  }
package/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- 'use strict'
1
+ 'use strict';
2
2
 
3
3
  // Bootstraps yargs for ESM:
4
- import esmPlatformShim from './lib/platform-shims/esm.mjs'
5
- import { YargsWithShim } from './build/lib/yargs-factory.js'
4
+ import esmPlatformShim from './lib/platform-shims/esm.mjs';
5
+ import {YargsWithShim} from './build/lib/yargs-factory.js';
6
6
 
7
- const Yargs = YargsWithShim(esmPlatformShim)
8
- export default Yargs
7
+ const Yargs = YargsWithShim(esmPlatformShim);
8
+ export default Yargs;