yargs-factory.js 72 KB

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