burgee 0.0.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +28 -1
  2. package/dist/agent.d.ts +19 -0
  3. package/dist/agent.js +25 -0
  4. package/dist/brand.d.ts +186 -0
  5. package/dist/brand.js +232 -0
  6. package/dist/cli.d.ts +62 -0
  7. package/dist/cli.js +121 -0
  8. package/dist/commander-argument.d.ts +22 -0
  9. package/dist/commander-argument.js +72 -0
  10. package/dist/commander-command.d.ts +355 -0
  11. package/dist/commander-command.js +1621 -0
  12. package/dist/commander-error.d.ts +10 -0
  13. package/dist/commander-error.js +20 -0
  14. package/dist/commander-help.d.ts +67 -0
  15. package/dist/commander-help.js +319 -0
  16. package/dist/commander-option.d.ts +58 -0
  17. package/dist/commander-option.js +164 -0
  18. package/dist/commander-suggest.d.ts +2 -0
  19. package/dist/commander-suggest.js +59 -0
  20. package/dist/commander.d.ts +18 -0
  21. package/dist/commander.js +12 -0
  22. package/dist/completions.d.ts +39 -0
  23. package/dist/completions.js +224 -0
  24. package/dist/config.d.ts +28 -0
  25. package/dist/config.js +98 -0
  26. package/dist/contrast.d.ts +70 -0
  27. package/dist/contrast.js +93 -0
  28. package/dist/dev.d.ts +47 -0
  29. package/dist/dev.js +132 -0
  30. package/dist/execute.d.ts +118 -0
  31. package/dist/execute.js +469 -0
  32. package/dist/exit-code.d.ts +18 -0
  33. package/dist/exit-code.js +12 -0
  34. package/dist/help.d.ts +34 -0
  35. package/dist/help.js +187 -0
  36. package/dist/index.d.ts +16 -1
  37. package/dist/index.js +9 -2
  38. package/dist/manifest.d.ts +207 -0
  39. package/dist/manifest.js +66 -0
  40. package/dist/mcp.d.ts +52 -0
  41. package/dist/mcp.js +124 -0
  42. package/dist/names.d.ts +5 -0
  43. package/dist/names.js +6 -0
  44. package/dist/pkg.d.ts +5 -0
  45. package/dist/pkg.js +21 -0
  46. package/dist/precedence.d.ts +55 -0
  47. package/dist/precedence.js +100 -0
  48. package/dist/runtime.d.ts +39 -0
  49. package/dist/runtime.js +24 -0
  50. package/dist/schema.d.ts +79 -0
  51. package/dist/schema.js +116 -0
  52. package/dist/testing-helpers.d.ts +79 -0
  53. package/dist/testing-helpers.js +145 -0
  54. package/dist/testing.d.ts +10 -0
  55. package/dist/testing.js +3 -0
  56. package/dist/validate.d.ts +27 -0
  57. package/dist/validate.js +133 -0
  58. package/dist/yargs-burgee.d.ts +50 -0
  59. package/dist/yargs-burgee.js +104 -0
  60. package/dist/yargs-cliui.d.ts +56 -0
  61. package/dist/yargs-cliui.js +421 -0
  62. package/dist/yargs-command.d.ts +82 -0
  63. package/dist/yargs-command.js +414 -0
  64. package/dist/yargs-completion.d.ts +41 -0
  65. package/dist/yargs-completion.js +271 -0
  66. package/dist/yargs-factory.d.ts +193 -0
  67. package/dist/yargs-factory.js +1606 -0
  68. package/dist/yargs-helpers.d.ts +6 -0
  69. package/dist/yargs-helpers.js +2 -0
  70. package/dist/yargs-middleware.d.ts +32 -0
  71. package/dist/yargs-middleware.js +81 -0
  72. package/dist/yargs-parser.d.ts +41 -0
  73. package/dist/yargs-parser.js +929 -0
  74. package/dist/yargs-shim.d.ts +54 -0
  75. package/dist/yargs-shim.js +84 -0
  76. package/dist/yargs-usage.d.ts +42 -0
  77. package/dist/yargs-usage.js +479 -0
  78. package/dist/yargs-utils.d.ts +33 -0
  79. package/dist/yargs-utils.js +209 -0
  80. package/dist/yargs-validation.d.ts +26 -0
  81. package/dist/yargs-validation.js +261 -0
  82. package/dist/yargs-y18n.d.ts +21 -0
  83. package/dist/yargs-y18n.js +117 -0
  84. package/dist/yargs.d.ts +6 -0
  85. package/dist/yargs.js +8 -0
  86. package/locales/be.json +46 -0
  87. package/locales/cs.json +51 -0
  88. package/locales/de.json +46 -0
  89. package/locales/en.json +55 -0
  90. package/locales/es.json +46 -0
  91. package/locales/fi.json +49 -0
  92. package/locales/fr.json +53 -0
  93. package/locales/he.json +55 -0
  94. package/locales/hi.json +49 -0
  95. package/locales/hu.json +46 -0
  96. package/locales/id.json +50 -0
  97. package/locales/it.json +46 -0
  98. package/locales/ja.json +51 -0
  99. package/locales/ka.json +55 -0
  100. package/locales/ko.json +49 -0
  101. package/locales/nb.json +44 -0
  102. package/locales/nl.json +49 -0
  103. package/locales/nn.json +44 -0
  104. package/locales/pirate.json +13 -0
  105. package/locales/pl.json +49 -0
  106. package/locales/pt.json +45 -0
  107. package/locales/pt_BR.json +48 -0
  108. package/locales/ru.json +51 -0
  109. package/locales/th.json +46 -0
  110. package/locales/tr.json +48 -0
  111. package/locales/uk_UA.json +51 -0
  112. package/locales/uz.json +52 -0
  113. package/locales/zh_CN.json +48 -0
  114. package/locales/zh_TW.json +51 -0
  115. package/package.json +62 -9
  116. package/dist/index.js.map +0 -1
@@ -0,0 +1,1606 @@
1
+ var _a;
2
+ import { ExitCode } from './exit-code.js';
3
+ import { Manifest } from './manifest.js';
4
+ import { serveMcp } from './mcp.js';
5
+ import { schemaOf } from './schema.js';
6
+ import { projectManifest, render } from './yargs-burgee.js';
7
+ import { command as Command, isCommandBuilderCallback } from './yargs-command.js';
8
+ import { completion as Completion } from './yargs-completion.js';
9
+ import { applyMiddleware, GlobalMiddleware } from './yargs-middleware.js';
10
+ import { tokenizeArgString } from './yargs-parser.js';
11
+ import { usage as Usage } from './yargs-usage.js';
12
+ import { applyExtends, argsert, isPromise, maybeAsyncResult, objectKeys, objFilter, setBlocking, YError } from './yargs-utils.js';
13
+ import { validation as Validation } from './yargs-validation.js';
14
+ const DEFAULT_LOCALE = 'en_US';
15
+ export function YargsFactory(shim) {
16
+ return (processArgs = [], cwd = shim.process.cwd(), parentRequire) => {
17
+ const yargs = new YargsInstance(processArgs, cwd, parentRequire, shim);
18
+ Object.defineProperty(yargs, 'argv', {
19
+ get: () => yargs.parse(),
20
+ enumerable: true,
21
+ });
22
+ yargs.help();
23
+ yargs.version();
24
+ return yargs;
25
+ };
26
+ }
27
+ export class YargsInstance {
28
+ $0;
29
+ argv;
30
+ customScriptName = false;
31
+ parsed = false;
32
+ #command;
33
+ #cwd;
34
+ #context = { commands: [], fullCommands: [] };
35
+ #completion = null;
36
+ #completionCommand = null;
37
+ #defaultShowHiddenOpt = 'show-hidden';
38
+ #exitError = null;
39
+ #detectLocale = true;
40
+ #emittedWarnings = {};
41
+ #exitProcess = true;
42
+ #frozens = [];
43
+ #globalMiddleware;
44
+ #groups = {};
45
+ #hasOutput = false;
46
+ #helpOpt = null;
47
+ #isGlobalContext = true;
48
+ #logger;
49
+ #output = '';
50
+ #options;
51
+ #parentRequire;
52
+ #parserConfig = {};
53
+ #parseFn = null;
54
+ #parseContext = null;
55
+ #pkgs = {};
56
+ #preservedGroups = {};
57
+ #processArgs;
58
+ #recommendCommands = false;
59
+ #shim;
60
+ #strict = false;
61
+ #strictCommands = false;
62
+ #strictOptions = false;
63
+ #usage;
64
+ #usageConfig = {};
65
+ #versionOpt = null;
66
+ #validation;
67
+ #burgee = undefined;
68
+ #effects = undefined;
69
+ #manifest = undefined;
70
+ constructor(processArgs = [], cwd, parentRequire, shim) {
71
+ this.#shim = shim;
72
+ this.#processArgs = processArgs;
73
+ this.#cwd = cwd;
74
+ this.#parentRequire = parentRequire;
75
+ this.#globalMiddleware = new GlobalMiddleware(this);
76
+ this.$0 = this.#getDollarZero();
77
+ this.#options = undefined;
78
+ this.#usage = undefined;
79
+ this.#validation = undefined;
80
+ this.#command = undefined;
81
+ this.#reset();
82
+ this.#options.showHiddenOpt = this.#defaultShowHiddenOpt;
83
+ this.#logger = this.#createLogger();
84
+ this.#shim.y18n.setLocale(DEFAULT_LOCALE);
85
+ }
86
+ addHelpOpt(opt, msg) {
87
+ const defaultHelpOpt = 'help';
88
+ argsert('[string|boolean] [string]', [opt, msg], arguments.length);
89
+ if (this.#helpOpt) {
90
+ this.#deleteFromParserHintObject(this.#helpOpt);
91
+ this.#helpOpt = null;
92
+ }
93
+ if (opt === false && msg === undefined)
94
+ return this;
95
+ this.#helpOpt = typeof opt === 'string' ? opt : defaultHelpOpt;
96
+ this.boolean(this.#helpOpt);
97
+ this.describe(this.#helpOpt, msg || this.#usage.deferY18nLookup('Show help'));
98
+ return this;
99
+ }
100
+ help(opt, msg) {
101
+ return this.addHelpOpt(opt, msg);
102
+ }
103
+ addShowHiddenOpt(opt, msg) {
104
+ argsert('[string|boolean] [string]', [opt, msg], arguments.length);
105
+ if (opt === false && msg === undefined)
106
+ return this;
107
+ const showHiddenOpt = typeof opt === 'string' ? opt : this.#defaultShowHiddenOpt;
108
+ this.boolean(showHiddenOpt);
109
+ this.describe(showHiddenOpt, msg || this.#usage.deferY18nLookup('Show hidden options'));
110
+ this.#options.showHiddenOpt = showHiddenOpt;
111
+ return this;
112
+ }
113
+ showHidden(opt, msg) {
114
+ return this.addShowHiddenOpt(opt, msg);
115
+ }
116
+ alias(key, value) {
117
+ argsert('<object|string|array> [string|array]', [key, value], arguments.length);
118
+ this.#populateParserHintArrayDictionary(this.alias.bind(this), 'alias', key, value);
119
+ return this;
120
+ }
121
+ array(keys) {
122
+ argsert('<array|string>', [keys], arguments.length);
123
+ this.#populateParserHintArray('array', keys);
124
+ this.#trackManuallySetKeys(keys);
125
+ return this;
126
+ }
127
+ boolean(keys) {
128
+ argsert('<array|string>', [keys], arguments.length);
129
+ this.#populateParserHintArray('boolean', keys);
130
+ this.#trackManuallySetKeys(keys);
131
+ return this;
132
+ }
133
+ check(f, global) {
134
+ argsert('<function> [boolean]', [f, global], arguments.length);
135
+ this.middleware((argv, _yargs) => maybeAsyncResult(() => f(argv, _yargs.getOptions()), (result) => {
136
+ if (!result)
137
+ this.#usage.fail(this.#shim.y18n.__('Argument check failed: %s', f.toString()));
138
+ else if (typeof result === 'string' || result instanceof Error)
139
+ this.#usage.fail(result.toString(), result);
140
+ return argv;
141
+ }, (err) => {
142
+ this.#usage.fail(err.message ? err.message : err.toString(), err);
143
+ return argv;
144
+ }), false, global);
145
+ return this;
146
+ }
147
+ choices(key, value) {
148
+ argsert('<object|string|array> [string|array]', [key, value], arguments.length);
149
+ this.#populateParserHintArrayDictionary(this.choices.bind(this), 'choices', key, value);
150
+ return this;
151
+ }
152
+ coerce(keys, value) {
153
+ argsert('<object|string|array> [function]', [keys, value], arguments.length);
154
+ if (Array.isArray(keys)) {
155
+ if (!value)
156
+ throw new YError('coerce callback must be provided');
157
+ for (const key of keys)
158
+ this.coerce(key, value);
159
+ return this;
160
+ }
161
+ else if (typeof keys === 'object') {
162
+ for (const key of Object.keys(keys))
163
+ this.coerce(key, keys[key]);
164
+ return this;
165
+ }
166
+ if (!value)
167
+ throw new YError('coerce callback must be provided');
168
+ const coerceKey = keys;
169
+ this.#options.key[coerceKey] = true;
170
+ this.#globalMiddleware.addCoerceMiddleware((argv, yargs) => {
171
+ const coerceKeyAliases = yargs.getAliases()[coerceKey] ?? [];
172
+ const argvKeys = [coerceKey, ...coerceKeyAliases].filter((key) => Object.prototype.hasOwnProperty.call(argv, key));
173
+ if (argvKeys.length === 0)
174
+ return argv;
175
+ return maybeAsyncResult(() => value(argv[argvKeys[0]]), (result) => {
176
+ argvKeys.forEach((key) => {
177
+ argv[key] = result;
178
+ });
179
+ return argv;
180
+ }, (err) => {
181
+ throw new YError(err.message);
182
+ });
183
+ }, coerceKey);
184
+ return this;
185
+ }
186
+ conflicts(key1, key2) {
187
+ argsert('<string|object> [string|array]', [key1, key2], arguments.length);
188
+ this.#validation.conflicts(key1, key2);
189
+ return this;
190
+ }
191
+ config(key = 'config', msg, parseFn) {
192
+ argsert('[object|string] [string|function] [function]', [key, msg, parseFn], arguments.length);
193
+ if (typeof key === 'object' && !Array.isArray(key)) {
194
+ key = applyExtends(key, this.#cwd, this.#getParserConfiguration()['deep-merge-config'] || false);
195
+ this.#options.configObjects = (this.#options.configObjects || []).concat(key);
196
+ return this;
197
+ }
198
+ if (typeof msg === 'function') {
199
+ parseFn = msg;
200
+ msg = undefined;
201
+ }
202
+ this.describe(key, msg || this.#usage.deferY18nLookup('Path to JSON config file'));
203
+ (Array.isArray(key) ? key : [key]).forEach((k) => {
204
+ this.#options.config[k] = parseFn || true;
205
+ });
206
+ return this;
207
+ }
208
+ completion(cmd, desc, fn) {
209
+ argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length);
210
+ if (typeof desc === 'function') {
211
+ fn = desc;
212
+ desc = undefined;
213
+ }
214
+ this.#completionCommand = cmd || this.#completionCommand || 'completion';
215
+ if (!desc && desc !== false)
216
+ desc = 'generate completion script';
217
+ this.command(this.#completionCommand, desc);
218
+ if (fn)
219
+ this.#completion.registerFunction(fn);
220
+ return this;
221
+ }
222
+ command(cmd, description, builder, handler, middlewares, deprecated) {
223
+ argsert('<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]', [cmd, description, builder, handler, middlewares, deprecated], arguments.length);
224
+ this.#command.addHandler(cmd, description, builder, handler, middlewares, deprecated);
225
+ return this;
226
+ }
227
+ commands(cmd, description, builder, handler, middlewares, deprecated) {
228
+ return this.command(cmd, description, builder, handler, middlewares, deprecated);
229
+ }
230
+ commandDir(dir, opts) {
231
+ argsert('<string> [object]', [dir, opts], arguments.length);
232
+ const req = this.#parentRequire || this.#shim.require;
233
+ this.#command.addDirectory(dir, req, this.#shim.getCallerFile(), opts);
234
+ return this;
235
+ }
236
+ count(keys) {
237
+ argsert('<array|string>', [keys], arguments.length);
238
+ this.#populateParserHintArray('count', keys);
239
+ this.#trackManuallySetKeys(keys);
240
+ return this;
241
+ }
242
+ default(key, value, defaultDescription) {
243
+ argsert('<object|string|array> [*] [string]', [key, value, defaultDescription], arguments.length);
244
+ if (defaultDescription) {
245
+ this.#shim.assert.strictEqual(typeof key, 'string');
246
+ this.#options.defaultDescription[key] = defaultDescription;
247
+ }
248
+ if (typeof value === 'function') {
249
+ this.#shim.assert.strictEqual(typeof key, 'string');
250
+ if (!this.#options.defaultDescription[key])
251
+ this.#options.defaultDescription[key] = this.#usage.functionDescription(value);
252
+ value = value.call();
253
+ }
254
+ this.#populateParserHintSingleValueDictionary(this.default.bind(this), 'default', key, value);
255
+ return this;
256
+ }
257
+ defaults(key, value, defaultDescription) {
258
+ return this.default(key, value, defaultDescription);
259
+ }
260
+ demandCommand(min = 1, max, minMsg, maxMsg) {
261
+ argsert('[number] [number|string] [string|null|undefined] [string|null|undefined]', [min, max, minMsg, maxMsg], arguments.length);
262
+ if (typeof max !== 'number') {
263
+ minMsg = max;
264
+ max = Infinity;
265
+ }
266
+ this.global('_', false);
267
+ this.#options.demandedCommands._ = { min, max, minMsg, maxMsg };
268
+ return this;
269
+ }
270
+ demand(keys, max, msg) {
271
+ if (Array.isArray(max)) {
272
+ max.forEach((key) => {
273
+ this.#shim.assert.notStrictEqual(msg, true);
274
+ this.demandOption(key, msg);
275
+ });
276
+ max = Infinity;
277
+ }
278
+ else if (typeof max !== 'number') {
279
+ msg = max;
280
+ max = Infinity;
281
+ }
282
+ if (typeof keys === 'number') {
283
+ this.#shim.assert.notStrictEqual(msg, true);
284
+ this.demandCommand(keys, max, msg, msg);
285
+ }
286
+ else if (Array.isArray(keys)) {
287
+ keys.forEach((key) => {
288
+ this.#shim.assert.notStrictEqual(msg, true);
289
+ this.demandOption(key, msg);
290
+ });
291
+ }
292
+ else if (typeof msg === 'string')
293
+ this.demandOption(keys, msg);
294
+ else if (msg === true || typeof msg === 'undefined')
295
+ this.demandOption(keys);
296
+ return this;
297
+ }
298
+ demandOption(keys, msg) {
299
+ argsert('<object|string|array> [string]', [keys, msg], arguments.length);
300
+ this.#populateParserHintSingleValueDictionary(this.demandOption.bind(this), 'demandedOptions', keys, msg);
301
+ return this;
302
+ }
303
+ deprecateOption(option, message) {
304
+ argsert('<string> [string|boolean]', [option, message], arguments.length);
305
+ this.#options.deprecatedOptions[option] = message;
306
+ return this;
307
+ }
308
+ describe(keys, description) {
309
+ argsert('<object|string|array> [string]', [keys, description], arguments.length);
310
+ this.#setKey(keys, true);
311
+ this.#usage.describe(keys, description);
312
+ return this;
313
+ }
314
+ detectLocale(detect) {
315
+ argsert('<boolean>', [detect], arguments.length);
316
+ this.#detectLocale = detect;
317
+ return this;
318
+ }
319
+ env(prefix) {
320
+ argsert('[string|boolean]', [prefix], arguments.length);
321
+ if (prefix === false)
322
+ delete this.#options.envPrefix;
323
+ else
324
+ this.#options.envPrefix = prefix || '';
325
+ return this;
326
+ }
327
+ epilogue(msg) {
328
+ argsert('<string>', [msg], arguments.length);
329
+ this.#usage.epilog(msg);
330
+ return this;
331
+ }
332
+ epilog(msg) {
333
+ return this.epilogue(msg);
334
+ }
335
+ example(cmd, description) {
336
+ argsert('<string|array> [string]', [cmd, description], arguments.length);
337
+ if (Array.isArray(cmd))
338
+ cmd.forEach((exampleParams) => this.example(...exampleParams));
339
+ else
340
+ this.#usage.example(cmd, description);
341
+ return this;
342
+ }
343
+ exit(code, err) {
344
+ this.#hasOutput = true;
345
+ this.#exitError = err;
346
+ const burgee = this.#burgee;
347
+ if (burgee !== undefined && code !== 0 && burgee.json)
348
+ this.#failureEnvelope(err);
349
+ if (burgee?.exit !== undefined) {
350
+ if (burgee.exited)
351
+ return;
352
+ burgee.exited = true;
353
+ burgee.exit(code === 0 ? ExitCode.OK : err instanceof YError || err === undefined || typeof err === 'string' ? ExitCode.USAGE : ExitCode.RUNTIME);
354
+ return;
355
+ }
356
+ if (this.#exitProcess)
357
+ this.#shim.process.exit(code);
358
+ }
359
+ exitProcess(enabled = true) {
360
+ argsert('[boolean]', [enabled], arguments.length);
361
+ this.#exitProcess = enabled;
362
+ return this;
363
+ }
364
+ fail(f) {
365
+ argsert('<function|boolean>', [f], arguments.length);
366
+ if (typeof f === 'boolean' && f !== false)
367
+ throw new YError("Invalid first argument. Expected function or boolean 'false'");
368
+ this.#usage.failFn(f);
369
+ return this;
370
+ }
371
+ getAliases() {
372
+ return this.parsed ? this.parsed.aliases : {};
373
+ }
374
+ async getCompletion(args, done) {
375
+ argsert('<array> [function]', [args, done], arguments.length);
376
+ if (!done) {
377
+ return new Promise((resolve, reject) => {
378
+ this.#completion.getCompletion(args, (err, completions) => {
379
+ if (err)
380
+ reject(err);
381
+ else
382
+ resolve(completions);
383
+ });
384
+ });
385
+ }
386
+ return this.#completion.getCompletion(args, done);
387
+ }
388
+ getDemandedOptions() {
389
+ argsert([], 0);
390
+ return this.#options.demandedOptions;
391
+ }
392
+ getDemandedCommands() {
393
+ argsert([], 0);
394
+ return this.#options.demandedCommands;
395
+ }
396
+ getDeprecatedOptions() {
397
+ argsert([], 0);
398
+ return this.#options.deprecatedOptions;
399
+ }
400
+ getDetectLocale() {
401
+ return this.#detectLocale;
402
+ }
403
+ getExitProcess() {
404
+ return this.#exitProcess;
405
+ }
406
+ getGroups() {
407
+ return Object.assign({}, this.#groups, this.#preservedGroups);
408
+ }
409
+ getHelp() {
410
+ this.#hasOutput = true;
411
+ if (!this.#usage.hasCachedHelpMessage()) {
412
+ if (!this.parsed) {
413
+ const parse = this.#runYargsParserAndExecuteCommands(this.#processArgs, undefined, undefined, 0, true);
414
+ if (isPromise(parse))
415
+ return parse.then(() => this.#usage.help());
416
+ }
417
+ const builderResponse = this.#command.runDefaultBuilderOn(this);
418
+ if (isPromise(builderResponse))
419
+ return builderResponse.then(() => this.#usage.help());
420
+ }
421
+ return Promise.resolve(this.#usage.help());
422
+ }
423
+ getOptions() {
424
+ return this.#options;
425
+ }
426
+ getStrict() {
427
+ return this.#strict;
428
+ }
429
+ getStrictCommands() {
430
+ return this.#strictCommands;
431
+ }
432
+ getStrictOptions() {
433
+ return this.#strictOptions;
434
+ }
435
+ global(globals, global) {
436
+ argsert('<string|array> [boolean]', [globals, global], arguments.length);
437
+ globals = [].concat(globals);
438
+ if (global !== false)
439
+ this.#options.local = this.#options.local.filter((l) => globals.indexOf(l) === -1);
440
+ else {
441
+ globals.forEach((g) => {
442
+ if (!this.#options.local.includes(g))
443
+ this.#options.local.push(g);
444
+ });
445
+ }
446
+ return this;
447
+ }
448
+ group(opts, groupName) {
449
+ argsert('<string|array> <string>', [opts, groupName], arguments.length);
450
+ const existing = this.#preservedGroups[groupName] || this.#groups[groupName];
451
+ if (this.#preservedGroups[groupName])
452
+ delete this.#preservedGroups[groupName];
453
+ const seen = {};
454
+ this.#groups[groupName] = (existing || []).concat(opts).filter((key) => {
455
+ if (seen[key])
456
+ return false;
457
+ return (seen[key] = true);
458
+ });
459
+ return this;
460
+ }
461
+ hide(key) {
462
+ argsert('<string>', [key], arguments.length);
463
+ this.#options.hiddenOptions.push(key);
464
+ return this;
465
+ }
466
+ implies(key, value) {
467
+ argsert('<string|object> [number|string|array]', [key, value], arguments.length);
468
+ this.#validation.implies(key, value);
469
+ return this;
470
+ }
471
+ locale(locale) {
472
+ argsert('[string]', [locale], arguments.length);
473
+ if (locale === undefined) {
474
+ this.#guessLocale();
475
+ return this.#shim.y18n.getLocale();
476
+ }
477
+ this.#detectLocale = false;
478
+ this.#shim.y18n.setLocale(locale);
479
+ return this;
480
+ }
481
+ middleware(callback, applyBeforeValidation, global) {
482
+ return this.#globalMiddleware.addMiddleware(callback, !!applyBeforeValidation, global);
483
+ }
484
+ nargs(key, value) {
485
+ argsert('<string|object|array> [number]', [key, value], arguments.length);
486
+ this.#populateParserHintSingleValueDictionary(this.nargs.bind(this), 'narg', key, value);
487
+ return this;
488
+ }
489
+ normalize(keys) {
490
+ argsert('<array|string>', [keys], arguments.length);
491
+ this.#populateParserHintArray('normalize', keys);
492
+ return this;
493
+ }
494
+ number(keys) {
495
+ argsert('<array|string>', [keys], arguments.length);
496
+ this.#populateParserHintArray('number', keys);
497
+ this.#trackManuallySetKeys(keys);
498
+ return this;
499
+ }
500
+ option(key, opt) {
501
+ argsert('<string|object> [object]', [key, opt], arguments.length);
502
+ if (typeof key === 'object') {
503
+ Object.keys(key).forEach((k) => {
504
+ this.options(k, key[k]);
505
+ });
506
+ }
507
+ else {
508
+ if (typeof opt !== 'object')
509
+ opt = {};
510
+ this.#trackManuallySetKeys(key);
511
+ if (this.#versionOpt && (key === 'version' || opt?.alias === 'version')) {
512
+ this.#emitWarning([
513
+ '"version" is a reserved word.',
514
+ 'Please do one of the following:',
515
+ '- Disable version with `yargs.version(false)` if using "version" as an option',
516
+ '- Use the built-in `yargs.version` method instead (if applicable)',
517
+ '- Use a different option key',
518
+ 'https://yargs.js.org/docs/#api-reference-version',
519
+ ].join('\n'), undefined, 'versionWarning');
520
+ }
521
+ this.#options.key[key] = true;
522
+ if (opt.alias)
523
+ this.alias(key, opt.alias);
524
+ const deprecate = opt.deprecate || opt.deprecated;
525
+ if (deprecate)
526
+ this.deprecateOption(key, deprecate);
527
+ const demand = opt.demand || opt.required || opt.require;
528
+ if (demand)
529
+ this.demand(key, demand);
530
+ if (opt.demandOption)
531
+ this.demandOption(key, typeof opt.demandOption === 'string' ? opt.demandOption : undefined);
532
+ if (opt.conflicts)
533
+ this.conflicts(key, opt.conflicts);
534
+ if ('default' in opt)
535
+ this.default(key, opt.default);
536
+ if (opt.implies !== undefined)
537
+ this.implies(key, opt.implies);
538
+ if (opt.nargs !== undefined)
539
+ this.nargs(key, opt.nargs);
540
+ if (opt.config)
541
+ this.config(key, opt.configParser);
542
+ if (opt.normalize)
543
+ this.normalize(key);
544
+ if (opt.choices)
545
+ this.choices(key, opt.choices);
546
+ if (opt.coerce)
547
+ this.coerce(key, opt.coerce);
548
+ if (opt.group)
549
+ this.group(key, opt.group);
550
+ if (opt.boolean || opt.type === 'boolean') {
551
+ this.boolean(key);
552
+ if (opt.alias)
553
+ this.boolean(opt.alias);
554
+ }
555
+ if (opt.array || opt.type === 'array') {
556
+ this.array(key);
557
+ if (opt.alias)
558
+ this.array(opt.alias);
559
+ }
560
+ if (opt.number || opt.type === 'number') {
561
+ this.number(key);
562
+ if (opt.alias)
563
+ this.number(opt.alias);
564
+ }
565
+ if (opt.string || opt.type === 'string') {
566
+ this.string(key);
567
+ if (opt.alias)
568
+ this.string(opt.alias);
569
+ }
570
+ if (opt.count || opt.type === 'count')
571
+ this.count(key);
572
+ if (typeof opt.global === 'boolean')
573
+ this.global(key, opt.global);
574
+ if (opt.defaultDescription)
575
+ this.#options.defaultDescription[key] = opt.defaultDescription;
576
+ if (opt.skipValidation)
577
+ this.skipValidation(key);
578
+ const desc = opt.describe || opt.description || opt.desc;
579
+ const descriptions = this.#usage.getDescriptions();
580
+ if (!Object.prototype.hasOwnProperty.call(descriptions, key) || typeof desc === 'string')
581
+ this.describe(key, desc);
582
+ if (opt.hidden)
583
+ this.hide(key);
584
+ if (opt.requiresArg)
585
+ this.requiresArg(key);
586
+ }
587
+ return this;
588
+ }
589
+ options(key, opt) {
590
+ return this.option(key, opt);
591
+ }
592
+ parse(args, shortCircuit, _parseFn) {
593
+ argsert('[string|array] [function|boolean|object] [function]', [args, shortCircuit, _parseFn], arguments.length);
594
+ if (shortCircuit === true)
595
+ return this.#parse(args, shortCircuit, _parseFn);
596
+ const before = this.#burgee === undefined ? undefined : { ...this.#burgee };
597
+ const restore = () => {
598
+ this.#burgee = before;
599
+ };
600
+ const seam = this.#burgee?.exit === undefined ? undefined : this.#burgee;
601
+ if (seam === undefined) {
602
+ try {
603
+ const result = this.#parse(args, shortCircuit, _parseFn);
604
+ if (isPromise(result))
605
+ return result.finally(restore);
606
+ restore();
607
+ return result;
608
+ }
609
+ catch (err) {
610
+ restore();
611
+ throw err;
612
+ }
613
+ }
614
+ seam.exited = false;
615
+ const finish = (argv) => {
616
+ if (!this.#burgee?.exited)
617
+ seam.exit?.(ExitCode.OK);
618
+ restore();
619
+ return argv;
620
+ };
621
+ const fail = (err) => {
622
+ if (err instanceof YError) {
623
+ restore();
624
+ throw err;
625
+ }
626
+ const message = err instanceof Error ? err.message : String(err);
627
+ if (this.#burgee?.json)
628
+ this.#failureEnvelope(err instanceof Error ? err : message);
629
+ else
630
+ this.#logger.error(message);
631
+ if (!this.#burgee?.exited)
632
+ seam.exit?.(ExitCode.RUNTIME);
633
+ restore();
634
+ return undefined;
635
+ };
636
+ try {
637
+ const result = this.#parse(args, shortCircuit, _parseFn);
638
+ return isPromise(result) ? result.then(finish, fail) : finish(result);
639
+ }
640
+ catch (err) {
641
+ return fail(err);
642
+ }
643
+ }
644
+ #parse(args, shortCircuit, _parseFn) {
645
+ this.#freeze();
646
+ if (typeof args === 'undefined')
647
+ args = this.#processArgs;
648
+ if (typeof shortCircuit === 'object') {
649
+ this.#parseContext = shortCircuit;
650
+ shortCircuit = _parseFn;
651
+ }
652
+ if (typeof shortCircuit === 'function') {
653
+ this.#parseFn = shortCircuit;
654
+ shortCircuit = false;
655
+ }
656
+ if (!shortCircuit) {
657
+ args = this.#takeJson(args);
658
+ this.#processArgs = args;
659
+ }
660
+ if (this.#parseFn)
661
+ this.#exitProcess = false;
662
+ if (!shortCircuit) {
663
+ const served = this.#burgeeSurface(args);
664
+ if (served !== false) {
665
+ const settle = () => {
666
+ const argv = this.#runYargsParserAndExecuteCommands(args, true);
667
+ this.#unfreeze();
668
+ return argv;
669
+ };
670
+ if (isPromise(served))
671
+ return served.then(settle);
672
+ return settle();
673
+ }
674
+ }
675
+ const parsed = this.#runYargsParserAndExecuteCommands(args, !!shortCircuit);
676
+ const tmpParsed = this.parsed;
677
+ this.#completion.setParsed(this.parsed);
678
+ if (isPromise(parsed)) {
679
+ return parsed
680
+ .then((argv) => {
681
+ if (this.#parseFn)
682
+ this.#parseFn.call(this, this.#exitError, argv, this.#output);
683
+ return argv;
684
+ })
685
+ .catch((err) => {
686
+ if (this.#parseFn)
687
+ this.#parseFn(err, this.parsed.argv, this.#output);
688
+ throw err;
689
+ })
690
+ .finally(() => {
691
+ this.#unfreeze();
692
+ this.parsed = tmpParsed;
693
+ });
694
+ }
695
+ if (this.#parseFn)
696
+ this.#parseFn.call(this, this.#exitError, parsed, this.#output);
697
+ this.#unfreeze();
698
+ this.parsed = tmpParsed;
699
+ return parsed;
700
+ }
701
+ parseAsync(args, shortCircuit, _parseFn) {
702
+ const maybePromise = this.parse(args, shortCircuit, _parseFn);
703
+ return !isPromise(maybePromise) ? Promise.resolve(maybePromise) : maybePromise;
704
+ }
705
+ parseSync(args, shortCircuit, _parseFn) {
706
+ const maybePromise = this.parse(args, shortCircuit, _parseFn);
707
+ if (isPromise(maybePromise))
708
+ throw new YError('.parseSync() must not be used with asynchronous builders, handlers, or middleware');
709
+ return maybePromise;
710
+ }
711
+ parserConfiguration(config) {
712
+ argsert('<object>', [config], arguments.length);
713
+ this.#parserConfig = config;
714
+ return this;
715
+ }
716
+ pkgConf(key, rootPath) {
717
+ argsert('<string> [string]', [key, rootPath], arguments.length);
718
+ let conf = null;
719
+ const obj = this.#pkgUp(rootPath || this.#cwd);
720
+ if (obj[key] && typeof obj[key] === 'object') {
721
+ conf = applyExtends(obj[key], rootPath || this.#cwd, this.#getParserConfiguration()['deep-merge-config'] || false);
722
+ this.#options.configObjects = (this.#options.configObjects || []).concat(conf);
723
+ }
724
+ return this;
725
+ }
726
+ positional(key, opts) {
727
+ argsert('<string> <object>', [key, opts], arguments.length);
728
+ const supportedOpts = ['default', 'defaultDescription', 'implies', 'normalize', 'choices', 'conflicts', 'coerce', 'type', 'describe', 'desc', 'description', 'alias'];
729
+ opts = objFilter(opts, (k, v) => {
730
+ if (k === 'type' && !['string', 'number', 'boolean'].includes(v))
731
+ return false;
732
+ return supportedOpts.includes(k);
733
+ });
734
+ const fullCommand = this.#context.fullCommands[this.#context.fullCommands.length - 1];
735
+ const parseOptions = fullCommand ? this.#command.cmdToParseOptions(fullCommand) : { array: [], alias: {}, default: {}, demand: {} };
736
+ objectKeys(parseOptions).forEach((pk) => {
737
+ const parseOption = parseOptions[pk];
738
+ if (Array.isArray(parseOption)) {
739
+ if (parseOption.indexOf(key) !== -1)
740
+ opts[pk] = true;
741
+ }
742
+ else if (parseOption[key] && !(pk in opts))
743
+ opts[pk] = parseOption[key];
744
+ });
745
+ this.group(key, this.#usage.getPositionalGroupName());
746
+ return this.option(key, opts);
747
+ }
748
+ recommendCommands(recommend = true) {
749
+ argsert('[boolean]', [recommend], arguments.length);
750
+ this.#recommendCommands = recommend;
751
+ return this;
752
+ }
753
+ required(keys, max, msg) {
754
+ return this.demand(keys, max, msg);
755
+ }
756
+ require(keys, max, msg) {
757
+ return this.demand(keys, max, msg);
758
+ }
759
+ requiresArg(keys) {
760
+ argsert('<array|string|object> [number]', [keys], arguments.length);
761
+ if (typeof keys === 'string' && this.#options.narg[keys])
762
+ return this;
763
+ this.#populateParserHintSingleValueDictionary(this.requiresArg.bind(this), 'narg', keys, NaN);
764
+ return this;
765
+ }
766
+ showCompletionScript($0, cmd) {
767
+ argsert('[string] [string]', [$0, cmd], arguments.length);
768
+ $0 = $0 || this.$0;
769
+ this.#logger.log(this.#completion.generateCompletionScript($0, cmd || this.#completionCommand || 'completion'));
770
+ return this;
771
+ }
772
+ showHelp(level) {
773
+ argsert('[string|function]', [level], arguments.length);
774
+ this.#hasOutput = true;
775
+ if (!this.#usage.hasCachedHelpMessage()) {
776
+ if (!this.parsed) {
777
+ const parse = this.#runYargsParserAndExecuteCommands(this.#processArgs, undefined, undefined, 0, true);
778
+ if (isPromise(parse)) {
779
+ parse.then(() => {
780
+ this.#usage.showHelp(level);
781
+ });
782
+ return this;
783
+ }
784
+ }
785
+ const builderResponse = this.#command.runDefaultBuilderOn(this);
786
+ if (isPromise(builderResponse)) {
787
+ builderResponse.then(() => {
788
+ this.#usage.showHelp(level);
789
+ });
790
+ return this;
791
+ }
792
+ }
793
+ this.#usage.showHelp(level);
794
+ return this;
795
+ }
796
+ scriptName(scriptName) {
797
+ this.customScriptName = true;
798
+ this.$0 = scriptName;
799
+ return this;
800
+ }
801
+ showHelpOnFail(enabled, message) {
802
+ argsert('[boolean|string] [string]', [enabled, message], arguments.length);
803
+ this.#usage.showHelpOnFail(enabled, message);
804
+ return this;
805
+ }
806
+ showVersion(level) {
807
+ argsert('[string|function]', [level], arguments.length);
808
+ this.#usage.showVersion(level);
809
+ return this;
810
+ }
811
+ skipValidation(keys) {
812
+ argsert('<array|string>', [keys], arguments.length);
813
+ this.#populateParserHintArray('skipValidation', keys);
814
+ return this;
815
+ }
816
+ strict(enabled) {
817
+ argsert('[boolean]', [enabled], arguments.length);
818
+ this.#strict = enabled !== false;
819
+ return this;
820
+ }
821
+ strictCommands(enabled) {
822
+ argsert('[boolean]', [enabled], arguments.length);
823
+ this.#strictCommands = enabled !== false;
824
+ return this;
825
+ }
826
+ strictOptions(enabled) {
827
+ argsert('[boolean]', [enabled], arguments.length);
828
+ this.#strictOptions = enabled !== false;
829
+ return this;
830
+ }
831
+ string(keys) {
832
+ argsert('<array|string>', [keys], arguments.length);
833
+ this.#populateParserHintArray('string', keys);
834
+ this.#trackManuallySetKeys(keys);
835
+ return this;
836
+ }
837
+ terminalWidth() {
838
+ argsert([], 0);
839
+ return this.#shim.process.stdColumns;
840
+ }
841
+ updateLocale(obj) {
842
+ return this.updateStrings(obj);
843
+ }
844
+ updateStrings(obj) {
845
+ argsert('<object>', [obj], arguments.length);
846
+ this.#detectLocale = false;
847
+ this.#shim.y18n.updateLocale(obj);
848
+ return this;
849
+ }
850
+ usage(msg, description, builder, handler) {
851
+ argsert('<string|null|undefined> [string|boolean] [function|object] [function]', [msg, description, builder, handler], arguments.length);
852
+ if (description !== undefined) {
853
+ this.#shim.assert.notStrictEqual(msg, null);
854
+ if (/^\$0( |$)/.exec(msg || ''))
855
+ return this.command(msg, description, builder, handler);
856
+ throw new YError('.usage() description must start with $0 if being used as alias for .command()');
857
+ }
858
+ this.#usage.usage(msg);
859
+ return this;
860
+ }
861
+ usageConfiguration(config) {
862
+ argsert('<object>', [config], arguments.length);
863
+ this.#usageConfig = config;
864
+ return this;
865
+ }
866
+ version(opt, msg, ver) {
867
+ const defaultVersionOpt = 'version';
868
+ argsert('[boolean|string] [string] [string]', [opt, msg, ver], arguments.length);
869
+ if (this.#versionOpt) {
870
+ this.#deleteFromParserHintObject(this.#versionOpt);
871
+ this.#usage.version(undefined);
872
+ this.#versionOpt = null;
873
+ }
874
+ if (arguments.length === 0) {
875
+ ver = this.#guessVersion();
876
+ opt = defaultVersionOpt;
877
+ }
878
+ else if (arguments.length === 1) {
879
+ if (opt === false)
880
+ return this;
881
+ ver = opt;
882
+ opt = defaultVersionOpt;
883
+ }
884
+ else if (arguments.length === 2) {
885
+ ver = msg;
886
+ msg = undefined;
887
+ }
888
+ this.#versionOpt = typeof opt === 'string' ? opt : defaultVersionOpt;
889
+ msg = msg || this.#usage.deferY18nLookup('Show version number');
890
+ this.#usage.version(ver || undefined);
891
+ this.boolean(this.#versionOpt);
892
+ this.describe(this.#versionOpt, msg);
893
+ return this;
894
+ }
895
+ wrap(cols) {
896
+ argsert('<number|null|undefined>', [cols], arguments.length);
897
+ this.#usage.wrap(cols);
898
+ return this;
899
+ }
900
+ #copyDoubleDash(argv) {
901
+ if (!argv._ || !argv['--'])
902
+ return argv;
903
+ argv._.push.apply(argv._, argv['--']);
904
+ try {
905
+ delete argv['--'];
906
+ }
907
+ catch {
908
+ }
909
+ return argv;
910
+ }
911
+ #createLogger() {
912
+ return {
913
+ log: (...args) => {
914
+ const out = this.#burgee?.stdout;
915
+ if (out !== undefined)
916
+ out.write(`${args.join(' ')}\n`);
917
+ else if (!this.#hasParseCallback())
918
+ console.log(...args);
919
+ this.#hasOutput = true;
920
+ if (this.#output.length)
921
+ this.#output += '\n';
922
+ this.#output += args.join(' ');
923
+ },
924
+ error: (...args) => {
925
+ const burgee = this.#burgee;
926
+ const line = args.join(' ');
927
+ if (burgee?.json) {
928
+ if (line.trim() !== '')
929
+ burgee.lastError = line;
930
+ }
931
+ else if (burgee?.stderr !== undefined)
932
+ burgee.stderr.write(`${line}\n`);
933
+ else if (!this.#hasParseCallback())
934
+ console.error(...args);
935
+ this.#hasOutput = true;
936
+ if (this.#output.length)
937
+ this.#output += '\n';
938
+ this.#output += line;
939
+ },
940
+ };
941
+ }
942
+ #deleteFromParserHintObject(optionKey) {
943
+ objectKeys(this.#options).forEach((hintKey) => {
944
+ if (hintKey === 'configObjects')
945
+ return;
946
+ const hint = this.#options[hintKey];
947
+ if (Array.isArray(hint)) {
948
+ if (hint.includes(optionKey))
949
+ hint.splice(hint.indexOf(optionKey), 1);
950
+ }
951
+ else if (typeof hint === 'object')
952
+ delete hint[optionKey];
953
+ });
954
+ delete this.#usage.getDescriptions()[optionKey];
955
+ }
956
+ #emitWarning(warning, type, deduplicationId) {
957
+ if (!this.#emittedWarnings[deduplicationId]) {
958
+ this.#shim.process.emitWarning(warning, type);
959
+ this.#emittedWarnings[deduplicationId] = true;
960
+ }
961
+ }
962
+ #freeze() {
963
+ this.#frozens.push({
964
+ options: this.#options,
965
+ configObjects: this.#options.configObjects.slice(0),
966
+ exitProcess: this.#exitProcess,
967
+ groups: this.#groups,
968
+ strict: this.#strict,
969
+ strictCommands: this.#strictCommands,
970
+ strictOptions: this.#strictOptions,
971
+ completionCommand: this.#completionCommand,
972
+ output: this.#output,
973
+ exitError: this.#exitError,
974
+ hasOutput: this.#hasOutput,
975
+ parsed: this.parsed,
976
+ parseFn: this.#parseFn,
977
+ parseContext: this.#parseContext,
978
+ });
979
+ this.#usage.freeze();
980
+ this.#validation.freeze();
981
+ this.#command.freeze();
982
+ this.#globalMiddleware.freeze();
983
+ }
984
+ #getDollarZero() {
985
+ let $0 = '';
986
+ let default$0;
987
+ if (/\b(node|iojs|electron|bun)(\.exe)?$/.test(this.#shim.process.argv()[0]))
988
+ default$0 = this.#shim.process.argv().slice(1, 2);
989
+ else
990
+ default$0 = this.#shim.process.argv().slice(0, 1);
991
+ $0 = default$0
992
+ .map((x) => {
993
+ const b = this.#rebase(this.#cwd, x);
994
+ return /^(\/|([a-zA-Z]:)?\\)/.exec(x) && b.length < x.length ? b : x;
995
+ })
996
+ .join(' ')
997
+ .trim();
998
+ if (this.#shim.getEnv('_') && this.#shim.getProcessArgvBin() === this.#shim.getEnv('_')) {
999
+ $0 = this.#shim.getEnv('_').replace(`${this.#shim.path.dirname(this.#shim.process.execPath())}/`, '');
1000
+ }
1001
+ return $0;
1002
+ }
1003
+ #getParserConfiguration() {
1004
+ return this.#parserConfig;
1005
+ }
1006
+ #getUsageConfiguration() {
1007
+ return this.#usageConfig;
1008
+ }
1009
+ #guessLocale() {
1010
+ if (!this.#detectLocale)
1011
+ return;
1012
+ const locale = this.#shim.getEnv('LC_ALL') || this.#shim.getEnv('LC_MESSAGES') || this.#shim.getEnv('LANG') || this.#shim.getEnv('LANGUAGE') || 'en_US';
1013
+ this.locale(locale.replace(/[.:].*/, ''));
1014
+ }
1015
+ #guessVersion() {
1016
+ const obj = this.#pkgUp();
1017
+ return obj.version || 'unknown';
1018
+ }
1019
+ #parsePositionalNumbers(argv) {
1020
+ const args = argv['--'] ? argv['--'] : argv._;
1021
+ for (let i = 0, arg; (arg = args[i]) !== undefined; i++) {
1022
+ if (this.#shim.Parser.looksLikeNumber(arg) && Number.isSafeInteger(Math.floor(parseFloat(`${arg}`))))
1023
+ args[i] = Number(arg);
1024
+ }
1025
+ return argv;
1026
+ }
1027
+ #pkgUp(rootPath) {
1028
+ const npath = rootPath || '*';
1029
+ if (this.#pkgs[npath])
1030
+ return this.#pkgs[npath];
1031
+ let obj = {};
1032
+ try {
1033
+ let startDir = rootPath || this.#shim.mainFilename;
1034
+ if (this.#shim.path.extname(startDir))
1035
+ startDir = this.#shim.path.dirname(startDir);
1036
+ const pkgJsonPath = this.#shim.findUp(startDir, (_dir, names) => {
1037
+ if (names.includes('package.json'))
1038
+ return 'package.json';
1039
+ return undefined;
1040
+ });
1041
+ this.#shim.assert.notStrictEqual(pkgJsonPath, undefined);
1042
+ obj = JSON.parse(this.#shim.readFileSync(pkgJsonPath, 'utf8'));
1043
+ }
1044
+ catch {
1045
+ }
1046
+ this.#pkgs[npath] = obj || {};
1047
+ return this.#pkgs[npath];
1048
+ }
1049
+ #populateParserHintArray(type, keys) {
1050
+ keys = [].concat(keys);
1051
+ keys.forEach((key) => {
1052
+ key = this.#sanitizeKey(key);
1053
+ this.#options[type].push(key);
1054
+ });
1055
+ }
1056
+ #populateParserHintSingleValueDictionary(builder, type, key, value) {
1057
+ this.#populateParserHintDictionary(builder, type, key, value, (t, k, v) => {
1058
+ this.#options[t][k] = v;
1059
+ });
1060
+ }
1061
+ #populateParserHintArrayDictionary(builder, type, key, value) {
1062
+ this.#populateParserHintDictionary(builder, type, key, value, (t, k, v) => {
1063
+ this.#options[t][k] = (this.#options[t][k] || []).concat(v);
1064
+ });
1065
+ }
1066
+ #populateParserHintDictionary(builder, type, key, value, singleKeyHandler) {
1067
+ if (Array.isArray(key)) {
1068
+ key.forEach((k) => {
1069
+ builder(k, value);
1070
+ });
1071
+ }
1072
+ else if (typeof key === 'object') {
1073
+ for (const k of objectKeys(key))
1074
+ builder(k, key[k]);
1075
+ }
1076
+ else
1077
+ singleKeyHandler(type, this.#sanitizeKey(key), value);
1078
+ }
1079
+ #sanitizeKey(key) {
1080
+ if (key === '__proto__')
1081
+ return '___proto___';
1082
+ return key;
1083
+ }
1084
+ #setKey(key, set) {
1085
+ this.#populateParserHintSingleValueDictionary(this.#setKey.bind(this), 'key', key, set);
1086
+ return this;
1087
+ }
1088
+ #unfreeze() {
1089
+ const frozen = this.#frozens.pop();
1090
+ this.#shim.assert.notStrictEqual(frozen, undefined);
1091
+ const f = frozen;
1092
+ this.#options = f.options;
1093
+ this.#exitProcess = f.exitProcess;
1094
+ this.#groups = f.groups;
1095
+ this.#output = f.output;
1096
+ this.#exitError = f.exitError;
1097
+ this.#hasOutput = f.hasOutput;
1098
+ this.parsed = f.parsed;
1099
+ this.#strict = f.strict;
1100
+ this.#strictCommands = f.strictCommands;
1101
+ this.#strictOptions = f.strictOptions;
1102
+ this.#completionCommand = f.completionCommand;
1103
+ this.#parseFn = f.parseFn;
1104
+ this.#parseContext = f.parseContext;
1105
+ this.#options.configObjects = f.configObjects;
1106
+ this.#usage.unfreeze();
1107
+ this.#validation.unfreeze();
1108
+ this.#command.unfreeze();
1109
+ this.#globalMiddleware.unfreeze();
1110
+ }
1111
+ #validateAsync(validation, argv) {
1112
+ return maybeAsyncResult(argv, (result) => {
1113
+ validation(result);
1114
+ return result;
1115
+ });
1116
+ }
1117
+ getInternalMethods() {
1118
+ return {
1119
+ getCommandInstance: this.#getCommandInstance.bind(this),
1120
+ getContext: this.#getContext.bind(this),
1121
+ getHasOutput: this.#getHasOutput.bind(this),
1122
+ getLoggerInstance: this.#getLoggerInstance.bind(this),
1123
+ getParseContext: this.#getParseContext.bind(this),
1124
+ getParserConfiguration: this.#getParserConfiguration.bind(this),
1125
+ getUsageConfiguration: this.#getUsageConfiguration.bind(this),
1126
+ getUsageInstance: this.#getUsageInstance.bind(this),
1127
+ getValidationInstance: this.#getValidationInstance.bind(this),
1128
+ hasParseCallback: this.#hasParseCallback.bind(this),
1129
+ isGlobalContext: this.#isGlobalContextFn.bind(this),
1130
+ postProcess: this.#postProcess.bind(this),
1131
+ reset: this.#reset.bind(this),
1132
+ runValidation: this.#runValidation.bind(this),
1133
+ runYargsParserAndExecuteCommands: this.#runYargsParserAndExecuteCommands.bind(this),
1134
+ setHasOutput: this.#setHasOutput.bind(this),
1135
+ runHandler: this.#runHandler.bind(this),
1136
+ };
1137
+ }
1138
+ get manifest() {
1139
+ this.#manifest ??= new Manifest();
1140
+ projectManifest(this.#manifest, this.#snapshot());
1141
+ return this.#manifest;
1142
+ }
1143
+ effects(value) {
1144
+ this.#effects = value;
1145
+ return this;
1146
+ }
1147
+ use(plugin) {
1148
+ this.manifest.use(plugin);
1149
+ return this;
1150
+ }
1151
+ burgee(seam) {
1152
+ this.#burgee = { ...(this.#burgee ?? { json: false, lastError: '' }), ...seam };
1153
+ return this;
1154
+ }
1155
+ #snapshot() {
1156
+ const o = this.#options;
1157
+ const skip = [this.#helpOpt, this.#versionOpt, o.showHiddenOpt].filter((k) => typeof k === 'string');
1158
+ const handlers = this.#command.getCommandHandlers();
1159
+ const commands = [];
1160
+ let positionals = { demanded: [], optional: [] };
1161
+ let hasHandler = false;
1162
+ let description;
1163
+ const isDefault = (h) => /^\$0( |$)/.test(h.original);
1164
+ for (const [name, handler] of Object.entries(handlers)) {
1165
+ if (isDefault(handler))
1166
+ continue;
1167
+ const child = this.#childOf(handler);
1168
+ commands.push({ name, description: handler.description, deprecated: handler.deprecated, child: child.#snapshotOf(handler, name) });
1169
+ }
1170
+ const root = Object.values(handlers).find(isDefault);
1171
+ if (root !== undefined) {
1172
+ hasHandler = true;
1173
+ positionals = { demanded: root.demanded, optional: root.optional };
1174
+ if (typeof root.description === 'string')
1175
+ description = root.description;
1176
+ }
1177
+ const first = this.#usage.getUsage()[0];
1178
+ if (description === undefined && first !== undefined && first[1] !== '')
1179
+ description = first[1];
1180
+ return {
1181
+ name: this.customScriptName ? this.$0 : this.#shim.path.basename(this.$0) || 'program',
1182
+ version: typeof this.#usage.getVersion() === 'string' ? this.#usage.getVersion() : undefined,
1183
+ description,
1184
+ effects: this.#effects,
1185
+ hasHandler,
1186
+ keys: Object.keys(o.key),
1187
+ aliases: o.alias,
1188
+ boolean: o.boolean,
1189
+ number: o.number,
1190
+ string: o.string,
1191
+ count: o.count,
1192
+ array: o.array,
1193
+ hiddenOptions: o.hiddenOptions,
1194
+ demanded: o.demandedOptions,
1195
+ deprecated: o.deprecatedOptions,
1196
+ choices: o.choices,
1197
+ defaults: o.default,
1198
+ descriptions: this.#usage.getDescriptions(),
1199
+ skip,
1200
+ positionals,
1201
+ commands,
1202
+ };
1203
+ }
1204
+ #snapshotOf(handler, name) {
1205
+ const snap = this.#snapshot();
1206
+ snap.name = name;
1207
+ snap.hasHandler = true;
1208
+ snap.positionals = { demanded: handler.demanded, optional: handler.optional };
1209
+ snap.description = typeof handler.description === 'string' ? handler.description : undefined;
1210
+ snap.version = undefined;
1211
+ return snap;
1212
+ }
1213
+ #childOf(handler) {
1214
+ const child = new _a([], this.#cwd, this.#parentRequire, this.#shim);
1215
+ child.#context.fullCommands.push(handler.original);
1216
+ const builder = handler.builder;
1217
+ try {
1218
+ if (isCommandBuilderCallback(builder)) {
1219
+ const out = builder(child, true);
1220
+ if (!isPromise(out) && out instanceof _a)
1221
+ return out;
1222
+ }
1223
+ else if (typeof builder === 'object' && builder !== null) {
1224
+ for (const key of Object.keys(builder))
1225
+ child.option(key, builder[key]);
1226
+ }
1227
+ }
1228
+ catch {
1229
+ }
1230
+ return child;
1231
+ }
1232
+ #takeJson(args) {
1233
+ const list = typeof args === 'string' ? tokenizeArgString(args) : args;
1234
+ const terminator = list.indexOf('--');
1235
+ const index = list.indexOf('--json');
1236
+ if (index === -1 || (terminator !== -1 && index > terminator))
1237
+ return args;
1238
+ if (this.#declares('json'))
1239
+ return args;
1240
+ this.#burgee = { ...(this.#burgee ?? { lastError: '' }), json: true };
1241
+ return [...list.slice(0, index), ...list.slice(index + 1)];
1242
+ }
1243
+ #declares(key) {
1244
+ if (this.#options.key[key] || Object.values(this.#options.alias).some((list) => list.includes(key)))
1245
+ return true;
1246
+ if (this.#command.getCommands().includes(key))
1247
+ return true;
1248
+ return this.manifest.commands.some((node) => Object.prototype.hasOwnProperty.call(node.options, key));
1249
+ }
1250
+ #burgeeSurface(args) {
1251
+ const list = typeof args === 'string' ? tokenizeArgString(args) : args;
1252
+ const terminator = list.indexOf('--');
1253
+ const head = terminator === -1 ? list : list.slice(0, terminator);
1254
+ if (head[0] === 'completion' && this.#completionCommand === null && !this.#declares('completion')) {
1255
+ return import('./completions.js').then(({ renderCompletion, renderFigSpec, SHELLS }) => {
1256
+ const shell = head[1] ?? '';
1257
+ if (shell === 'fig') {
1258
+ this.#logger.log(JSON.stringify(renderFigSpec(this.manifest), null, 2));
1259
+ this.exit(0);
1260
+ return true;
1261
+ }
1262
+ const known = SHELLS.find((s) => s === shell);
1263
+ if (known === undefined)
1264
+ return false;
1265
+ this.#logger.log(renderCompletion(this.manifest, known).replace(/\n$/, ''));
1266
+ this.exit(0);
1267
+ return true;
1268
+ });
1269
+ }
1270
+ if (head.includes('--schema') && !this.#declares('schema')) {
1271
+ this.#logger.log(JSON.stringify(schemaOf(this.manifest), null, 2));
1272
+ this.exit(0);
1273
+ return true;
1274
+ }
1275
+ if (head[0] === '--mcp' && !this.#declares('mcp')) {
1276
+ const invoke = async (argv) => {
1277
+ const out = [];
1278
+ const err = [];
1279
+ let code = 0;
1280
+ const before = this.#burgee;
1281
+ this.#burgee = { json: false, lastError: '', stdout: { write: (s) => out.push(s) }, stderr: { write: (s) => err.push(s) }, exit: (c) => void (code = c) };
1282
+ try {
1283
+ await this.parseAsync([...argv, '--json']);
1284
+ }
1285
+ finally {
1286
+ this.#burgee = before;
1287
+ }
1288
+ return { stdout: out.join(''), stderr: err.join(''), code };
1289
+ };
1290
+ const write = this.#burgee?.stdout ?? this.#shim.process.stdout();
1291
+ return serveMcp(this.manifest, { input: this.#shim.process.stdin(), output: { write: (s) => void write.write(s) }, invoke }).then(() => {
1292
+ this.exit(0);
1293
+ return true;
1294
+ });
1295
+ }
1296
+ return false;
1297
+ }
1298
+ #runHandler(handler, argv, original) {
1299
+ const manifest = this.#manifest;
1300
+ const settle = (value) => {
1301
+ this.#settle(value, argv);
1302
+ return value;
1303
+ };
1304
+ if (manifest === undefined || manifest.plugins.length === 0) {
1305
+ const result = handler(argv);
1306
+ return isPromise(result) ? result.then(settle) : settle(result);
1307
+ }
1308
+ const name = original.replace(/^\$0 ?/, '').split(' ')[0] ?? '';
1309
+ const options = {};
1310
+ for (const key of Object.keys(this.#options.key))
1311
+ options[key] = argv[key];
1312
+ return manifest
1313
+ .fire('preRun', name, options)
1314
+ .then(() => handler(argv))
1315
+ .then(async (value) => {
1316
+ await manifest.fire('postRun', name, options);
1317
+ return settle(value);
1318
+ });
1319
+ }
1320
+ #settle(value, argv) {
1321
+ const burgee = this.#burgee;
1322
+ if (burgee === undefined)
1323
+ return;
1324
+ if (burgee.json) {
1325
+ this.#logger.log(JSON.stringify({ ok: true, data: value ?? null, meta: { provenance: this.#provenance(argv) } }));
1326
+ return;
1327
+ }
1328
+ const text = render(value);
1329
+ if (text !== '')
1330
+ this.#logger.log(text.replace(/\n$/, ''));
1331
+ }
1332
+ #failureEnvelope(err) {
1333
+ const burgee = this.#burgee;
1334
+ const message = err instanceof Error ? err.message : typeof err === 'string' ? err : burgee.lastError;
1335
+ const code = err instanceof YError || err === undefined || typeof err === 'string' ? 'usage' : 'runtime';
1336
+ this.#logger.log(JSON.stringify({ ok: false, error: { code, message } }));
1337
+ }
1338
+ #provenance(argv) {
1339
+ const out = {};
1340
+ const defaulted = this.parsed?.defaulted ?? {};
1341
+ const prefix = this.#options.envPrefix;
1342
+ const positional = new Set(this.getGroups()[this.#usage.getPositionalGroupName()] ?? []);
1343
+ for (const key of Object.keys(this.#options.key)) {
1344
+ if (key === this.#helpOpt || key === this.#versionOpt || positional.has(key))
1345
+ continue;
1346
+ if (!Object.prototype.hasOwnProperty.call(argv, key) || argv[key] === undefined)
1347
+ continue;
1348
+ let source = 'flag';
1349
+ if (defaulted[key])
1350
+ source = 'default';
1351
+ else if (this.#options.configObjects.some((c) => Object.prototype.hasOwnProperty.call(c, key)))
1352
+ source = 'config';
1353
+ else if (prefix !== undefined && this.#shim.getEnv(`${prefix}${prefix === '' ? '' : '_'}${key.replace(/[A-Z]/g, (c) => `_${c}`).toUpperCase()}`) !== undefined)
1354
+ source = 'env';
1355
+ out[key] = { source };
1356
+ }
1357
+ return out;
1358
+ }
1359
+ #getCommandInstance() {
1360
+ return this.#command;
1361
+ }
1362
+ #getContext() {
1363
+ return this.#context;
1364
+ }
1365
+ #getHasOutput() {
1366
+ return this.#hasOutput;
1367
+ }
1368
+ #getLoggerInstance() {
1369
+ return this.#logger;
1370
+ }
1371
+ #getParseContext() {
1372
+ return this.#parseContext || {};
1373
+ }
1374
+ #getUsageInstance() {
1375
+ return this.#usage;
1376
+ }
1377
+ #getValidationInstance() {
1378
+ return this.#validation;
1379
+ }
1380
+ #hasParseCallback() {
1381
+ return !!this.#parseFn;
1382
+ }
1383
+ #isGlobalContextFn() {
1384
+ return this.#isGlobalContext;
1385
+ }
1386
+ #postProcess(argv, populateDoubleDash, calledFromCommand, runGlobalMiddleware) {
1387
+ if (calledFromCommand)
1388
+ return argv;
1389
+ if (isPromise(argv))
1390
+ return argv;
1391
+ if (!populateDoubleDash)
1392
+ argv = this.#copyDoubleDash(argv);
1393
+ const parsePositionalNumbers = this.#getParserConfiguration()['parse-positional-numbers'] || this.#getParserConfiguration()['parse-positional-numbers'] === undefined;
1394
+ if (parsePositionalNumbers)
1395
+ argv = this.#parsePositionalNumbers(argv);
1396
+ if (runGlobalMiddleware)
1397
+ argv = applyMiddleware(argv, this, this.#globalMiddleware.getMiddleware(), false);
1398
+ return argv;
1399
+ }
1400
+ #reset(aliases = {}) {
1401
+ this.#options = this.#options || {};
1402
+ const tmpOptions = {};
1403
+ tmpOptions.local = this.#options.local || [];
1404
+ tmpOptions.configObjects = this.#options.configObjects || [];
1405
+ const localLookup = {};
1406
+ tmpOptions.local.forEach((l) => {
1407
+ localLookup[l] = true;
1408
+ (aliases[l] || []).forEach((a) => {
1409
+ localLookup[a] = true;
1410
+ });
1411
+ });
1412
+ Object.assign(this.#preservedGroups, Object.keys(this.#groups).reduce((acc, groupName) => {
1413
+ const keys = this.#groups[groupName].filter((key) => !(key in localLookup));
1414
+ if (keys.length > 0)
1415
+ acc[groupName] = keys;
1416
+ return acc;
1417
+ }, {}));
1418
+ this.#groups = {};
1419
+ const arrayOptions = ['array', 'boolean', 'string', 'skipValidation', 'count', 'normalize', 'number', 'hiddenOptions'];
1420
+ const objectOptions = ['narg', 'key', 'alias', 'default', 'defaultDescription', 'config', 'choices', 'demandedOptions', 'demandedCommands', 'deprecatedOptions'];
1421
+ arrayOptions.forEach((k) => {
1422
+ tmpOptions[k] = (this.#options[k] || []).filter((key) => !localLookup[key]);
1423
+ });
1424
+ objectOptions.forEach((k) => {
1425
+ tmpOptions[k] = objFilter(this.#options[k], (key) => !localLookup[key]);
1426
+ });
1427
+ tmpOptions.envPrefix = this.#options.envPrefix;
1428
+ this.#options = tmpOptions;
1429
+ this.#usage = this.#usage ? this.#usage.reset(localLookup) : Usage(this, this.#shim);
1430
+ this.#validation = this.#validation ? this.#validation.reset(localLookup) : Validation(this, this.#usage, this.#shim);
1431
+ this.#command = this.#command ? this.#command.reset() : Command(this.#usage, this.#validation, this.#globalMiddleware, this.#shim);
1432
+ if (!this.#completion)
1433
+ this.#completion = Completion(this, this.#usage, this.#command, this.#shim);
1434
+ this.#globalMiddleware.reset();
1435
+ this.#completionCommand = null;
1436
+ this.#output = '';
1437
+ this.#exitError = null;
1438
+ this.#hasOutput = false;
1439
+ this.parsed = false;
1440
+ return this;
1441
+ }
1442
+ #rebase(base, dir) {
1443
+ return this.#shim.path.relative(base, dir);
1444
+ }
1445
+ #runYargsParserAndExecuteCommands(args, shortCircuit, calledFromCommand, commandIndex = 0, helpOnly = false) {
1446
+ let skipValidation = !!calledFromCommand || helpOnly;
1447
+ args = args || this.#processArgs;
1448
+ this.#options.__ = this.#shim.y18n.__;
1449
+ this.#options.configuration = this.#getParserConfiguration();
1450
+ const populateDoubleDash = !!this.#options.configuration['populate--'];
1451
+ const config = Object.assign({}, this.#options.configuration, { 'populate--': true });
1452
+ const parsed = this.#shim.Parser.detailed(args, Object.assign({}, this.#options, { configuration: { 'parse-positional-numbers': false, ...config } }));
1453
+ const argv = Object.assign(parsed.argv, this.#parseContext);
1454
+ let argvPromise = undefined;
1455
+ const aliases = parsed.aliases;
1456
+ let helpOptSet = false;
1457
+ let versionOptSet = false;
1458
+ Object.keys(argv).forEach((key) => {
1459
+ if (key === this.#helpOpt && argv[key])
1460
+ helpOptSet = true;
1461
+ else if (key === this.#versionOpt && argv[key])
1462
+ versionOptSet = true;
1463
+ });
1464
+ argv.$0 = this.$0;
1465
+ this.parsed = parsed;
1466
+ if (commandIndex === 0)
1467
+ this.#usage.clearCachedHelpMessage();
1468
+ try {
1469
+ this.#guessLocale();
1470
+ if (shortCircuit)
1471
+ return this.#postProcess(argv, populateDoubleDash, !!calledFromCommand, false);
1472
+ if (this.#helpOpt) {
1473
+ const helpCmds = [this.#helpOpt].concat(aliases[this.#helpOpt] || []).filter((k) => k.length > 1);
1474
+ if (helpCmds.includes(`${argv._[argv._.length - 1]}`)) {
1475
+ argv._.pop();
1476
+ helpOptSet = true;
1477
+ }
1478
+ }
1479
+ this.#isGlobalContext = false;
1480
+ const handlerKeys = this.#command.getCommands();
1481
+ const requestCompletions = this.#completion?.completionKey
1482
+ ? [this.#completion?.completionKey, ...(this.getAliases()[this.#completion?.completionKey] ?? [])].some((key) => Object.prototype.hasOwnProperty.call(argv, key))
1483
+ : false;
1484
+ const skipRecommendation = helpOptSet || requestCompletions || helpOnly;
1485
+ if (argv._.length) {
1486
+ if (handlerKeys.length) {
1487
+ let firstUnknownCommand;
1488
+ for (let i = commandIndex || 0, cmd; argv._[i] !== undefined; i++) {
1489
+ cmd = String(argv._[i]);
1490
+ if (handlerKeys.includes(cmd) && cmd !== this.#completionCommand) {
1491
+ const innerArgv = this.#command.runCommand(cmd, this, parsed, i + 1, helpOnly, helpOptSet || versionOptSet || helpOnly);
1492
+ return this.#postProcess(innerArgv, populateDoubleDash, !!calledFromCommand, false);
1493
+ }
1494
+ else if (!firstUnknownCommand && cmd !== this.#completionCommand) {
1495
+ firstUnknownCommand = cmd;
1496
+ break;
1497
+ }
1498
+ }
1499
+ if (!this.#command.hasDefaultCommand() && this.#recommendCommands && firstUnknownCommand && !skipRecommendation) {
1500
+ this.#validation.recommendCommands(firstUnknownCommand, handlerKeys);
1501
+ }
1502
+ }
1503
+ if (this.#completionCommand && argv._.includes(this.#completionCommand) && !requestCompletions) {
1504
+ if (this.#exitProcess)
1505
+ setBlocking(true);
1506
+ this.showCompletionScript();
1507
+ this.exit(0);
1508
+ }
1509
+ }
1510
+ if (this.#command.hasDefaultCommand() && !skipRecommendation) {
1511
+ const innerArgv = this.#command.runCommand(null, this, parsed, 0, helpOnly, helpOptSet || versionOptSet || helpOnly);
1512
+ return this.#postProcess(innerArgv, populateDoubleDash, !!calledFromCommand, false);
1513
+ }
1514
+ if (requestCompletions) {
1515
+ if (this.#exitProcess)
1516
+ setBlocking(true);
1517
+ args = [].concat(args);
1518
+ const completionArgs = args.slice(args.indexOf(`--${this.#completion.completionKey}`) + 1);
1519
+ this.#completion.getCompletion(completionArgs, (err, completions) => {
1520
+ if (err)
1521
+ throw new YError(err.message);
1522
+ (completions || []).forEach((completion) => {
1523
+ this.#logger.log(completion);
1524
+ });
1525
+ this.exit(0);
1526
+ });
1527
+ return this.#postProcess(argv, !populateDoubleDash, !!calledFromCommand, false);
1528
+ }
1529
+ if (!this.#hasOutput) {
1530
+ if (helpOptSet) {
1531
+ if (this.#exitProcess)
1532
+ setBlocking(true);
1533
+ skipValidation = true;
1534
+ this.showHelp((message) => {
1535
+ this.#logger.log(message);
1536
+ this.exit(0);
1537
+ });
1538
+ }
1539
+ else if (versionOptSet) {
1540
+ if (this.#exitProcess)
1541
+ setBlocking(true);
1542
+ skipValidation = true;
1543
+ this.#usage.showVersion('log');
1544
+ this.exit(0);
1545
+ }
1546
+ }
1547
+ if (!skipValidation && this.#options.skipValidation.length > 0) {
1548
+ skipValidation = Object.keys(argv).some((key) => this.#options.skipValidation.indexOf(key) >= 0 && argv[key] === true);
1549
+ }
1550
+ if (!skipValidation) {
1551
+ if (parsed.error)
1552
+ throw new YError(parsed.error.message);
1553
+ if (!requestCompletions) {
1554
+ const validation = this.#runValidation(aliases, {}, parsed.error);
1555
+ if (!calledFromCommand)
1556
+ argvPromise = applyMiddleware(argv, this, this.#globalMiddleware.getMiddleware(), true);
1557
+ argvPromise = this.#validateAsync(validation, argvPromise ?? argv);
1558
+ if (isPromise(argvPromise) && !calledFromCommand) {
1559
+ argvPromise = argvPromise.then(() => applyMiddleware(argv, this, this.#globalMiddleware.getMiddleware(), false));
1560
+ }
1561
+ }
1562
+ }
1563
+ }
1564
+ catch (err) {
1565
+ if (err instanceof YError)
1566
+ this.#usage.fail(err.message, err);
1567
+ else
1568
+ throw err;
1569
+ }
1570
+ return this.#postProcess(argvPromise ?? argv, populateDoubleDash, !!calledFromCommand, true);
1571
+ }
1572
+ #runValidation(aliases, positionalMap, parseErrors, isDefaultCommand) {
1573
+ const demandedOptions = { ...this.getDemandedOptions() };
1574
+ return (argv) => {
1575
+ if (parseErrors)
1576
+ throw new YError(parseErrors.message);
1577
+ this.#validation.nonOptionCount(argv);
1578
+ this.#validation.requiredArguments(argv, demandedOptions);
1579
+ let failedStrictCommands = false;
1580
+ if (this.#strictCommands)
1581
+ failedStrictCommands = this.#validation.unknownCommands(argv);
1582
+ if (this.#strict && !failedStrictCommands)
1583
+ this.#validation.unknownArguments(argv, aliases, positionalMap, !!isDefaultCommand);
1584
+ else if (this.#strictOptions)
1585
+ this.#validation.unknownArguments(argv, aliases, {}, false, false);
1586
+ this.#validation.limitedChoices(argv);
1587
+ this.#validation.implications(argv);
1588
+ this.#validation.conflicting(argv);
1589
+ };
1590
+ }
1591
+ #setHasOutput() {
1592
+ this.#hasOutput = true;
1593
+ }
1594
+ #trackManuallySetKeys(keys) {
1595
+ if (typeof keys === 'string')
1596
+ this.#options.key[keys] = true;
1597
+ else {
1598
+ for (const k of keys)
1599
+ this.#options.key[k] = true;
1600
+ }
1601
+ }
1602
+ }
1603
+ _a = YargsInstance;
1604
+ export function isYargsInstance(y) {
1605
+ return !!y && typeof y.getInternalMethods === 'function';
1606
+ }