yargs 17.0.0-candidate.7 → 17.0.1

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,3 +1,17 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
2
+ if (!privateMap.has(receiver)) {
3
+ throw new TypeError("attempted to set private field on non-instance");
4
+ }
5
+ privateMap.set(receiver, value);
6
+ return value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
9
+ if (!privateMap.has(receiver)) {
10
+ throw new TypeError("attempted to get private field on non-instance");
11
+ }
12
+ return privateMap.get(receiver);
13
+ };
14
+ var _command, _cwd, _context, _completion, _completionCommand, _defaultShowHiddenOpt, _exitError, _detectLocale, _exitProcess, _frozens, _globalMiddleware, _groups, _hasOutput, _helpOpt, _logger, _output, _options, _parentRequire, _parserConfig, _parseFn_1, _parseContext, _pkgs, _preservedGroups, _processArgs, _recommendCommands, _shim_1, _strict, _strictCommands, _strictOptions, _usage, _versionOpt, _validation;
1
15
  import { command as Command, } from './command.js';
2
16
  import { assertNotStrictEqual, assertSingleKey, objectKeys, } from './typings/common-types.js';
3
17
  import { YError } from './yerror.js';
@@ -11,313 +25,194 @@ import { applyMiddleware, GlobalMiddleware, } from './middleware.js';
11
25
  import { isPromise } from './utils/is-promise.js';
12
26
  import { maybeAsyncResult } from './utils/maybe-async-result.js';
13
27
  import setBlocking from './utils/set-blocking.js';
14
- let shim;
15
- export function YargsWithShim(_shim) {
16
- shim = _shim;
17
- return Yargs;
18
- }
19
- function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
20
- const self = {};
21
- let command;
22
- let completion = null;
23
- let groups = {};
24
- let output = '';
25
- const preservedGroups = {};
26
- const globalMiddleware = new GlobalMiddleware(self);
27
- let usage;
28
- let validation;
29
- const y18n = shim.y18n;
30
- self.scriptName = function (scriptName) {
31
- self.customScriptName = true;
32
- self.$0 = scriptName;
33
- return self;
34
- };
35
- let default$0;
36
- if (/\b(node|iojs|electron)(\.exe)?$/.test(shim.process.argv()[0])) {
37
- default$0 = shim.process.argv().slice(1, 2);
38
- }
39
- else {
40
- default$0 = shim.process.argv().slice(0, 1);
41
- }
42
- self.$0 = default$0
43
- .map(x => {
44
- const b = rebase(cwd, x);
45
- return x.match(/^(\/|([a-zA-Z]:)?\\)/) && b.length < x.length ? b : x;
46
- })
47
- .join(' ')
48
- .trim();
49
- if (shim.getEnv('_') && shim.getProcessArgvBin() === shim.getEnv('_')) {
50
- self.$0 = shim
51
- .getEnv('_')
52
- .replace(`${shim.path.dirname(shim.process.execPath())}/`, '');
53
- }
54
- const context = { resets: -1, commands: [], fullCommands: [] };
55
- self.getContext = () => context;
56
- let hasOutput = false;
57
- let exitError = null;
58
- self.exit = (code, err) => {
59
- hasOutput = true;
60
- exitError = err;
61
- if (exitProcess)
62
- shim.process.exit(code);
63
- };
64
- let completionCommand = null;
65
- self.completion = function (cmd, desc, fn) {
66
- argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
67
- if (typeof desc === 'function') {
68
- fn = desc;
69
- desc = undefined;
70
- }
71
- completionCommand = cmd || completionCommand || 'completion';
72
- if (!desc && desc !== false) {
73
- desc = 'generate completion script';
74
- }
75
- self.command(completionCommand, desc);
76
- if (fn)
77
- completion.registerFunction(fn);
78
- return self;
79
- };
80
- let options;
81
- self.resetOptions = self.reset = function resetOptions(aliases = {}) {
82
- context.resets++;
83
- options = options || {};
84
- const tmpOptions = {};
85
- tmpOptions.local = options.local ? options.local : [];
86
- tmpOptions.configObjects = options.configObjects
87
- ? options.configObjects
88
- : [];
89
- const localLookup = {};
90
- tmpOptions.local.forEach(l => {
91
- localLookup[l] = true;
92
- (aliases[l] || []).forEach(a => {
93
- localLookup[a] = true;
94
- });
95
- });
96
- Object.assign(preservedGroups, Object.keys(groups).reduce((acc, groupName) => {
97
- const keys = groups[groupName].filter(key => !(key in localLookup));
98
- if (keys.length > 0) {
99
- acc[groupName] = keys;
100
- }
101
- return acc;
102
- }, {}));
103
- groups = {};
104
- const arrayOptions = [
105
- 'array',
106
- 'boolean',
107
- 'string',
108
- 'skipValidation',
109
- 'count',
110
- 'normalize',
111
- 'number',
112
- 'hiddenOptions',
113
- ];
114
- const objectOptions = [
115
- 'narg',
116
- 'key',
117
- 'alias',
118
- 'default',
119
- 'defaultDescription',
120
- 'config',
121
- 'choices',
122
- 'demandedOptions',
123
- 'demandedCommands',
124
- 'deprecatedOptions',
125
- ];
126
- arrayOptions.forEach(k => {
127
- tmpOptions[k] = (options[k] || []).filter((k) => !localLookup[k]);
28
+ export function YargsFactory(_shim) {
29
+ return (processArgs = [], cwd = _shim.process.cwd(), parentRequire) => {
30
+ const yargs = new YargsInstance(processArgs, cwd, parentRequire, _shim);
31
+ Object.defineProperty(yargs, 'argv', {
32
+ get: () => {
33
+ return yargs.parse();
34
+ },
35
+ enumerable: true,
128
36
  });
129
- objectOptions.forEach((k) => {
130
- tmpOptions[k] = objFilter(options[k], k => !localLookup[k]);
131
- });
132
- tmpOptions.envPrefix = options.envPrefix;
133
- options = tmpOptions;
134
- usage = usage ? usage.reset(localLookup) : Usage(self, y18n, shim);
135
- validation = validation
136
- ? validation.reset(localLookup)
137
- : Validation(self, usage, y18n, shim);
138
- command = command
139
- ? command.reset()
140
- : Command(usage, validation, globalMiddleware, shim);
141
- if (!completion)
142
- completion = Completion(self, usage, command, shim);
143
- globalMiddleware.reset();
144
- completionCommand = null;
145
- output = '';
146
- exitError = null;
147
- hasOutput = false;
148
- self.parsed = false;
149
- return self;
37
+ yargs.help();
38
+ yargs.version();
39
+ return yargs;
150
40
  };
151
- self.resetOptions();
152
- const frozens = [];
153
- function freeze() {
154
- frozens.push({
155
- options,
156
- configObjects: options.configObjects.slice(0),
157
- exitProcess,
158
- groups,
159
- strict,
160
- strictCommands,
161
- strictOptions,
162
- completionCommand,
163
- output,
164
- exitError,
165
- hasOutput,
166
- parsed: self.parsed,
167
- parseFn,
168
- parseContext,
169
- });
170
- usage.freeze();
171
- validation.freeze();
172
- command.freeze();
173
- globalMiddleware.freeze();
174
- }
175
- function unfreeze() {
176
- const frozen = frozens.pop();
177
- assertNotStrictEqual(frozen, undefined, shim);
178
- let configObjects;
179
- ({
180
- options,
181
- configObjects,
182
- exitProcess,
183
- groups,
184
- output,
185
- exitError,
186
- hasOutput,
187
- parsed: self.parsed,
188
- strict,
189
- strictCommands,
190
- strictOptions,
191
- completionCommand,
192
- parseFn,
193
- parseContext,
194
- } = frozen);
195
- options.configObjects = configObjects;
196
- usage.unfreeze();
197
- validation.unfreeze();
198
- command.unfreeze();
199
- globalMiddleware.unfreeze();
41
+ }
42
+ const kCopyDoubleDash = Symbol('copyDoubleDash');
43
+ const kCreateLogger = Symbol('copyDoubleDash');
44
+ const kDeleteFromParserHintObject = Symbol('deleteFromParserHintObject');
45
+ const kFreeze = Symbol('freeze');
46
+ const kGetDollarZero = Symbol('getDollarZero');
47
+ const kGetParserConfiguration = Symbol('getParserConfiguration');
48
+ const kGuessLocale = Symbol('guessLocale');
49
+ const kGuessVersion = Symbol('guessVersion');
50
+ const kParsePositionalNumbers = Symbol('parsePositionalNumbers');
51
+ const kPkgUp = Symbol('pkgUp');
52
+ const kPopulateParserHintArray = Symbol('populateParserHintArray');
53
+ const kPopulateParserHintSingleValueDictionary = Symbol('populateParserHintSingleValueDictionary');
54
+ const kPopulateParserHintArrayDictionary = Symbol('populateParserHintArrayDictionary');
55
+ const kPopulateParserHintDictionary = Symbol('populateParserHintDictionary');
56
+ const kSanitizeKey = Symbol('sanitizeKey');
57
+ const kSetKey = Symbol('setKey');
58
+ const kUnfreeze = Symbol('unfreeze');
59
+ const kValidateAsync = Symbol('validateAsync');
60
+ const kGetCommandInstance = Symbol('getCommandInstance');
61
+ const kGetContext = Symbol('getContext');
62
+ const kGetHasOutput = Symbol('getHasOutput');
63
+ const kGetLoggerInstance = Symbol('getLoggerInstance');
64
+ const kGetParseContext = Symbol('getParseContext');
65
+ const kGetUsageInstance = Symbol('getUsageInstance');
66
+ const kGetValidationInstance = Symbol('getValidationInstance');
67
+ const kHasParseCallback = Symbol('hasParseCallback');
68
+ const kPostProcess = Symbol('postProcess');
69
+ const kRebase = Symbol('rebase');
70
+ const kReset = Symbol('reset');
71
+ const kRunYargsParserAndExecuteCommands = Symbol('runYargsParserAndExecuteCommands');
72
+ const kRunValidation = Symbol('runValidation');
73
+ const kSetHasOutput = Symbol('setHasOutput');
74
+ export class YargsInstance {
75
+ constructor(processArgs = [], cwd, parentRequire, shim) {
76
+ this.customScriptName = false;
77
+ this.parsed = false;
78
+ _command.set(this, void 0);
79
+ _cwd.set(this, void 0);
80
+ _context.set(this, { commands: [], fullCommands: [] });
81
+ _completion.set(this, null);
82
+ _completionCommand.set(this, null);
83
+ _defaultShowHiddenOpt.set(this, 'show-hidden');
84
+ _exitError.set(this, null);
85
+ _detectLocale.set(this, true);
86
+ _exitProcess.set(this, true);
87
+ _frozens.set(this, []);
88
+ _globalMiddleware.set(this, void 0);
89
+ _groups.set(this, {});
90
+ _hasOutput.set(this, false);
91
+ _helpOpt.set(this, null);
92
+ _logger.set(this, void 0);
93
+ _output.set(this, '');
94
+ _options.set(this, void 0);
95
+ _parentRequire.set(this, void 0);
96
+ _parserConfig.set(this, {});
97
+ _parseFn_1.set(this, null);
98
+ _parseContext.set(this, null);
99
+ _pkgs.set(this, {});
100
+ _preservedGroups.set(this, {});
101
+ _processArgs.set(this, void 0);
102
+ _recommendCommands.set(this, false);
103
+ _shim_1.set(this, void 0);
104
+ _strict.set(this, false);
105
+ _strictCommands.set(this, false);
106
+ _strictOptions.set(this, false);
107
+ _usage.set(this, void 0);
108
+ _versionOpt.set(this, null);
109
+ _validation.set(this, void 0);
110
+ __classPrivateFieldSet(this, _shim_1, shim);
111
+ __classPrivateFieldSet(this, _processArgs, processArgs);
112
+ __classPrivateFieldSet(this, _cwd, cwd);
113
+ __classPrivateFieldSet(this, _parentRequire, parentRequire);
114
+ __classPrivateFieldSet(this, _globalMiddleware, new GlobalMiddleware(this));
115
+ this.$0 = this[kGetDollarZero]();
116
+ this[kReset]();
117
+ __classPrivateFieldSet(this, _command, __classPrivateFieldGet(this, _command));
118
+ __classPrivateFieldSet(this, _usage, __classPrivateFieldGet(this, _usage));
119
+ __classPrivateFieldSet(this, _validation, __classPrivateFieldGet(this, _validation));
120
+ __classPrivateFieldSet(this, _options, __classPrivateFieldGet(this, _options));
121
+ __classPrivateFieldGet(this, _options).showHiddenOpt = __classPrivateFieldGet(this, _defaultShowHiddenOpt);
122
+ __classPrivateFieldSet(this, _logger, this[kCreateLogger]());
200
123
  }
201
- self.boolean = function (keys) {
202
- argsert('<array|string>', [keys], arguments.length);
203
- populateParserHintArray('boolean', keys);
204
- return self;
205
- };
206
- self.array = function (keys) {
207
- argsert('<array|string>', [keys], arguments.length);
208
- populateParserHintArray('array', keys);
209
- return self;
210
- };
211
- self.number = function (keys) {
212
- argsert('<array|string>', [keys], arguments.length);
213
- populateParserHintArray('number', keys);
214
- return self;
215
- };
216
- self.normalize = function (keys) {
217
- argsert('<array|string>', [keys], arguments.length);
218
- populateParserHintArray('normalize', keys);
219
- return self;
220
- };
221
- self.count = function (keys) {
222
- argsert('<array|string>', [keys], arguments.length);
223
- populateParserHintArray('count', keys);
224
- return self;
225
- };
226
- self.string = function (keys) {
227
- argsert('<array|string>', [keys], arguments.length);
228
- populateParserHintArray('string', keys);
229
- return self;
230
- };
231
- self.requiresArg = function (keys) {
232
- argsert('<array|string|object> [number]', [keys], arguments.length);
233
- if (typeof keys === 'string' && options.narg[keys]) {
234
- return self;
235
- }
236
- else {
237
- populateParserHintSingleValueDictionary(self.requiresArg, 'narg', keys, NaN);
124
+ addHelpOpt(opt, msg) {
125
+ const defaultHelpOpt = 'help';
126
+ argsert('[string|boolean] [string]', [opt, msg], arguments.length);
127
+ if (__classPrivateFieldGet(this, _helpOpt)) {
128
+ this[kDeleteFromParserHintObject](__classPrivateFieldGet(this, _helpOpt));
129
+ __classPrivateFieldSet(this, _helpOpt, null);
238
130
  }
239
- return self;
240
- };
241
- self.skipValidation = function (keys) {
242
- argsert('<array|string>', [keys], arguments.length);
243
- populateParserHintArray('skipValidation', keys);
244
- return self;
245
- };
246
- function populateParserHintArray(type, keys) {
247
- keys = [].concat(keys);
248
- keys.forEach(key => {
249
- key = sanitizeKey(key);
250
- options[type].push(key);
251
- });
131
+ if (opt === false && msg === undefined)
132
+ return this;
133
+ __classPrivateFieldSet(this, _helpOpt, typeof opt === 'string' ? opt : defaultHelpOpt);
134
+ this.boolean(__classPrivateFieldGet(this, _helpOpt));
135
+ this.describe(__classPrivateFieldGet(this, _helpOpt), msg || __classPrivateFieldGet(this, _usage).deferY18nLookup('Show help'));
136
+ return this;
252
137
  }
253
- self.nargs = function (key, value) {
254
- argsert('<string|object|array> [number]', [key, value], arguments.length);
255
- populateParserHintSingleValueDictionary(self.nargs, 'narg', key, value);
256
- return self;
257
- };
258
- self.choices = function (key, value) {
259
- argsert('<object|string|array> [string|array]', [key, value], arguments.length);
260
- populateParserHintArrayDictionary(self.choices, 'choices', key, value);
261
- return self;
262
- };
263
- self.alias = function (key, value) {
138
+ help(opt, msg) {
139
+ return this.addHelpOpt(opt, msg);
140
+ }
141
+ addShowHiddenOpt(opt, msg) {
142
+ argsert('[string|boolean] [string]', [opt, msg], arguments.length);
143
+ if (opt === false && msg === undefined)
144
+ return this;
145
+ const showHiddenOpt = typeof opt === 'string' ? opt : __classPrivateFieldGet(this, _defaultShowHiddenOpt);
146
+ this.boolean(showHiddenOpt);
147
+ this.describe(showHiddenOpt, msg || __classPrivateFieldGet(this, _usage).deferY18nLookup('Show hidden options'));
148
+ __classPrivateFieldGet(this, _options).showHiddenOpt = showHiddenOpt;
149
+ return this;
150
+ }
151
+ showHidden(opt, msg) {
152
+ return this.addShowHiddenOpt(opt, msg);
153
+ }
154
+ alias(key, value) {
264
155
  argsert('<object|string|array> [string|array]', [key, value], arguments.length);
265
- populateParserHintArrayDictionary(self.alias, 'alias', key, value);
266
- return self;
267
- };
268
- self.default = self.defaults = function (key, value, defaultDescription) {
269
- argsert('<object|string|array> [*] [string]', [key, value, defaultDescription], arguments.length);
270
- if (defaultDescription) {
271
- assertSingleKey(key, shim);
272
- options.defaultDescription[key] = defaultDescription;
273
- }
274
- if (typeof value === 'function') {
275
- assertSingleKey(key, shim);
276
- if (!options.defaultDescription[key])
277
- options.defaultDescription[key] = usage.functionDescription(value);
278
- value = value.call();
279
- }
280
- populateParserHintSingleValueDictionary(self.default, 'default', key, value);
281
- return self;
282
- };
283
- self.describe = function (key, desc) {
284
- argsert('<object|string|array> [string]', [key, desc], arguments.length);
285
- setKey(key, true);
286
- usage.describe(key, desc);
287
- return self;
288
- };
289
- function setKey(key, set) {
290
- populateParserHintSingleValueDictionary(setKey, 'key', key, set);
291
- return self;
156
+ this[kPopulateParserHintArrayDictionary](this.alias.bind(this), 'alias', key, value);
157
+ return this;
292
158
  }
293
- function demandOption(keys, msg) {
294
- argsert('<object|string|array> [string]', [keys, msg], arguments.length);
295
- populateParserHintSingleValueDictionary(self.demandOption, 'demandedOptions', keys, msg);
296
- return self;
159
+ array(keys) {
160
+ argsert('<array|string>', [keys], arguments.length);
161
+ this[kPopulateParserHintArray]('array', keys);
162
+ return this;
297
163
  }
298
- self.demandOption = demandOption;
299
- self.coerce = function (keys, value) {
164
+ boolean(keys) {
165
+ argsert('<array|string>', [keys], arguments.length);
166
+ this[kPopulateParserHintArray]('boolean', keys);
167
+ return this;
168
+ }
169
+ check(f, global) {
170
+ argsert('<function> [boolean]', [f, global], arguments.length);
171
+ this.middleware((argv, _yargs) => {
172
+ return maybeAsyncResult(() => {
173
+ return f(argv);
174
+ }, (result) => {
175
+ if (!result) {
176
+ __classPrivateFieldGet(this, _usage).fail(__classPrivateFieldGet(this, _shim_1).y18n.__('Argument check failed: %s', f.toString()));
177
+ }
178
+ else if (typeof result === 'string' || result instanceof Error) {
179
+ __classPrivateFieldGet(this, _usage).fail(result.toString(), result);
180
+ }
181
+ return argv;
182
+ }, (err) => {
183
+ __classPrivateFieldGet(this, _usage).fail(err.message ? err.message : err.toString(), err);
184
+ return argv;
185
+ });
186
+ }, false, global);
187
+ return this;
188
+ }
189
+ choices(key, value) {
190
+ argsert('<object|string|array> [string|array]', [key, value], arguments.length);
191
+ this[kPopulateParserHintArrayDictionary](this.choices.bind(this), 'choices', key, value);
192
+ return this;
193
+ }
194
+ coerce(keys, value) {
300
195
  argsert('<object|string|array> [function]', [keys, value], arguments.length);
301
196
  if (Array.isArray(keys)) {
302
197
  if (!value) {
303
198
  throw new YError('coerce callback must be provided');
304
199
  }
305
200
  for (const key of keys) {
306
- self.coerce(key, value);
201
+ this.coerce(key, value);
307
202
  }
308
- return self;
203
+ return this;
309
204
  }
310
205
  else if (typeof keys === 'object') {
311
206
  for (const key of Object.keys(keys)) {
312
- self.coerce(key, keys[key]);
207
+ this.coerce(key, keys[key]);
313
208
  }
314
- return self;
209
+ return this;
315
210
  }
316
211
  if (!value) {
317
212
  throw new YError('coerce callback must be provided');
318
213
  }
319
- self.alias(keys, keys);
320
- globalMiddleware.addCoerceMiddleware((argv, yargs) => {
214
+ __classPrivateFieldGet(this, _options).key[keys] = true;
215
+ __classPrivateFieldGet(this, _globalMiddleware).addCoerceMiddleware((argv, yargs) => {
321
216
  let aliases;
322
217
  return maybeAsyncResult(() => {
323
218
  aliases = yargs.getAliases();
@@ -334,96 +229,102 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
334
229
  throw new YError(err.message);
335
230
  });
336
231
  }, keys);
337
- return self;
338
- };
339
- function populateParserHintSingleValueDictionary(builder, type, key, value) {
340
- populateParserHintDictionary(builder, type, key, value, (type, key, value) => {
341
- options[type][key] = value;
342
- });
343
- }
344
- function populateParserHintArrayDictionary(builder, type, key, value) {
345
- populateParserHintDictionary(builder, type, key, value, (type, key, value) => {
346
- options[type][key] = (options[type][key] || []).concat(value);
347
- });
348
- }
349
- function populateParserHintDictionary(builder, type, key, value, singleKeyHandler) {
350
- if (Array.isArray(key)) {
351
- key.forEach(k => {
352
- builder(k, value);
353
- });
354
- }
355
- else if (((key) => typeof key === 'object')(key)) {
356
- for (const k of objectKeys(key)) {
357
- builder(k, key[k]);
358
- }
359
- }
360
- else {
361
- singleKeyHandler(type, sanitizeKey(key), value);
362
- }
232
+ return this;
363
233
  }
364
- function sanitizeKey(key) {
365
- if (key === '__proto__')
366
- return '___proto___';
367
- return key;
368
- }
369
- function deleteFromParserHintObject(optionKey) {
370
- objectKeys(options).forEach((hintKey) => {
371
- if (((key) => key === 'configObjects')(hintKey))
372
- return;
373
- const hint = options[hintKey];
374
- if (Array.isArray(hint)) {
375
- if (~hint.indexOf(optionKey))
376
- hint.splice(hint.indexOf(optionKey), 1);
377
- }
378
- else if (typeof hint === 'object') {
379
- delete hint[optionKey];
380
- }
381
- });
382
- delete usage.getDescriptions()[optionKey];
234
+ conflicts(key1, key2) {
235
+ argsert('<string|object> [string|array]', [key1, key2], arguments.length);
236
+ __classPrivateFieldGet(this, _validation).conflicts(key1, key2);
237
+ return this;
383
238
  }
384
- self.config = function config(key = 'config', msg, parseFn) {
239
+ config(key = 'config', msg, parseFn) {
385
240
  argsert('[object|string] [string|function] [function]', [key, msg, parseFn], arguments.length);
386
241
  if (typeof key === 'object' && !Array.isArray(key)) {
387
- key = applyExtends(key, cwd, self.getParserConfiguration()['deep-merge-config'] || false, shim);
388
- options.configObjects = (options.configObjects || []).concat(key);
389
- return self;
242
+ key = applyExtends(key, __classPrivateFieldGet(this, _cwd), this[kGetParserConfiguration]()['deep-merge-config'] || false, __classPrivateFieldGet(this, _shim_1));
243
+ __classPrivateFieldGet(this, _options).configObjects = (__classPrivateFieldGet(this, _options).configObjects || []).concat(key);
244
+ return this;
390
245
  }
391
246
  if (typeof msg === 'function') {
392
247
  parseFn = msg;
393
248
  msg = undefined;
394
249
  }
395
- self.describe(key, msg || usage.deferY18nLookup('Path to JSON config file'));
250
+ this.describe(key, msg || __classPrivateFieldGet(this, _usage).deferY18nLookup('Path to JSON config file'));
396
251
  (Array.isArray(key) ? key : [key]).forEach(k => {
397
- options.config[k] = parseFn || true;
252
+ __classPrivateFieldGet(this, _options).config[k] = parseFn || true;
398
253
  });
399
- return self;
400
- };
401
- self.example = function (cmd, description) {
402
- argsert('<string|array> [string]', [cmd, description], arguments.length);
403
- if (Array.isArray(cmd)) {
404
- cmd.forEach(exampleParams => self.example(...exampleParams));
254
+ return this;
255
+ }
256
+ completion(cmd, desc, fn) {
257
+ argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
258
+ if (typeof desc === 'function') {
259
+ fn = desc;
260
+ desc = undefined;
405
261
  }
406
- else {
407
- usage.example(cmd, description);
262
+ __classPrivateFieldSet(this, _completionCommand, cmd || __classPrivateFieldGet(this, _completionCommand) || 'completion');
263
+ if (!desc && desc !== false) {
264
+ desc = 'generate completion script';
408
265
  }
409
- return self;
410
- };
411
- self.command = self.commands = function (cmd, description, builder, handler, middlewares, deprecated) {
266
+ this.command(__classPrivateFieldGet(this, _completionCommand), desc);
267
+ if (fn)
268
+ __classPrivateFieldGet(this, _completion).registerFunction(fn);
269
+ return this;
270
+ }
271
+ command(cmd, description, builder, handler, middlewares, deprecated) {
412
272
  argsert('<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]', [cmd, description, builder, handler, middlewares, deprecated], arguments.length);
413
- command.addHandler(cmd, description, builder, handler, middlewares, deprecated);
414
- return self;
415
- };
416
- self.commandDir = function (dir, opts) {
273
+ __classPrivateFieldGet(this, _command).addHandler(cmd, description, builder, handler, middlewares, deprecated);
274
+ return this;
275
+ }
276
+ commands(cmd, description, builder, handler, middlewares, deprecated) {
277
+ return this.command(cmd, description, builder, handler, middlewares, deprecated);
278
+ }
279
+ commandDir(dir, opts) {
417
280
  argsert('<string> [object]', [dir, opts], arguments.length);
418
- const req = parentRequire || shim.require;
419
- command.addDirectory(dir, req, shim.getCallerFile(), opts);
420
- return self;
421
- };
422
- self.demand = self.required = self.require = function demand(keys, max, msg) {
281
+ const req = __classPrivateFieldGet(this, _parentRequire) || __classPrivateFieldGet(this, _shim_1).require;
282
+ __classPrivateFieldGet(this, _command).addDirectory(dir, req, __classPrivateFieldGet(this, _shim_1).getCallerFile(), opts);
283
+ return this;
284
+ }
285
+ count(keys) {
286
+ argsert('<array|string>', [keys], arguments.length);
287
+ this[kPopulateParserHintArray]('count', keys);
288
+ return this;
289
+ }
290
+ default(key, value, defaultDescription) {
291
+ argsert('<object|string|array> [*] [string]', [key, value, defaultDescription], arguments.length);
292
+ if (defaultDescription) {
293
+ assertSingleKey(key, __classPrivateFieldGet(this, _shim_1));
294
+ __classPrivateFieldGet(this, _options).defaultDescription[key] = defaultDescription;
295
+ }
296
+ if (typeof value === 'function') {
297
+ assertSingleKey(key, __classPrivateFieldGet(this, _shim_1));
298
+ if (!__classPrivateFieldGet(this, _options).defaultDescription[key])
299
+ __classPrivateFieldGet(this, _options).defaultDescription[key] = __classPrivateFieldGet(this, _usage).functionDescription(value);
300
+ value = value.call();
301
+ }
302
+ this[kPopulateParserHintSingleValueDictionary](this.default.bind(this), 'default', key, value);
303
+ return this;
304
+ }
305
+ defaults(key, value, defaultDescription) {
306
+ return this.default(key, value, defaultDescription);
307
+ }
308
+ demandCommand(min = 1, max, minMsg, maxMsg) {
309
+ argsert('[number] [number|string] [string|null|undefined] [string|null|undefined]', [min, max, minMsg, maxMsg], arguments.length);
310
+ if (typeof max !== 'number') {
311
+ minMsg = max;
312
+ max = Infinity;
313
+ }
314
+ this.global('_', false);
315
+ __classPrivateFieldGet(this, _options).demandedCommands._ = {
316
+ min,
317
+ max,
318
+ minMsg,
319
+ maxMsg,
320
+ };
321
+ return this;
322
+ }
323
+ demand(keys, max, msg) {
423
324
  if (Array.isArray(max)) {
424
325
  max.forEach(key => {
425
- assertNotStrictEqual(msg, true, shim);
426
- demandOption(key, msg);
326
+ assertNotStrictEqual(msg, true, __classPrivateFieldGet(this, _shim_1));
327
+ this.demandOption(key, msg);
427
328
  });
428
329
  max = Infinity;
429
330
  }
@@ -432,306 +333,407 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
432
333
  max = Infinity;
433
334
  }
434
335
  if (typeof keys === 'number') {
435
- assertNotStrictEqual(msg, true, shim);
436
- self.demandCommand(keys, max, msg, msg);
336
+ assertNotStrictEqual(msg, true, __classPrivateFieldGet(this, _shim_1));
337
+ this.demandCommand(keys, max, msg, msg);
437
338
  }
438
339
  else if (Array.isArray(keys)) {
439
340
  keys.forEach(key => {
440
- assertNotStrictEqual(msg, true, shim);
441
- demandOption(key, msg);
341
+ assertNotStrictEqual(msg, true, __classPrivateFieldGet(this, _shim_1));
342
+ this.demandOption(key, msg);
442
343
  });
443
344
  }
444
345
  else {
445
346
  if (typeof msg === 'string') {
446
- demandOption(keys, msg);
347
+ this.demandOption(keys, msg);
447
348
  }
448
349
  else if (msg === true || typeof msg === 'undefined') {
449
- demandOption(keys);
350
+ this.demandOption(keys);
450
351
  }
451
352
  }
452
- return self;
453
- };
454
- self.demandCommand = function demandCommand(min = 1, max, minMsg, maxMsg) {
455
- argsert('[number] [number|string] [string|null|undefined] [string|null|undefined]', [min, max, minMsg, maxMsg], arguments.length);
456
- if (typeof max !== 'number') {
457
- minMsg = max;
458
- max = Infinity;
459
- }
460
- self.global('_', false);
461
- options.demandedCommands._ = {
462
- min,
463
- max,
464
- minMsg,
465
- maxMsg,
466
- };
467
- return self;
468
- };
469
- self.getAliases = () => {
470
- return self.parsed ? self.parsed.aliases : {};
471
- };
472
- self.getDemandedOptions = () => {
473
- argsert([], 0);
474
- return options.demandedOptions;
475
- };
476
- self.getDemandedCommands = () => {
477
- argsert([], 0);
478
- return options.demandedCommands;
479
- };
480
- self.deprecateOption = function deprecateOption(option, message) {
353
+ return this;
354
+ }
355
+ demandOption(keys, msg) {
356
+ argsert('<object|string|array> [string]', [keys, msg], arguments.length);
357
+ this[kPopulateParserHintSingleValueDictionary](this.demandOption.bind(this), 'demandedOptions', keys, msg);
358
+ return this;
359
+ }
360
+ deprecateOption(option, message) {
481
361
  argsert('<string> [string|boolean]', [option, message], arguments.length);
482
- options.deprecatedOptions[option] = message;
483
- return self;
484
- };
485
- self.getDeprecatedOptions = () => {
486
- argsert([], 0);
487
- return options.deprecatedOptions;
488
- };
489
- self.implies = function (key, value) {
490
- argsert('<string|object> [number|string|array]', [key, value], arguments.length);
491
- validation.implies(key, value);
492
- return self;
493
- };
494
- self.conflicts = function (key1, key2) {
495
- argsert('<string|object> [string|array]', [key1, key2], arguments.length);
496
- validation.conflicts(key1, key2);
497
- return self;
498
- };
499
- self.usage = function (msg, description, builder, handler) {
500
- argsert('<string|null|undefined> [string|boolean] [function|object] [function]', [msg, description, builder, handler], arguments.length);
501
- if (description !== undefined) {
502
- assertNotStrictEqual(msg, null, shim);
503
- if ((msg || '').match(/^\$0( |$)/)) {
504
- return self.command(msg, description, builder, handler);
505
- }
506
- else {
507
- throw new YError('.usage() description must start with $0 if being used as alias for .command()');
508
- }
362
+ __classPrivateFieldGet(this, _options).deprecatedOptions[option] = message;
363
+ return this;
364
+ }
365
+ describe(keys, description) {
366
+ argsert('<object|string|array> [string]', [keys, description], arguments.length);
367
+ this[kSetKey](keys, true);
368
+ __classPrivateFieldGet(this, _usage).describe(keys, description);
369
+ return this;
370
+ }
371
+ detectLocale(detect) {
372
+ argsert('<boolean>', [detect], arguments.length);
373
+ __classPrivateFieldSet(this, _detectLocale, detect);
374
+ return this;
375
+ }
376
+ env(prefix) {
377
+ argsert('[string|boolean]', [prefix], arguments.length);
378
+ if (prefix === false)
379
+ delete __classPrivateFieldGet(this, _options).envPrefix;
380
+ else
381
+ __classPrivateFieldGet(this, _options).envPrefix = prefix || '';
382
+ return this;
383
+ }
384
+ epilogue(msg) {
385
+ argsert('<string>', [msg], arguments.length);
386
+ __classPrivateFieldGet(this, _usage).epilog(msg);
387
+ return this;
388
+ }
389
+ epilog(msg) {
390
+ return this.epilogue(msg);
391
+ }
392
+ example(cmd, description) {
393
+ argsert('<string|array> [string]', [cmd, description], arguments.length);
394
+ if (Array.isArray(cmd)) {
395
+ cmd.forEach(exampleParams => this.example(...exampleParams));
509
396
  }
510
397
  else {
511
- usage.usage(msg);
512
- return self;
398
+ __classPrivateFieldGet(this, _usage).example(cmd, description);
513
399
  }
514
- };
515
- self.epilogue = self.epilog = function (msg) {
516
- argsert('<string>', [msg], arguments.length);
517
- usage.epilog(msg);
518
- return self;
519
- };
520
- self.fail = function (f) {
400
+ return this;
401
+ }
402
+ exit(code, err) {
403
+ __classPrivateFieldSet(this, _hasOutput, true);
404
+ __classPrivateFieldSet(this, _exitError, err);
405
+ if (__classPrivateFieldGet(this, _exitProcess))
406
+ __classPrivateFieldGet(this, _shim_1).process.exit(code);
407
+ }
408
+ exitProcess(enabled = true) {
409
+ argsert('[boolean]', [enabled], arguments.length);
410
+ __classPrivateFieldSet(this, _exitProcess, enabled);
411
+ return this;
412
+ }
413
+ fail(f) {
521
414
  argsert('<function|boolean>', [f], arguments.length);
522
415
  if (typeof f === 'boolean' && f !== false) {
523
416
  throw new YError("Invalid first argument. Expected function or boolean 'false'");
524
417
  }
525
- usage.failFn(f);
526
- return self;
527
- };
528
- self.check = function (f, global) {
529
- argsert('<function> [boolean]', [f, global], arguments.length);
530
- self.middleware((argv, _yargs) => {
531
- return maybeAsyncResult(() => {
532
- return f(argv);
533
- }, (result) => {
534
- if (!result) {
535
- usage.fail(y18n.__('Argument check failed: %s', f.toString()));
536
- }
537
- else if (typeof result === 'string' || result instanceof Error) {
538
- usage.fail(result.toString(), result);
539
- }
540
- return argv;
541
- }, (err) => {
542
- usage.fail(err.message ? err.message : err.toString(), err);
543
- return argv;
418
+ __classPrivateFieldGet(this, _usage).failFn(f);
419
+ return this;
420
+ }
421
+ getAliases() {
422
+ return this.parsed ? this.parsed.aliases : {};
423
+ }
424
+ async getCompletion(args, done) {
425
+ argsert('<array> [function]', [args, done], arguments.length);
426
+ if (!done) {
427
+ return new Promise((resolve, reject) => {
428
+ __classPrivateFieldGet(this, _completion).getCompletion(args, (err, completions) => {
429
+ if (err)
430
+ reject(err);
431
+ else
432
+ resolve(completions);
433
+ });
544
434
  });
545
- }, false, global);
546
- return self;
547
- };
548
- self.middleware = (callback, applyBeforeValidation, global = true) => {
549
- return globalMiddleware.addMiddleware(callback, !!applyBeforeValidation, global);
550
- };
551
- self.global = function global(globals, global) {
435
+ }
436
+ else {
437
+ return __classPrivateFieldGet(this, _completion).getCompletion(args, done);
438
+ }
439
+ }
440
+ getDemandedOptions() {
441
+ argsert([], 0);
442
+ return __classPrivateFieldGet(this, _options).demandedOptions;
443
+ }
444
+ getDemandedCommands() {
445
+ argsert([], 0);
446
+ return __classPrivateFieldGet(this, _options).demandedCommands;
447
+ }
448
+ getDeprecatedOptions() {
449
+ argsert([], 0);
450
+ return __classPrivateFieldGet(this, _options).deprecatedOptions;
451
+ }
452
+ getDetectLocale() {
453
+ return __classPrivateFieldGet(this, _detectLocale);
454
+ }
455
+ getExitProcess() {
456
+ return __classPrivateFieldGet(this, _exitProcess);
457
+ }
458
+ getGroups() {
459
+ return Object.assign({}, __classPrivateFieldGet(this, _groups), __classPrivateFieldGet(this, _preservedGroups));
460
+ }
461
+ getHelp() {
462
+ __classPrivateFieldSet(this, _hasOutput, true);
463
+ if (!__classPrivateFieldGet(this, _usage).hasCachedHelpMessage()) {
464
+ if (!this.parsed) {
465
+ const parse = this[kRunYargsParserAndExecuteCommands](__classPrivateFieldGet(this, _processArgs), undefined, undefined, 0, true);
466
+ if (isPromise(parse)) {
467
+ return parse.then(() => {
468
+ return __classPrivateFieldGet(this, _usage).help();
469
+ });
470
+ }
471
+ }
472
+ const builderResponse = __classPrivateFieldGet(this, _command).runDefaultBuilderOn(this);
473
+ if (isPromise(builderResponse)) {
474
+ return builderResponse.then(() => {
475
+ return __classPrivateFieldGet(this, _usage).help();
476
+ });
477
+ }
478
+ }
479
+ return Promise.resolve(__classPrivateFieldGet(this, _usage).help());
480
+ }
481
+ getOptions() {
482
+ return __classPrivateFieldGet(this, _options);
483
+ }
484
+ getStrict() {
485
+ return __classPrivateFieldGet(this, _strict);
486
+ }
487
+ getStrictCommands() {
488
+ return __classPrivateFieldGet(this, _strictCommands);
489
+ }
490
+ getStrictOptions() {
491
+ return __classPrivateFieldGet(this, _strictOptions);
492
+ }
493
+ global(globals, global) {
552
494
  argsert('<string|array> [boolean]', [globals, global], arguments.length);
553
495
  globals = [].concat(globals);
554
496
  if (global !== false) {
555
- options.local = options.local.filter(l => globals.indexOf(l) === -1);
497
+ __classPrivateFieldGet(this, _options).local = __classPrivateFieldGet(this, _options).local.filter(l => globals.indexOf(l) === -1);
556
498
  }
557
499
  else {
558
500
  globals.forEach(g => {
559
- if (options.local.indexOf(g) === -1)
560
- options.local.push(g);
501
+ if (__classPrivateFieldGet(this, _options).local.indexOf(g) === -1)
502
+ __classPrivateFieldGet(this, _options).local.push(g);
561
503
  });
562
504
  }
563
- return self;
564
- };
565
- self.pkgConf = function pkgConf(key, rootPath) {
566
- argsert('<string> [string]', [key, rootPath], arguments.length);
567
- let conf = null;
568
- const obj = pkgUp(rootPath || cwd);
569
- if (obj[key] && typeof obj[key] === 'object') {
570
- conf = applyExtends(obj[key], rootPath || cwd, self.getParserConfiguration()['deep-merge-config'] || false, shim);
571
- options.configObjects = (options.configObjects || []).concat(conf);
572
- }
573
- return self;
574
- };
575
- const pkgs = {};
576
- function pkgUp(rootPath) {
577
- const npath = rootPath || '*';
578
- if (pkgs[npath])
579
- return pkgs[npath];
580
- let obj = {};
581
- try {
582
- let startDir = rootPath || shim.mainFilename;
583
- if (!rootPath && shim.path.extname(startDir)) {
584
- startDir = shim.path.dirname(startDir);
585
- }
586
- const pkgJsonPath = shim.findUp(startDir, (dir, names) => {
587
- if (names.includes('package.json')) {
588
- return 'package.json';
589
- }
590
- else {
591
- return undefined;
592
- }
593
- });
594
- assertNotStrictEqual(pkgJsonPath, undefined, shim);
595
- obj = JSON.parse(shim.readFileSync(pkgJsonPath, 'utf8'));
596
- }
597
- catch (_noop) { }
598
- pkgs[npath] = obj || {};
599
- return pkgs[npath];
505
+ return this;
600
506
  }
601
- let parseFn = null;
602
- let parseContext = null;
603
- self.parse = function parse(args, shortCircuit, _parseFn) {
604
- argsert('[string|array] [function|boolean|object] [function]', [args, shortCircuit, _parseFn], arguments.length);
605
- freeze();
606
- if (typeof args === 'undefined') {
607
- const argv = self._parseArgs(processArgs);
608
- const tmpParsed = self.parsed;
609
- unfreeze();
610
- self.parsed = tmpParsed;
611
- return argv;
612
- }
613
- if (typeof shortCircuit === 'object') {
614
- parseContext = shortCircuit;
615
- shortCircuit = _parseFn;
507
+ group(opts, groupName) {
508
+ argsert('<string|array> <string>', [opts, groupName], arguments.length);
509
+ const existing = __classPrivateFieldGet(this, _preservedGroups)[groupName] || __classPrivateFieldGet(this, _groups)[groupName];
510
+ if (__classPrivateFieldGet(this, _preservedGroups)[groupName]) {
511
+ delete __classPrivateFieldGet(this, _preservedGroups)[groupName];
616
512
  }
617
- if (typeof shortCircuit === 'function') {
618
- parseFn = shortCircuit;
619
- shortCircuit = false;
513
+ const seen = {};
514
+ __classPrivateFieldGet(this, _groups)[groupName] = (existing || []).concat(opts).filter(key => {
515
+ if (seen[key])
516
+ return false;
517
+ return (seen[key] = true);
518
+ });
519
+ return this;
520
+ }
521
+ hide(key) {
522
+ argsert('<string>', [key], arguments.length);
523
+ __classPrivateFieldGet(this, _options).hiddenOptions.push(key);
524
+ return this;
525
+ }
526
+ implies(key, value) {
527
+ argsert('<string|object> [number|string|array]', [key, value], arguments.length);
528
+ __classPrivateFieldGet(this, _validation).implies(key, value);
529
+ return this;
530
+ }
531
+ locale(locale) {
532
+ argsert('[string]', [locale], arguments.length);
533
+ if (!locale) {
534
+ this[kGuessLocale]();
535
+ return __classPrivateFieldGet(this, _shim_1).y18n.getLocale();
620
536
  }
621
- if (!shortCircuit)
622
- processArgs = args;
623
- if (parseFn)
624
- exitProcess = false;
625
- const parsed = self._parseArgs(args, !!shortCircuit);
626
- completion.setParsed(self.parsed);
627
- if (parseFn)
628
- parseFn(exitError, parsed, output);
629
- unfreeze();
630
- return parsed;
631
- };
632
- self._getParseContext = () => parseContext || {};
633
- self._hasParseCallback = () => !!parseFn;
634
- self.option = self.options = function option(key, opt) {
537
+ __classPrivateFieldSet(this, _detectLocale, false);
538
+ __classPrivateFieldGet(this, _shim_1).y18n.setLocale(locale);
539
+ return this;
540
+ }
541
+ middleware(callback, applyBeforeValidation, global) {
542
+ return __classPrivateFieldGet(this, _globalMiddleware).addMiddleware(callback, !!applyBeforeValidation, global);
543
+ }
544
+ nargs(key, value) {
545
+ argsert('<string|object|array> [number]', [key, value], arguments.length);
546
+ this[kPopulateParserHintSingleValueDictionary](this.nargs.bind(this), 'narg', key, value);
547
+ return this;
548
+ }
549
+ normalize(keys) {
550
+ argsert('<array|string>', [keys], arguments.length);
551
+ this[kPopulateParserHintArray]('normalize', keys);
552
+ return this;
553
+ }
554
+ number(keys) {
555
+ argsert('<array|string>', [keys], arguments.length);
556
+ this[kPopulateParserHintArray]('number', keys);
557
+ return this;
558
+ }
559
+ option(key, opt) {
635
560
  argsert('<string|object> [object]', [key, opt], arguments.length);
636
561
  if (typeof key === 'object') {
637
562
  Object.keys(key).forEach(k => {
638
- self.options(k, key[k]);
563
+ this.options(k, key[k]);
639
564
  });
640
565
  }
641
566
  else {
642
567
  if (typeof opt !== 'object') {
643
568
  opt = {};
644
569
  }
645
- options.key[key] = true;
570
+ __classPrivateFieldGet(this, _options).key[key] = true;
646
571
  if (opt.alias)
647
- self.alias(key, opt.alias);
572
+ this.alias(key, opt.alias);
648
573
  const deprecate = opt.deprecate || opt.deprecated;
649
574
  if (deprecate) {
650
- self.deprecateOption(key, deprecate);
575
+ this.deprecateOption(key, deprecate);
651
576
  }
652
577
  const demand = opt.demand || opt.required || opt.require;
653
578
  if (demand) {
654
- self.demand(key, demand);
579
+ this.demand(key, demand);
655
580
  }
656
581
  if (opt.demandOption) {
657
- self.demandOption(key, typeof opt.demandOption === 'string' ? opt.demandOption : undefined);
582
+ this.demandOption(key, typeof opt.demandOption === 'string' ? opt.demandOption : undefined);
658
583
  }
659
584
  if (opt.conflicts) {
660
- self.conflicts(key, opt.conflicts);
585
+ this.conflicts(key, opt.conflicts);
661
586
  }
662
587
  if ('default' in opt) {
663
- self.default(key, opt.default);
588
+ this.default(key, opt.default);
664
589
  }
665
590
  if (opt.implies !== undefined) {
666
- self.implies(key, opt.implies);
591
+ this.implies(key, opt.implies);
667
592
  }
668
593
  if (opt.nargs !== undefined) {
669
- self.nargs(key, opt.nargs);
594
+ this.nargs(key, opt.nargs);
670
595
  }
671
596
  if (opt.config) {
672
- self.config(key, opt.configParser);
597
+ this.config(key, opt.configParser);
673
598
  }
674
599
  if (opt.normalize) {
675
- self.normalize(key);
600
+ this.normalize(key);
676
601
  }
677
602
  if (opt.choices) {
678
- self.choices(key, opt.choices);
603
+ this.choices(key, opt.choices);
679
604
  }
680
605
  if (opt.coerce) {
681
- self.coerce(key, opt.coerce);
606
+ this.coerce(key, opt.coerce);
682
607
  }
683
608
  if (opt.group) {
684
- self.group(key, opt.group);
609
+ this.group(key, opt.group);
685
610
  }
686
611
  if (opt.boolean || opt.type === 'boolean') {
687
- self.boolean(key);
612
+ this.boolean(key);
688
613
  if (opt.alias)
689
- self.boolean(opt.alias);
614
+ this.boolean(opt.alias);
690
615
  }
691
616
  if (opt.array || opt.type === 'array') {
692
- self.array(key);
617
+ this.array(key);
693
618
  if (opt.alias)
694
- self.array(opt.alias);
619
+ this.array(opt.alias);
695
620
  }
696
621
  if (opt.number || opt.type === 'number') {
697
- self.number(key);
622
+ this.number(key);
698
623
  if (opt.alias)
699
- self.number(opt.alias);
624
+ this.number(opt.alias);
700
625
  }
701
626
  if (opt.string || opt.type === 'string') {
702
- self.string(key);
627
+ this.string(key);
703
628
  if (opt.alias)
704
- self.string(opt.alias);
629
+ this.string(opt.alias);
705
630
  }
706
631
  if (opt.count || opt.type === 'count') {
707
- self.count(key);
632
+ this.count(key);
708
633
  }
709
634
  if (typeof opt.global === 'boolean') {
710
- self.global(key, opt.global);
635
+ this.global(key, opt.global);
711
636
  }
712
637
  if (opt.defaultDescription) {
713
- options.defaultDescription[key] = opt.defaultDescription;
638
+ __classPrivateFieldGet(this, _options).defaultDescription[key] = opt.defaultDescription;
714
639
  }
715
640
  if (opt.skipValidation) {
716
- self.skipValidation(key);
641
+ this.skipValidation(key);
717
642
  }
718
643
  const desc = opt.describe || opt.description || opt.desc;
719
- self.describe(key, desc);
644
+ this.describe(key, desc);
720
645
  if (opt.hidden) {
721
- self.hide(key);
646
+ this.hide(key);
722
647
  }
723
648
  if (opt.requiresArg) {
724
- self.requiresArg(key);
649
+ this.requiresArg(key);
725
650
  }
726
651
  }
727
- return self;
728
- };
729
- self.getOptions = () => options;
730
- self.positional = function (key, opts) {
731
- argsert('<string> <object>', [key, opts], arguments.length);
732
- if (context.resets === 0) {
733
- throw new YError(".positional() can only be called in a command's builder function");
652
+ return this;
653
+ }
654
+ options(key, opt) {
655
+ return this.option(key, opt);
656
+ }
657
+ parse(args, shortCircuit, _parseFn) {
658
+ argsert('[string|array] [function|boolean|object] [function]', [args, shortCircuit, _parseFn], arguments.length);
659
+ this[kFreeze]();
660
+ if (typeof args === 'undefined') {
661
+ args = __classPrivateFieldGet(this, _processArgs);
662
+ }
663
+ if (typeof shortCircuit === 'object') {
664
+ __classPrivateFieldSet(this, _parseContext, shortCircuit);
665
+ shortCircuit = _parseFn;
666
+ }
667
+ if (typeof shortCircuit === 'function') {
668
+ __classPrivateFieldSet(this, _parseFn_1, shortCircuit);
669
+ shortCircuit = false;
734
670
  }
671
+ if (!shortCircuit)
672
+ __classPrivateFieldSet(this, _processArgs, args);
673
+ if (__classPrivateFieldGet(this, _parseFn_1))
674
+ __classPrivateFieldSet(this, _exitProcess, false);
675
+ const parsed = this[kRunYargsParserAndExecuteCommands](args, !!shortCircuit);
676
+ const tmpParsed = this.parsed;
677
+ __classPrivateFieldGet(this, _completion).setParsed(this.parsed);
678
+ if (isPromise(parsed)) {
679
+ return parsed
680
+ .then(argv => {
681
+ if (__classPrivateFieldGet(this, _parseFn_1))
682
+ __classPrivateFieldGet(this, _parseFn_1).call(this, __classPrivateFieldGet(this, _exitError), argv, __classPrivateFieldGet(this, _output));
683
+ return argv;
684
+ })
685
+ .catch(err => {
686
+ if (__classPrivateFieldGet(this, _parseFn_1)) {
687
+ __classPrivateFieldGet(this, _parseFn_1)(err, this.parsed.argv, __classPrivateFieldGet(this, _output));
688
+ }
689
+ throw err;
690
+ })
691
+ .finally(() => {
692
+ this[kUnfreeze]();
693
+ this.parsed = tmpParsed;
694
+ });
695
+ }
696
+ else {
697
+ if (__classPrivateFieldGet(this, _parseFn_1))
698
+ __classPrivateFieldGet(this, _parseFn_1).call(this, __classPrivateFieldGet(this, _exitError), parsed, __classPrivateFieldGet(this, _output));
699
+ this[kUnfreeze]();
700
+ this.parsed = tmpParsed;
701
+ }
702
+ return parsed;
703
+ }
704
+ parseAsync(args, shortCircuit, _parseFn) {
705
+ const maybePromise = this.parse(args, shortCircuit, _parseFn);
706
+ if (!isPromise(maybePromise)) {
707
+ return Promise.resolve(maybePromise);
708
+ }
709
+ else {
710
+ return maybePromise;
711
+ }
712
+ }
713
+ parseSync(args, shortCircuit, _parseFn) {
714
+ const maybePromise = this.parse(args, shortCircuit, _parseFn);
715
+ if (isPromise(maybePromise)) {
716
+ throw new YError('.parseSync() must not be used with asynchronous builders, handlers, or middleware');
717
+ }
718
+ return maybePromise;
719
+ }
720
+ parserConfiguration(config) {
721
+ argsert('<object>', [config], arguments.length);
722
+ __classPrivateFieldSet(this, _parserConfig, config);
723
+ return this;
724
+ }
725
+ pkgConf(key, rootPath) {
726
+ argsert('<string> [string]', [key, rootPath], arguments.length);
727
+ let conf = null;
728
+ const obj = this[kPkgUp](rootPath || __classPrivateFieldGet(this, _cwd));
729
+ if (obj[key] && typeof obj[key] === 'object') {
730
+ conf = applyExtends(obj[key], rootPath || __classPrivateFieldGet(this, _cwd), this[kGetParserConfiguration]()['deep-merge-config'] || false, __classPrivateFieldGet(this, _shim_1));
731
+ __classPrivateFieldGet(this, _options).configObjects = (__classPrivateFieldGet(this, _options).configObjects || []).concat(conf);
732
+ }
733
+ return this;
734
+ }
735
+ positional(key, opts) {
736
+ argsert('<string> <object>', [key, opts], arguments.length);
735
737
  const supportedOpts = [
736
738
  'default',
737
739
  'defaultDescription',
@@ -752,9 +754,9 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
752
754
  accept = false;
753
755
  return accept;
754
756
  });
755
- const fullCommand = context.fullCommands[context.fullCommands.length - 1];
757
+ const fullCommand = __classPrivateFieldGet(this, _context).fullCommands[__classPrivateFieldGet(this, _context).fullCommands.length - 1];
756
758
  const parseOptions = fullCommand
757
- ? command.cmdToParseOptions(fullCommand)
759
+ ? __classPrivateFieldGet(this, _command).cmdToParseOptions(fullCommand)
758
760
  : {
759
761
  array: [],
760
762
  alias: {},
@@ -772,125 +774,144 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
772
774
  opts[pk] = parseOption[key];
773
775
  }
774
776
  });
775
- self.group(key, usage.getPositionalGroupName());
776
- return self.option(key, opts);
777
- };
778
- self.group = function group(opts, groupName) {
779
- argsert('<string|array> <string>', [opts, groupName], arguments.length);
780
- const existing = preservedGroups[groupName] || groups[groupName];
781
- if (preservedGroups[groupName]) {
782
- delete preservedGroups[groupName];
777
+ this.group(key, __classPrivateFieldGet(this, _usage).getPositionalGroupName());
778
+ return this.option(key, opts);
779
+ }
780
+ recommendCommands(recommend = true) {
781
+ argsert('[boolean]', [recommend], arguments.length);
782
+ __classPrivateFieldSet(this, _recommendCommands, recommend);
783
+ return this;
784
+ }
785
+ required(keys, max, msg) {
786
+ return this.demand(keys, max, msg);
787
+ }
788
+ require(keys, max, msg) {
789
+ return this.demand(keys, max, msg);
790
+ }
791
+ requiresArg(keys) {
792
+ argsert('<array|string|object> [number]', [keys], arguments.length);
793
+ if (typeof keys === 'string' && __classPrivateFieldGet(this, _options).narg[keys]) {
794
+ return this;
783
795
  }
784
- const seen = {};
785
- groups[groupName] = (existing || []).concat(opts).filter(key => {
786
- if (seen[key])
787
- return false;
788
- return (seen[key] = true);
789
- });
790
- return self;
791
- };
792
- self.getGroups = () => Object.assign({}, groups, preservedGroups);
793
- self.env = function (prefix) {
794
- argsert('[string|boolean]', [prefix], arguments.length);
795
- if (prefix === false)
796
- delete options.envPrefix;
797
- else
798
- options.envPrefix = prefix || '';
799
- return self;
800
- };
801
- self.wrap = function (cols) {
802
- argsert('<number|null|undefined>', [cols], arguments.length);
803
- usage.wrap(cols);
804
- return self;
805
- };
806
- let strict = false;
807
- self.strict = function (enabled) {
808
- argsert('[boolean]', [enabled], arguments.length);
809
- strict = enabled !== false;
810
- return self;
811
- };
812
- self.getStrict = () => strict;
813
- let strictCommands = false;
814
- self.strictCommands = function (enabled) {
815
- argsert('[boolean]', [enabled], arguments.length);
816
- strictCommands = enabled !== false;
817
- return self;
818
- };
819
- self.getStrictCommands = () => strictCommands;
820
- let strictOptions = false;
821
- self.strictOptions = function (enabled) {
822
- argsert('[boolean]', [enabled], arguments.length);
823
- strictOptions = enabled !== false;
824
- return self;
825
- };
826
- self.getStrictOptions = () => strictOptions;
827
- let parserConfig = {};
828
- self.parserConfiguration = function parserConfiguration(config) {
829
- argsert('<object>', [config], arguments.length);
830
- parserConfig = config;
831
- return self;
832
- };
833
- self.getParserConfiguration = () => parserConfig;
834
- self.getHelp = async function () {
835
- hasOutput = true;
836
- if (!usage.hasCachedHelpMessage()) {
837
- if (!self.parsed) {
838
- const parse = self._parseArgs(processArgs, undefined, undefined, 0, true);
796
+ else {
797
+ this[kPopulateParserHintSingleValueDictionary](this.requiresArg.bind(this), 'narg', keys, NaN);
798
+ }
799
+ return this;
800
+ }
801
+ showCompletionScript($0, cmd) {
802
+ argsert('[string] [string]', [$0, cmd], arguments.length);
803
+ $0 = $0 || this.$0;
804
+ __classPrivateFieldGet(this, _logger).log(__classPrivateFieldGet(this, _completion).generateCompletionScript($0, cmd || __classPrivateFieldGet(this, _completionCommand) || 'completion'));
805
+ return this;
806
+ }
807
+ showHelp(level) {
808
+ argsert('[string|function]', [level], arguments.length);
809
+ __classPrivateFieldSet(this, _hasOutput, true);
810
+ if (!__classPrivateFieldGet(this, _usage).hasCachedHelpMessage()) {
811
+ if (!this.parsed) {
812
+ const parse = this[kRunYargsParserAndExecuteCommands](__classPrivateFieldGet(this, _processArgs), undefined, undefined, 0, true);
839
813
  if (isPromise(parse)) {
840
- return parse.then(() => {
841
- return usage.help();
814
+ parse.then(() => {
815
+ __classPrivateFieldGet(this, _usage).showHelp(level);
842
816
  });
817
+ return this;
843
818
  }
844
819
  }
845
- if (command.hasDefaultCommand()) {
846
- context.resets++;
847
- command.runDefaultBuilderOn(self);
820
+ const builderResponse = __classPrivateFieldGet(this, _command).runDefaultBuilderOn(this);
821
+ if (isPromise(builderResponse)) {
822
+ builderResponse.then(() => {
823
+ __classPrivateFieldGet(this, _usage).showHelp(level);
824
+ });
825
+ return this;
826
+ }
827
+ }
828
+ __classPrivateFieldGet(this, _usage).showHelp(level);
829
+ return this;
830
+ }
831
+ scriptName(scriptName) {
832
+ this.customScriptName = true;
833
+ this.$0 = scriptName;
834
+ return this;
835
+ }
836
+ showHelpOnFail(enabled, message) {
837
+ argsert('[boolean|string] [string]', [enabled, message], arguments.length);
838
+ __classPrivateFieldGet(this, _usage).showHelpOnFail(enabled, message);
839
+ return this;
840
+ }
841
+ showVersion(level) {
842
+ argsert('[string|function]', [level], arguments.length);
843
+ __classPrivateFieldGet(this, _usage).showVersion(level);
844
+ return this;
845
+ }
846
+ skipValidation(keys) {
847
+ argsert('<array|string>', [keys], arguments.length);
848
+ this[kPopulateParserHintArray]('skipValidation', keys);
849
+ return this;
850
+ }
851
+ strict(enabled) {
852
+ argsert('[boolean]', [enabled], arguments.length);
853
+ __classPrivateFieldSet(this, _strict, enabled !== false);
854
+ return this;
855
+ }
856
+ strictCommands(enabled) {
857
+ argsert('[boolean]', [enabled], arguments.length);
858
+ __classPrivateFieldSet(this, _strictCommands, enabled !== false);
859
+ return this;
860
+ }
861
+ strictOptions(enabled) {
862
+ argsert('[boolean]', [enabled], arguments.length);
863
+ __classPrivateFieldSet(this, _strictOptions, enabled !== false);
864
+ return this;
865
+ }
866
+ string(key) {
867
+ argsert('<array|string>', [key], arguments.length);
868
+ this[kPopulateParserHintArray]('string', key);
869
+ return this;
870
+ }
871
+ terminalWidth() {
872
+ argsert([], 0);
873
+ return __classPrivateFieldGet(this, _shim_1).process.stdColumns;
874
+ }
875
+ updateLocale(obj) {
876
+ return this.updateStrings(obj);
877
+ }
878
+ updateStrings(obj) {
879
+ argsert('<object>', [obj], arguments.length);
880
+ __classPrivateFieldSet(this, _detectLocale, false);
881
+ __classPrivateFieldGet(this, _shim_1).y18n.updateLocale(obj);
882
+ return this;
883
+ }
884
+ usage(msg, description, builder, handler) {
885
+ argsert('<string|null|undefined> [string|boolean] [function|object] [function]', [msg, description, builder, handler], arguments.length);
886
+ if (description !== undefined) {
887
+ assertNotStrictEqual(msg, null, __classPrivateFieldGet(this, _shim_1));
888
+ if ((msg || '').match(/^\$0( |$)/)) {
889
+ return this.command(msg, description, builder, handler);
890
+ }
891
+ else {
892
+ throw new YError('.usage() description must start with $0 if being used as alias for .command()');
848
893
  }
849
894
  }
850
- return usage.help();
851
- };
852
- self.showHelp = function (level) {
853
- argsert('[string|function]', [level], arguments.length);
854
- hasOutput = true;
855
- if (!usage.hasCachedHelpMessage()) {
856
- if (!self.parsed) {
857
- const parse = self._parseArgs(processArgs, undefined, undefined, 0, true);
858
- if (isPromise(parse)) {
859
- parse.then(() => {
860
- usage.showHelp(level);
861
- });
862
- return self;
863
- }
864
- }
865
- if (command.hasDefaultCommand()) {
866
- context.resets++;
867
- command.runDefaultBuilderOn(self);
868
- }
895
+ else {
896
+ __classPrivateFieldGet(this, _usage).usage(msg);
897
+ return this;
869
898
  }
870
- usage.showHelp(level);
871
- return self;
872
- };
873
- self.showVersion = function (level) {
874
- argsert('[string|function]', [level], arguments.length);
875
- usage.showVersion(level);
876
- return self;
877
- };
878
- let versionOpt = null;
879
- self.version = function version(opt, msg, ver) {
899
+ }
900
+ version(opt, msg, ver) {
880
901
  const defaultVersionOpt = 'version';
881
902
  argsert('[boolean|string] [string] [string]', [opt, msg, ver], arguments.length);
882
- if (versionOpt) {
883
- deleteFromParserHintObject(versionOpt);
884
- usage.version(undefined);
885
- versionOpt = null;
903
+ if (__classPrivateFieldGet(this, _versionOpt)) {
904
+ this[kDeleteFromParserHintObject](__classPrivateFieldGet(this, _versionOpt));
905
+ __classPrivateFieldGet(this, _usage).version(undefined);
906
+ __classPrivateFieldSet(this, _versionOpt, null);
886
907
  }
887
908
  if (arguments.length === 0) {
888
- ver = guessVersion();
909
+ ver = this[kGuessVersion]();
889
910
  opt = defaultVersionOpt;
890
911
  }
891
912
  else if (arguments.length === 1) {
892
913
  if (opt === false) {
893
- return self;
914
+ return this;
894
915
  }
895
916
  ver = opt;
896
917
  opt = defaultVersionOpt;
@@ -899,274 +920,492 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
899
920
  ver = msg;
900
921
  msg = undefined;
901
922
  }
902
- versionOpt = typeof opt === 'string' ? opt : defaultVersionOpt;
903
- msg = msg || usage.deferY18nLookup('Show version number');
904
- usage.version(ver || undefined);
905
- self.boolean(versionOpt);
906
- self.describe(versionOpt, msg);
907
- return self;
908
- };
909
- function guessVersion() {
910
- const obj = pkgUp();
911
- return obj.version || 'unknown';
923
+ __classPrivateFieldSet(this, _versionOpt, typeof opt === 'string' ? opt : defaultVersionOpt);
924
+ msg = msg || __classPrivateFieldGet(this, _usage).deferY18nLookup('Show version number');
925
+ __classPrivateFieldGet(this, _usage).version(ver || undefined);
926
+ this.boolean(__classPrivateFieldGet(this, _versionOpt));
927
+ this.describe(__classPrivateFieldGet(this, _versionOpt), msg);
928
+ return this;
912
929
  }
913
- let helpOpt = null;
914
- self.addHelpOpt = self.help = function addHelpOpt(opt, msg) {
915
- const defaultHelpOpt = 'help';
916
- argsert('[string|boolean] [string]', [opt, msg], arguments.length);
917
- if (helpOpt) {
918
- deleteFromParserHintObject(helpOpt);
919
- helpOpt = null;
930
+ wrap(cols) {
931
+ argsert('<number|null|undefined>', [cols], arguments.length);
932
+ __classPrivateFieldGet(this, _usage).wrap(cols);
933
+ return this;
934
+ }
935
+ [(_command = new WeakMap(), _cwd = new WeakMap(), _context = new WeakMap(), _completion = new WeakMap(), _completionCommand = new WeakMap(), _defaultShowHiddenOpt = new WeakMap(), _exitError = new WeakMap(), _detectLocale = new WeakMap(), _exitProcess = new WeakMap(), _frozens = new WeakMap(), _globalMiddleware = new WeakMap(), _groups = new WeakMap(), _hasOutput = new WeakMap(), _helpOpt = new WeakMap(), _logger = new WeakMap(), _output = new WeakMap(), _options = new WeakMap(), _parentRequire = new WeakMap(), _parserConfig = new WeakMap(), _parseFn_1 = new WeakMap(), _parseContext = new WeakMap(), _pkgs = new WeakMap(), _preservedGroups = new WeakMap(), _processArgs = new WeakMap(), _recommendCommands = new WeakMap(), _shim_1 = new WeakMap(), _strict = new WeakMap(), _strictCommands = new WeakMap(), _strictOptions = new WeakMap(), _usage = new WeakMap(), _versionOpt = new WeakMap(), _validation = new WeakMap(), kCopyDoubleDash)](argv) {
936
+ if (!argv._ || !argv['--'])
937
+ return argv;
938
+ argv._.push.apply(argv._, argv['--']);
939
+ try {
940
+ delete argv['--'];
920
941
  }
921
- if (arguments.length === 1) {
922
- if (opt === false)
923
- return self;
942
+ catch (_err) { }
943
+ return argv;
944
+ }
945
+ [kCreateLogger]() {
946
+ return {
947
+ log: (...args) => {
948
+ if (!this[kHasParseCallback]())
949
+ console.log(...args);
950
+ __classPrivateFieldSet(this, _hasOutput, true);
951
+ if (__classPrivateFieldGet(this, _output).length)
952
+ __classPrivateFieldSet(this, _output, __classPrivateFieldGet(this, _output) + '\n');
953
+ __classPrivateFieldSet(this, _output, __classPrivateFieldGet(this, _output) + args.join(' '));
954
+ },
955
+ error: (...args) => {
956
+ if (!this[kHasParseCallback]())
957
+ console.error(...args);
958
+ __classPrivateFieldSet(this, _hasOutput, true);
959
+ if (__classPrivateFieldGet(this, _output).length)
960
+ __classPrivateFieldSet(this, _output, __classPrivateFieldGet(this, _output) + '\n');
961
+ __classPrivateFieldSet(this, _output, __classPrivateFieldGet(this, _output) + args.join(' '));
962
+ },
963
+ };
964
+ }
965
+ [kDeleteFromParserHintObject](optionKey) {
966
+ objectKeys(__classPrivateFieldGet(this, _options)).forEach((hintKey) => {
967
+ if (((key) => key === 'configObjects')(hintKey))
968
+ return;
969
+ const hint = __classPrivateFieldGet(this, _options)[hintKey];
970
+ if (Array.isArray(hint)) {
971
+ if (~hint.indexOf(optionKey))
972
+ hint.splice(hint.indexOf(optionKey), 1);
973
+ }
974
+ else if (typeof hint === 'object') {
975
+ delete hint[optionKey];
976
+ }
977
+ });
978
+ delete __classPrivateFieldGet(this, _usage).getDescriptions()[optionKey];
979
+ }
980
+ [kFreeze]() {
981
+ __classPrivateFieldGet(this, _frozens).push({
982
+ options: __classPrivateFieldGet(this, _options),
983
+ configObjects: __classPrivateFieldGet(this, _options).configObjects.slice(0),
984
+ exitProcess: __classPrivateFieldGet(this, _exitProcess),
985
+ groups: __classPrivateFieldGet(this, _groups),
986
+ strict: __classPrivateFieldGet(this, _strict),
987
+ strictCommands: __classPrivateFieldGet(this, _strictCommands),
988
+ strictOptions: __classPrivateFieldGet(this, _strictOptions),
989
+ completionCommand: __classPrivateFieldGet(this, _completionCommand),
990
+ output: __classPrivateFieldGet(this, _output),
991
+ exitError: __classPrivateFieldGet(this, _exitError),
992
+ hasOutput: __classPrivateFieldGet(this, _hasOutput),
993
+ parsed: this.parsed,
994
+ parseFn: __classPrivateFieldGet(this, _parseFn_1),
995
+ parseContext: __classPrivateFieldGet(this, _parseContext),
996
+ });
997
+ __classPrivateFieldGet(this, _usage).freeze();
998
+ __classPrivateFieldGet(this, _validation).freeze();
999
+ __classPrivateFieldGet(this, _command).freeze();
1000
+ __classPrivateFieldGet(this, _globalMiddleware).freeze();
1001
+ }
1002
+ [kGetDollarZero]() {
1003
+ let $0 = '';
1004
+ let default$0;
1005
+ if (/\b(node|iojs|electron)(\.exe)?$/.test(__classPrivateFieldGet(this, _shim_1).process.argv()[0])) {
1006
+ default$0 = __classPrivateFieldGet(this, _shim_1).process.argv().slice(1, 2);
924
1007
  }
925
- helpOpt = typeof opt === 'string' ? opt : defaultHelpOpt;
926
- self.boolean(helpOpt);
927
- self.describe(helpOpt, msg || usage.deferY18nLookup('Show help'));
928
- return self;
929
- };
930
- const defaultShowHiddenOpt = 'show-hidden';
931
- options.showHiddenOpt = defaultShowHiddenOpt;
932
- self.addShowHiddenOpt = self.showHidden = function addShowHiddenOpt(opt, msg) {
933
- argsert('[string|boolean] [string]', [opt, msg], arguments.length);
934
- if (arguments.length === 1) {
935
- if (opt === false)
936
- return self;
1008
+ else {
1009
+ default$0 = __classPrivateFieldGet(this, _shim_1).process.argv().slice(0, 1);
937
1010
  }
938
- const showHiddenOpt = typeof opt === 'string' ? opt : defaultShowHiddenOpt;
939
- self.boolean(showHiddenOpt);
940
- self.describe(showHiddenOpt, msg || usage.deferY18nLookup('Show hidden options'));
941
- options.showHiddenOpt = showHiddenOpt;
942
- return self;
943
- };
944
- self.hide = function hide(key) {
945
- argsert('<string>', [key], arguments.length);
946
- options.hiddenOptions.push(key);
947
- return self;
948
- };
949
- self.showHelpOnFail = function showHelpOnFail(enabled, message) {
950
- argsert('[boolean|string] [string]', [enabled, message], arguments.length);
951
- usage.showHelpOnFail(enabled, message);
952
- return self;
953
- };
954
- let exitProcess = true;
955
- self.exitProcess = function (enabled = true) {
956
- argsert('[boolean]', [enabled], arguments.length);
957
- exitProcess = enabled;
958
- return self;
959
- };
960
- self.getExitProcess = () => exitProcess;
961
- self.showCompletionScript = function ($0, cmd) {
962
- argsert('[string] [string]', [$0, cmd], arguments.length);
963
- $0 = $0 || self.$0;
964
- _logger.log(completion.generateCompletionScript($0, cmd || completionCommand || 'completion'));
965
- return self;
966
- };
967
- self.getCompletion = async function (args, done) {
968
- argsert('<array> [function]', [args, done], arguments.length);
969
- if (!done) {
970
- return new Promise((resolve, reject) => {
971
- completion.getCompletion(args, (err, completions) => {
972
- if (err)
973
- reject(err);
974
- else
975
- resolve(completions);
976
- });
1011
+ $0 = default$0
1012
+ .map(x => {
1013
+ const b = this[kRebase](__classPrivateFieldGet(this, _cwd), x);
1014
+ return x.match(/^(\/|([a-zA-Z]:)?\\)/) && b.length < x.length ? b : x;
1015
+ })
1016
+ .join(' ')
1017
+ .trim();
1018
+ if (__classPrivateFieldGet(this, _shim_1).getEnv('_') &&
1019
+ __classPrivateFieldGet(this, _shim_1).getProcessArgvBin() === __classPrivateFieldGet(this, _shim_1).getEnv('_')) {
1020
+ $0 = __classPrivateFieldGet(this, _shim_1).getEnv('_')
1021
+ .replace(`${__classPrivateFieldGet(this, _shim_1).path.dirname(__classPrivateFieldGet(this, _shim_1).process.execPath())}/`, '');
1022
+ }
1023
+ return $0;
1024
+ }
1025
+ [kGetParserConfiguration]() {
1026
+ return __classPrivateFieldGet(this, _parserConfig);
1027
+ }
1028
+ [kGuessLocale]() {
1029
+ if (!__classPrivateFieldGet(this, _detectLocale))
1030
+ return;
1031
+ const locale = __classPrivateFieldGet(this, _shim_1).getEnv('LC_ALL') ||
1032
+ __classPrivateFieldGet(this, _shim_1).getEnv('LC_MESSAGES') ||
1033
+ __classPrivateFieldGet(this, _shim_1).getEnv('LANG') ||
1034
+ __classPrivateFieldGet(this, _shim_1).getEnv('LANGUAGE') ||
1035
+ 'en_US';
1036
+ this.locale(locale.replace(/[.:].*/, ''));
1037
+ }
1038
+ [kGuessVersion]() {
1039
+ const obj = this[kPkgUp]();
1040
+ return obj.version || 'unknown';
1041
+ }
1042
+ [kParsePositionalNumbers](argv) {
1043
+ const args = argv['--'] ? argv['--'] : argv._;
1044
+ for (let i = 0, arg; (arg = args[i]) !== undefined; i++) {
1045
+ if (__classPrivateFieldGet(this, _shim_1).Parser.looksLikeNumber(arg) &&
1046
+ Number.isSafeInteger(Math.floor(parseFloat(`${arg}`)))) {
1047
+ args[i] = Number(arg);
1048
+ }
1049
+ }
1050
+ return argv;
1051
+ }
1052
+ [kPkgUp](rootPath) {
1053
+ const npath = rootPath || '*';
1054
+ if (__classPrivateFieldGet(this, _pkgs)[npath])
1055
+ return __classPrivateFieldGet(this, _pkgs)[npath];
1056
+ let obj = {};
1057
+ try {
1058
+ let startDir = rootPath || __classPrivateFieldGet(this, _shim_1).mainFilename;
1059
+ if (!rootPath && __classPrivateFieldGet(this, _shim_1).path.extname(startDir)) {
1060
+ startDir = __classPrivateFieldGet(this, _shim_1).path.dirname(startDir);
1061
+ }
1062
+ const pkgJsonPath = __classPrivateFieldGet(this, _shim_1).findUp(startDir, (dir, names) => {
1063
+ if (names.includes('package.json')) {
1064
+ return 'package.json';
1065
+ }
1066
+ else {
1067
+ return undefined;
1068
+ }
1069
+ });
1070
+ assertNotStrictEqual(pkgJsonPath, undefined, __classPrivateFieldGet(this, _shim_1));
1071
+ obj = JSON.parse(__classPrivateFieldGet(this, _shim_1).readFileSync(pkgJsonPath, 'utf8'));
1072
+ }
1073
+ catch (_noop) { }
1074
+ __classPrivateFieldGet(this, _pkgs)[npath] = obj || {};
1075
+ return __classPrivateFieldGet(this, _pkgs)[npath];
1076
+ }
1077
+ [kPopulateParserHintArray](type, keys) {
1078
+ keys = [].concat(keys);
1079
+ keys.forEach(key => {
1080
+ key = this[kSanitizeKey](key);
1081
+ __classPrivateFieldGet(this, _options)[type].push(key);
1082
+ });
1083
+ }
1084
+ [kPopulateParserHintSingleValueDictionary](builder, type, key, value) {
1085
+ this[kPopulateParserHintDictionary](builder, type, key, value, (type, key, value) => {
1086
+ __classPrivateFieldGet(this, _options)[type][key] = value;
1087
+ });
1088
+ }
1089
+ [kPopulateParserHintArrayDictionary](builder, type, key, value) {
1090
+ this[kPopulateParserHintDictionary](builder, type, key, value, (type, key, value) => {
1091
+ __classPrivateFieldGet(this, _options)[type][key] = (__classPrivateFieldGet(this, _options)[type][key] || []).concat(value);
1092
+ });
1093
+ }
1094
+ [kPopulateParserHintDictionary](builder, type, key, value, singleKeyHandler) {
1095
+ if (Array.isArray(key)) {
1096
+ key.forEach(k => {
1097
+ builder(k, value);
977
1098
  });
978
1099
  }
1100
+ else if (((key) => typeof key === 'object')(key)) {
1101
+ for (const k of objectKeys(key)) {
1102
+ builder(k, key[k]);
1103
+ }
1104
+ }
979
1105
  else {
980
- return completion.getCompletion(args, done);
1106
+ singleKeyHandler(type, this[kSanitizeKey](key), value);
981
1107
  }
982
- };
983
- self.locale = function (locale) {
984
- argsert('[string]', [locale], arguments.length);
985
- if (!locale) {
986
- guessLocale();
987
- return y18n.getLocale();
1108
+ }
1109
+ [kSanitizeKey](key) {
1110
+ if (key === '__proto__')
1111
+ return '___proto___';
1112
+ return key;
1113
+ }
1114
+ [kSetKey](key, set) {
1115
+ this[kPopulateParserHintSingleValueDictionary](this[kSetKey].bind(this), 'key', key, set);
1116
+ return this;
1117
+ }
1118
+ [kUnfreeze]() {
1119
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1120
+ const frozen = __classPrivateFieldGet(this, _frozens).pop();
1121
+ assertNotStrictEqual(frozen, undefined, __classPrivateFieldGet(this, _shim_1));
1122
+ let configObjects;
1123
+ (_a = this, _b = this, _c = this, _d = this, _e = this, _f = this, _g = this, _h = this, _j = this, _k = this, _l = this, _m = this, {
1124
+ options: ({ set value(_o) { __classPrivateFieldSet(_a, _options, _o); } }).value,
1125
+ configObjects,
1126
+ exitProcess: ({ set value(_o) { __classPrivateFieldSet(_b, _exitProcess, _o); } }).value,
1127
+ groups: ({ set value(_o) { __classPrivateFieldSet(_c, _groups, _o); } }).value,
1128
+ output: ({ set value(_o) { __classPrivateFieldSet(_d, _output, _o); } }).value,
1129
+ exitError: ({ set value(_o) { __classPrivateFieldSet(_e, _exitError, _o); } }).value,
1130
+ hasOutput: ({ set value(_o) { __classPrivateFieldSet(_f, _hasOutput, _o); } }).value,
1131
+ parsed: this.parsed,
1132
+ strict: ({ set value(_o) { __classPrivateFieldSet(_g, _strict, _o); } }).value,
1133
+ strictCommands: ({ set value(_o) { __classPrivateFieldSet(_h, _strictCommands, _o); } }).value,
1134
+ strictOptions: ({ set value(_o) { __classPrivateFieldSet(_j, _strictOptions, _o); } }).value,
1135
+ completionCommand: ({ set value(_o) { __classPrivateFieldSet(_k, _completionCommand, _o); } }).value,
1136
+ parseFn: ({ set value(_o) { __classPrivateFieldSet(_l, _parseFn_1, _o); } }).value,
1137
+ parseContext: ({ set value(_o) { __classPrivateFieldSet(_m, _parseContext, _o); } }).value,
1138
+ } = frozen);
1139
+ __classPrivateFieldGet(this, _options).configObjects = configObjects;
1140
+ __classPrivateFieldGet(this, _usage).unfreeze();
1141
+ __classPrivateFieldGet(this, _validation).unfreeze();
1142
+ __classPrivateFieldGet(this, _command).unfreeze();
1143
+ __classPrivateFieldGet(this, _globalMiddleware).unfreeze();
1144
+ }
1145
+ [kValidateAsync](validation, argv) {
1146
+ return maybeAsyncResult(argv, result => {
1147
+ validation(result);
1148
+ return result;
1149
+ });
1150
+ }
1151
+ getInternalMethods() {
1152
+ return {
1153
+ getCommandInstance: this[kGetCommandInstance].bind(this),
1154
+ getContext: this[kGetContext].bind(this),
1155
+ getHasOutput: this[kGetHasOutput].bind(this),
1156
+ getLoggerInstance: this[kGetLoggerInstance].bind(this),
1157
+ getParseContext: this[kGetParseContext].bind(this),
1158
+ getParserConfiguration: this[kGetParserConfiguration].bind(this),
1159
+ getUsageInstance: this[kGetUsageInstance].bind(this),
1160
+ getValidationInstance: this[kGetValidationInstance].bind(this),
1161
+ hasParseCallback: this[kHasParseCallback].bind(this),
1162
+ postProcess: this[kPostProcess].bind(this),
1163
+ reset: this[kReset].bind(this),
1164
+ runValidation: this[kRunValidation].bind(this),
1165
+ runYargsParserAndExecuteCommands: this[kRunYargsParserAndExecuteCommands].bind(this),
1166
+ setHasOutput: this[kSetHasOutput].bind(this),
1167
+ };
1168
+ }
1169
+ [kGetCommandInstance]() {
1170
+ return __classPrivateFieldGet(this, _command);
1171
+ }
1172
+ [kGetContext]() {
1173
+ return __classPrivateFieldGet(this, _context);
1174
+ }
1175
+ [kGetHasOutput]() {
1176
+ return __classPrivateFieldGet(this, _hasOutput);
1177
+ }
1178
+ [kGetLoggerInstance]() {
1179
+ return __classPrivateFieldGet(this, _logger);
1180
+ }
1181
+ [kGetParseContext]() {
1182
+ return __classPrivateFieldGet(this, _parseContext) || {};
1183
+ }
1184
+ [kGetUsageInstance]() {
1185
+ return __classPrivateFieldGet(this, _usage);
1186
+ }
1187
+ [kGetValidationInstance]() {
1188
+ return __classPrivateFieldGet(this, _validation);
1189
+ }
1190
+ [kHasParseCallback]() {
1191
+ return !!__classPrivateFieldGet(this, _parseFn_1);
1192
+ }
1193
+ [kPostProcess](argv, populateDoubleDash, calledFromCommand, runGlobalMiddleware) {
1194
+ if (calledFromCommand)
1195
+ return argv;
1196
+ if (isPromise(argv))
1197
+ return argv;
1198
+ if (!populateDoubleDash) {
1199
+ argv = this[kCopyDoubleDash](argv);
988
1200
  }
989
- detectLocale = false;
990
- y18n.setLocale(locale);
991
- return self;
992
- };
993
- self.updateStrings = self.updateLocale = function (obj) {
994
- argsert('<object>', [obj], arguments.length);
995
- detectLocale = false;
996
- y18n.updateLocale(obj);
997
- return self;
998
- };
999
- let detectLocale = true;
1000
- self.detectLocale = function (detect) {
1001
- argsert('<boolean>', [detect], arguments.length);
1002
- detectLocale = detect;
1003
- return self;
1004
- };
1005
- self.getDetectLocale = () => detectLocale;
1006
- const _logger = {
1007
- log(...args) {
1008
- if (!self._hasParseCallback())
1009
- console.log(...args);
1010
- hasOutput = true;
1011
- if (output.length)
1012
- output += '\n';
1013
- output += args.join(' ');
1014
- },
1015
- error(...args) {
1016
- if (!self._hasParseCallback())
1017
- console.error(...args);
1018
- hasOutput = true;
1019
- if (output.length)
1020
- output += '\n';
1021
- output += args.join(' ');
1022
- },
1023
- };
1024
- self._getLoggerInstance = () => _logger;
1025
- self._hasOutput = () => hasOutput;
1026
- self._setHasOutput = () => {
1027
- hasOutput = true;
1028
- };
1029
- let recommendCommands;
1030
- self.recommendCommands = function (recommend = true) {
1031
- argsert('[boolean]', [recommend], arguments.length);
1032
- recommendCommands = recommend;
1033
- return self;
1034
- };
1035
- self.getUsageInstance = () => usage;
1036
- self.getValidationInstance = () => validation;
1037
- self.getCommandInstance = () => command;
1038
- self.terminalWidth = () => {
1039
- argsert([], 0);
1040
- return shim.process.stdColumns;
1041
- };
1042
- Object.defineProperty(self, 'argv', {
1043
- get: () => {
1044
- return self.parse();
1045
- },
1046
- enumerable: true,
1047
- });
1048
- self._parseArgs = function parseArgs(args, shortCircuit, calledFromCommand, commandIndex = 0, helpOnly = false) {
1201
+ const parsePositionalNumbers = this[kGetParserConfiguration]()['parse-positional-numbers'] ||
1202
+ this[kGetParserConfiguration]()['parse-positional-numbers'] === undefined;
1203
+ if (parsePositionalNumbers) {
1204
+ argv = this[kParsePositionalNumbers](argv);
1205
+ }
1206
+ if (runGlobalMiddleware) {
1207
+ argv = applyMiddleware(argv, this, __classPrivateFieldGet(this, _globalMiddleware).getMiddleware(), false);
1208
+ }
1209
+ return argv;
1210
+ }
1211
+ [kReset](aliases = {}) {
1212
+ __classPrivateFieldSet(this, _options, __classPrivateFieldGet(this, _options) || {});
1213
+ const tmpOptions = {};
1214
+ tmpOptions.local = __classPrivateFieldGet(this, _options).local ? __classPrivateFieldGet(this, _options).local : [];
1215
+ tmpOptions.configObjects = __classPrivateFieldGet(this, _options).configObjects
1216
+ ? __classPrivateFieldGet(this, _options).configObjects
1217
+ : [];
1218
+ const localLookup = {};
1219
+ tmpOptions.local.forEach(l => {
1220
+ localLookup[l] = true;
1221
+ (aliases[l] || []).forEach(a => {
1222
+ localLookup[a] = true;
1223
+ });
1224
+ });
1225
+ Object.assign(__classPrivateFieldGet(this, _preservedGroups), Object.keys(__classPrivateFieldGet(this, _groups)).reduce((acc, groupName) => {
1226
+ const keys = __classPrivateFieldGet(this, _groups)[groupName].filter(key => !(key in localLookup));
1227
+ if (keys.length > 0) {
1228
+ acc[groupName] = keys;
1229
+ }
1230
+ return acc;
1231
+ }, {}));
1232
+ __classPrivateFieldSet(this, _groups, {});
1233
+ const arrayOptions = [
1234
+ 'array',
1235
+ 'boolean',
1236
+ 'string',
1237
+ 'skipValidation',
1238
+ 'count',
1239
+ 'normalize',
1240
+ 'number',
1241
+ 'hiddenOptions',
1242
+ ];
1243
+ const objectOptions = [
1244
+ 'narg',
1245
+ 'key',
1246
+ 'alias',
1247
+ 'default',
1248
+ 'defaultDescription',
1249
+ 'config',
1250
+ 'choices',
1251
+ 'demandedOptions',
1252
+ 'demandedCommands',
1253
+ 'deprecatedOptions',
1254
+ ];
1255
+ arrayOptions.forEach(k => {
1256
+ tmpOptions[k] = (__classPrivateFieldGet(this, _options)[k] || []).filter((k) => !localLookup[k]);
1257
+ });
1258
+ objectOptions.forEach((k) => {
1259
+ tmpOptions[k] = objFilter(__classPrivateFieldGet(this, _options)[k], k => !localLookup[k]);
1260
+ });
1261
+ tmpOptions.envPrefix = __classPrivateFieldGet(this, _options).envPrefix;
1262
+ __classPrivateFieldSet(this, _options, tmpOptions);
1263
+ __classPrivateFieldSet(this, _usage, __classPrivateFieldGet(this, _usage) ? __classPrivateFieldGet(this, _usage).reset(localLookup)
1264
+ : Usage(this, __classPrivateFieldGet(this, _shim_1)));
1265
+ __classPrivateFieldSet(this, _validation, __classPrivateFieldGet(this, _validation) ? __classPrivateFieldGet(this, _validation).reset(localLookup)
1266
+ : Validation(this, __classPrivateFieldGet(this, _usage), __classPrivateFieldGet(this, _shim_1)));
1267
+ __classPrivateFieldSet(this, _command, __classPrivateFieldGet(this, _command) ? __classPrivateFieldGet(this, _command).reset()
1268
+ : Command(__classPrivateFieldGet(this, _usage), __classPrivateFieldGet(this, _validation), __classPrivateFieldGet(this, _globalMiddleware), __classPrivateFieldGet(this, _shim_1)));
1269
+ if (!__classPrivateFieldGet(this, _completion))
1270
+ __classPrivateFieldSet(this, _completion, Completion(this, __classPrivateFieldGet(this, _usage), __classPrivateFieldGet(this, _command), __classPrivateFieldGet(this, _shim_1)));
1271
+ __classPrivateFieldGet(this, _globalMiddleware).reset();
1272
+ __classPrivateFieldSet(this, _completionCommand, null);
1273
+ __classPrivateFieldSet(this, _output, '');
1274
+ __classPrivateFieldSet(this, _exitError, null);
1275
+ __classPrivateFieldSet(this, _hasOutput, false);
1276
+ this.parsed = false;
1277
+ return this;
1278
+ }
1279
+ [kRebase](base, dir) {
1280
+ return __classPrivateFieldGet(this, _shim_1).path.relative(base, dir);
1281
+ }
1282
+ [kRunYargsParserAndExecuteCommands](args, shortCircuit, calledFromCommand, commandIndex = 0, helpOnly = false) {
1049
1283
  let skipValidation = !!calledFromCommand || helpOnly;
1050
- args = args || processArgs;
1051
- options.__ = y18n.__;
1052
- options.configuration = self.getParserConfiguration();
1053
- const populateDoubleDash = !!options.configuration['populate--'];
1054
- const config = Object.assign({}, options.configuration, {
1284
+ args = args || __classPrivateFieldGet(this, _processArgs);
1285
+ __classPrivateFieldGet(this, _options).__ = __classPrivateFieldGet(this, _shim_1).y18n.__;
1286
+ __classPrivateFieldGet(this, _options).configuration = this[kGetParserConfiguration]();
1287
+ const populateDoubleDash = !!__classPrivateFieldGet(this, _options).configuration['populate--'];
1288
+ const config = Object.assign({}, __classPrivateFieldGet(this, _options).configuration, {
1055
1289
  'populate--': true,
1056
1290
  });
1057
- const parsed = shim.Parser.detailed(args, Object.assign({}, options, {
1058
- configuration: Object.assign({ 'parse-positional-numbers': false }, config),
1291
+ const parsed = __classPrivateFieldGet(this, _shim_1).Parser.detailed(args, Object.assign({}, __classPrivateFieldGet(this, _options), {
1292
+ configuration: { 'parse-positional-numbers': false, ...config },
1059
1293
  }));
1060
- let argv = parsed.argv;
1294
+ const argv = Object.assign(parsed.argv, __classPrivateFieldGet(this, _parseContext));
1061
1295
  let argvPromise = undefined;
1062
- if (parseContext)
1063
- argv = Object.assign({}, argv, parseContext);
1064
1296
  const aliases = parsed.aliases;
1065
- argv.$0 = self.$0;
1066
- self.parsed = parsed;
1297
+ let helpOptSet = false;
1298
+ let versionOptSet = false;
1299
+ Object.keys(argv).forEach(key => {
1300
+ if (key === __classPrivateFieldGet(this, _helpOpt) && argv[key]) {
1301
+ helpOptSet = true;
1302
+ }
1303
+ else if (key === __classPrivateFieldGet(this, _versionOpt) && argv[key]) {
1304
+ versionOptSet = true;
1305
+ }
1306
+ });
1307
+ argv.$0 = this.$0;
1308
+ this.parsed = parsed;
1067
1309
  if (commandIndex === 0) {
1068
- usage.clearCachedHelpMessage();
1310
+ __classPrivateFieldGet(this, _usage).clearCachedHelpMessage();
1069
1311
  }
1070
1312
  try {
1071
- guessLocale();
1313
+ this[kGuessLocale]();
1072
1314
  if (shortCircuit) {
1073
- return self._postProcess(argv, populateDoubleDash, !!calledFromCommand, false);
1315
+ return this[kPostProcess](argv, populateDoubleDash, !!calledFromCommand, false);
1074
1316
  }
1075
- if (helpOpt) {
1076
- const helpCmds = [helpOpt]
1077
- .concat(aliases[helpOpt] || [])
1317
+ if (__classPrivateFieldGet(this, _helpOpt)) {
1318
+ const helpCmds = [__classPrivateFieldGet(this, _helpOpt)]
1319
+ .concat(aliases[__classPrivateFieldGet(this, _helpOpt)] || [])
1078
1320
  .filter(k => k.length > 1);
1079
1321
  if (~helpCmds.indexOf('' + argv._[argv._.length - 1])) {
1080
1322
  argv._.pop();
1081
- argv[helpOpt] = true;
1323
+ helpOptSet = true;
1082
1324
  }
1083
1325
  }
1084
- const handlerKeys = command.getCommands();
1085
- const requestCompletions = completion.completionKey in argv;
1086
- const skipRecommendation = argv[helpOpt] || requestCompletions || helpOnly;
1326
+ const handlerKeys = __classPrivateFieldGet(this, _command).getCommands();
1327
+ const requestCompletions = __classPrivateFieldGet(this, _completion).completionKey in argv;
1328
+ const skipRecommendation = helpOptSet || requestCompletions || helpOnly;
1087
1329
  if (argv._.length) {
1088
1330
  if (handlerKeys.length) {
1089
1331
  let firstUnknownCommand;
1090
1332
  for (let i = commandIndex || 0, cmd; argv._[i] !== undefined; i++) {
1091
1333
  cmd = String(argv._[i]);
1092
- if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) {
1093
- const innerArgv = command.runCommand(cmd, self, parsed, i + 1, helpOnly);
1094
- return self._postProcess(innerArgv, populateDoubleDash, !!calledFromCommand, false);
1334
+ if (~handlerKeys.indexOf(cmd) && cmd !== __classPrivateFieldGet(this, _completionCommand)) {
1335
+ const innerArgv = __classPrivateFieldGet(this, _command).runCommand(cmd, this, parsed, i + 1, helpOnly, helpOptSet || versionOptSet || helpOnly);
1336
+ return this[kPostProcess](innerArgv, populateDoubleDash, !!calledFromCommand, false);
1095
1337
  }
1096
- else if (!firstUnknownCommand && cmd !== completionCommand) {
1338
+ else if (!firstUnknownCommand &&
1339
+ cmd !== __classPrivateFieldGet(this, _completionCommand)) {
1097
1340
  firstUnknownCommand = cmd;
1098
1341
  break;
1099
1342
  }
1100
1343
  }
1101
- if (command.hasDefaultCommand() && !skipRecommendation) {
1102
- const innerArgv = command.runCommand(null, self, parsed, 0, helpOnly);
1103
- return self._postProcess(innerArgv, populateDoubleDash, !!calledFromCommand, false);
1104
- }
1105
- if (recommendCommands && firstUnknownCommand && !skipRecommendation) {
1106
- validation.recommendCommands(firstUnknownCommand, handlerKeys);
1344
+ if (!__classPrivateFieldGet(this, _command).hasDefaultCommand() && __classPrivateFieldGet(this, _recommendCommands) &&
1345
+ firstUnknownCommand &&
1346
+ !skipRecommendation) {
1347
+ __classPrivateFieldGet(this, _validation).recommendCommands(firstUnknownCommand, handlerKeys);
1107
1348
  }
1108
1349
  }
1109
- if (completionCommand &&
1110
- ~argv._.indexOf(completionCommand) &&
1350
+ if (__classPrivateFieldGet(this, _completionCommand) &&
1351
+ ~argv._.indexOf(__classPrivateFieldGet(this, _completionCommand)) &&
1111
1352
  !requestCompletions) {
1112
- if (exitProcess)
1353
+ if (__classPrivateFieldGet(this, _exitProcess))
1113
1354
  setBlocking(true);
1114
- self.showCompletionScript();
1115
- self.exit(0);
1355
+ this.showCompletionScript();
1356
+ this.exit(0);
1116
1357
  }
1117
1358
  }
1118
- else if (command.hasDefaultCommand() && !skipRecommendation) {
1119
- const innerArgv = command.runCommand(null, self, parsed, 0, helpOnly);
1120
- return self._postProcess(innerArgv, populateDoubleDash, !!calledFromCommand, false);
1359
+ if (__classPrivateFieldGet(this, _command).hasDefaultCommand() && !skipRecommendation) {
1360
+ const innerArgv = __classPrivateFieldGet(this, _command).runCommand(null, this, parsed, 0, helpOnly, helpOptSet || versionOptSet || helpOnly);
1361
+ return this[kPostProcess](innerArgv, populateDoubleDash, !!calledFromCommand, false);
1121
1362
  }
1122
1363
  if (requestCompletions) {
1123
- if (exitProcess)
1364
+ if (__classPrivateFieldGet(this, _exitProcess))
1124
1365
  setBlocking(true);
1125
1366
  args = [].concat(args);
1126
- const completionArgs = args.slice(args.indexOf(`--${completion.completionKey}`) + 1);
1127
- completion.getCompletion(completionArgs, (err, completions) => {
1367
+ const completionArgs = args.slice(args.indexOf(`--${__classPrivateFieldGet(this, _completion).completionKey}`) + 1);
1368
+ __classPrivateFieldGet(this, _completion).getCompletion(completionArgs, (err, completions) => {
1128
1369
  if (err)
1129
1370
  throw new YError(err.message);
1130
1371
  (completions || []).forEach(completion => {
1131
- _logger.log(completion);
1372
+ __classPrivateFieldGet(this, _logger).log(completion);
1132
1373
  });
1133
- self.exit(0);
1374
+ this.exit(0);
1134
1375
  });
1135
- return self._postProcess(argv, !populateDoubleDash, !!calledFromCommand, false);
1376
+ return this[kPostProcess](argv, !populateDoubleDash, !!calledFromCommand, false);
1136
1377
  }
1137
- if (!hasOutput) {
1138
- Object.keys(argv).forEach(key => {
1139
- if (key === helpOpt && argv[key]) {
1140
- if (exitProcess)
1141
- setBlocking(true);
1142
- skipValidation = true;
1143
- self.showHelp('log');
1144
- self.exit(0);
1145
- }
1146
- else if (key === versionOpt && argv[key]) {
1147
- if (exitProcess)
1148
- setBlocking(true);
1149
- skipValidation = true;
1150
- usage.showVersion('log');
1151
- self.exit(0);
1152
- }
1153
- });
1378
+ if (!__classPrivateFieldGet(this, _hasOutput)) {
1379
+ if (helpOptSet) {
1380
+ if (__classPrivateFieldGet(this, _exitProcess))
1381
+ setBlocking(true);
1382
+ skipValidation = true;
1383
+ this.showHelp('log');
1384
+ this.exit(0);
1385
+ }
1386
+ else if (versionOptSet) {
1387
+ if (__classPrivateFieldGet(this, _exitProcess))
1388
+ setBlocking(true);
1389
+ skipValidation = true;
1390
+ __classPrivateFieldGet(this, _usage).showVersion('log');
1391
+ this.exit(0);
1392
+ }
1154
1393
  }
1155
- if (!skipValidation && options.skipValidation.length > 0) {
1156
- skipValidation = Object.keys(argv).some(key => options.skipValidation.indexOf(key) >= 0 && argv[key] === true);
1394
+ if (!skipValidation && __classPrivateFieldGet(this, _options).skipValidation.length > 0) {
1395
+ skipValidation = Object.keys(argv).some(key => __classPrivateFieldGet(this, _options).skipValidation.indexOf(key) >= 0 && argv[key] === true);
1157
1396
  }
1158
1397
  if (!skipValidation) {
1159
1398
  if (parsed.error)
1160
1399
  throw new YError(parsed.error.message);
1161
1400
  if (!requestCompletions) {
1162
- const validation = self._runValidation(aliases, {}, parsed.error);
1401
+ const validation = this[kRunValidation](aliases, {}, parsed.error);
1163
1402
  if (!calledFromCommand) {
1164
- argvPromise = applyMiddleware(argv, self, globalMiddleware.getMiddleware(), true);
1403
+ argvPromise = applyMiddleware(argv, this, __classPrivateFieldGet(this, _globalMiddleware).getMiddleware(), true);
1165
1404
  }
1166
- argvPromise = validateAsync(validation, argvPromise !== null && argvPromise !== void 0 ? argvPromise : argv);
1405
+ argvPromise = this[kValidateAsync](validation, argvPromise !== null && argvPromise !== void 0 ? argvPromise : argv);
1167
1406
  if (isPromise(argvPromise) && !calledFromCommand) {
1168
1407
  argvPromise = argvPromise.then(() => {
1169
- return applyMiddleware(argv, self, globalMiddleware.getMiddleware(), false);
1408
+ return applyMiddleware(argv, this, __classPrivateFieldGet(this, _globalMiddleware).getMiddleware(), false);
1170
1409
  });
1171
1410
  }
1172
1411
  }
@@ -1174,95 +1413,40 @@ function Yargs(processArgs = [], cwd = shim.process.cwd(), parentRequire) {
1174
1413
  }
1175
1414
  catch (err) {
1176
1415
  if (err instanceof YError)
1177
- usage.fail(err.message, err);
1416
+ __classPrivateFieldGet(this, _usage).fail(err.message, err);
1178
1417
  else
1179
1418
  throw err;
1180
1419
  }
1181
- return self._postProcess(argvPromise !== null && argvPromise !== void 0 ? argvPromise : argv, populateDoubleDash, !!calledFromCommand, true);
1182
- };
1183
- function validateAsync(validation, argv) {
1184
- return maybeAsyncResult(argv, result => {
1185
- validation(result);
1186
- return result;
1187
- });
1420
+ return this[kPostProcess](argvPromise !== null && argvPromise !== void 0 ? argvPromise : argv, populateDoubleDash, !!calledFromCommand, true);
1188
1421
  }
1189
- self._postProcess = function (argv, populateDoubleDash, calledFromCommand, runGlobalMiddleware) {
1190
- if (calledFromCommand)
1191
- return argv;
1192
- if (isPromise(argv))
1193
- return argv;
1194
- if (!populateDoubleDash) {
1195
- argv = self._copyDoubleDash(argv);
1196
- }
1197
- const parsePositionalNumbers = self.getParserConfiguration()['parse-positional-numbers'] ||
1198
- self.getParserConfiguration()['parse-positional-numbers'] === undefined;
1199
- if (parsePositionalNumbers) {
1200
- argv = self._parsePositionalNumbers(argv);
1201
- }
1202
- if (runGlobalMiddleware) {
1203
- argv = applyMiddleware(argv, self, globalMiddleware.getMiddleware(), false);
1204
- }
1205
- return argv;
1206
- };
1207
- self._copyDoubleDash = function (argv) {
1208
- if (!argv._ || !argv['--'])
1209
- return argv;
1210
- argv._.push.apply(argv._, argv['--']);
1211
- try {
1212
- delete argv['--'];
1213
- }
1214
- catch (_err) { }
1215
- return argv;
1216
- };
1217
- self._parsePositionalNumbers = function (argv) {
1218
- const args = argv['--'] ? argv['--'] : argv._;
1219
- for (let i = 0, arg; (arg = args[i]) !== undefined; i++) {
1220
- if (shim.Parser.looksLikeNumber(arg) &&
1221
- Number.isSafeInteger(Math.floor(parseFloat(`${arg}`)))) {
1222
- args[i] = Number(arg);
1223
- }
1224
- }
1225
- return argv;
1226
- };
1227
- self._runValidation = function runValidation(aliases, positionalMap, parseErrors, isDefaultCommand = false) {
1228
- aliases = Object.assign({}, aliases);
1229
- positionalMap = Object.assign({}, positionalMap);
1230
- const demandedOptions = Object.assign({}, self.getDemandedOptions());
1422
+ [kRunValidation](aliases, positionalMap, parseErrors, isDefaultCommand) {
1423
+ aliases = { ...aliases };
1424
+ positionalMap = { ...positionalMap };
1425
+ const demandedOptions = { ...this.getDemandedOptions() };
1231
1426
  return (argv) => {
1232
1427
  if (parseErrors)
1233
1428
  throw new YError(parseErrors.message);
1234
- validation.nonOptionCount(argv);
1235
- validation.requiredArguments(argv, demandedOptions);
1429
+ __classPrivateFieldGet(this, _validation).nonOptionCount(argv);
1430
+ __classPrivateFieldGet(this, _validation).requiredArguments(argv, demandedOptions);
1236
1431
  let failedStrictCommands = false;
1237
- if (strictCommands) {
1238
- failedStrictCommands = validation.unknownCommands(argv);
1432
+ if (__classPrivateFieldGet(this, _strictCommands)) {
1433
+ failedStrictCommands = __classPrivateFieldGet(this, _validation).unknownCommands(argv);
1239
1434
  }
1240
- if (strict && !failedStrictCommands) {
1241
- validation.unknownArguments(argv, aliases, positionalMap, isDefaultCommand);
1435
+ if (__classPrivateFieldGet(this, _strict) && !failedStrictCommands) {
1436
+ __classPrivateFieldGet(this, _validation).unknownArguments(argv, aliases, positionalMap, !!isDefaultCommand);
1242
1437
  }
1243
- else if (strictOptions) {
1244
- validation.unknownArguments(argv, aliases, {}, false, false);
1438
+ else if (__classPrivateFieldGet(this, _strictOptions)) {
1439
+ __classPrivateFieldGet(this, _validation).unknownArguments(argv, aliases, {}, false, false);
1245
1440
  }
1246
- validation.limitedChoices(argv);
1247
- validation.implications(argv);
1248
- validation.conflicting(argv);
1441
+ __classPrivateFieldGet(this, _validation).limitedChoices(argv);
1442
+ __classPrivateFieldGet(this, _validation).implications(argv);
1443
+ __classPrivateFieldGet(this, _validation).conflicting(argv);
1249
1444
  };
1250
- };
1251
- function guessLocale() {
1252
- if (!detectLocale)
1253
- return;
1254
- const locale = shim.getEnv('LC_ALL') ||
1255
- shim.getEnv('LC_MESSAGES') ||
1256
- shim.getEnv('LANG') ||
1257
- shim.getEnv('LANGUAGE') ||
1258
- 'en_US';
1259
- self.locale(locale.replace(/[.:].*/, ''));
1260
1445
  }
1261
- self.help();
1262
- self.version();
1263
- return self;
1446
+ [kSetHasOutput]() {
1447
+ __classPrivateFieldSet(this, _hasOutput, true);
1448
+ }
1264
1449
  }
1265
- export const rebase = (base, dir) => shim.path.relative(base, dir);
1266
1450
  export function isYargsInstance(y) {
1267
- return !!y && typeof y._parseArgs === 'function';
1451
+ return !!y && typeof y.getInternalMethods === 'function';
1268
1452
  }