Skip to content
Myr

Switch @api private to official JSDoc (#2018)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by GitHub · parent c876dee · Browse files · 3 files+54 added−56 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+54 added−56 removed

  • other:+54 added−56 removed

3 files+54 added−56 removed

modified:lib/argument.js+2 added-2 removed
modified:lib/command.js+47 added-48 removed
109 unmodified lines
110 }111112 /**113 * @returns {Command[]}114 * @api private114 * @private115 */116117 _getCommandAndAncestors() {118 const result = [];
275 unmodified lines
394 }395396 /**397 * @return {boolean}398 * @api private398 * @package internal use only399 */400401 _hasImplicitHelpCommand() {402 if (this._addImplicitHelpCommand === undefined) {
52 unmodified lines
455 * @param {number} exitCode exit code for using with process.exit456 * @param {string} code an id string representing the error457 * @param {string} message human-readable description of the error458 * @return never459 * @api private459 * @private460 */461462 _exit(exitCode, code, message) {463 if (this._exitCallback) {
57 unmodified lines
521 * @param {Option | Argument} target522 * @param {string} value523 * @param {any} previous524 * @param {string} invalidArgumentMessage525 * @api private525 * @private526 */527528 _callParseArg(target, value, previous, invalidArgumentMessage) {529 try {
77 unmodified lines
607608 /**609 * Internal implementation shared by .option() and .requiredOption()610 *611 * @api private611 * @private612 */613 _optionEx(config, flags, description, fn, defaultValue) {614 if (typeof flags === 'object' && flags instanceof Option) {615 throw new Error('To add an Option object use addOption() instead of option() or requiredOption()');
152 unmodified lines
768 return this;769 }770771 /**772 * @api private772 * @private773 */774775 _checkForBrokenPassThrough() {776 if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
99 unmodified lines
876 /**877 * Get user arguments from implied or explicit arguments.878 * Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.879 *880 * @api private880 * @private881 */882883 _prepareUserArgs(argv, parseOptions) {884 if (argv !== undefined && !Array.isArray(argv)) {
94 unmodified lines
979980 /**981 * Execute a sub-command executable.982 *983 * @api private983 * @private984 */985986 _executeSubCommand(subcommand, args) {987 args = args.slice();
116 unmodified lines
1104 this.runningCommand = proc;1105 }11061107 /**1108 * @api private1108 * @private1109 */11101111 _dispatchSubcommand(commandName, operands, unknown) {1112 const subCommand = this._findCommand(commandName);
14 unmodified lines
1127 /**1128 * Invoke help directly if possible, or dispatch if necessary.1129 * e.g. help foo1130 *1131 * @api private1131 * @private1132 */11331134 _dispatchHelpCommand(subcommandName) {1135 if (!subcommandName) {
12 unmodified lines
11481149 /**1150 * Check this.args against expected this._args.1151 *1152 * @api private1152 * @private1153 */11541155 _checkNumberOfArguments() {1156 // too few
13 unmodified lines
11701171 /**1172 * Process this.args using this._args and save as this.processedArgs!1173 *1174 * @api private1174 * @private1175 */11761177 _processArguments() {1178 const myParseArg = (argument, value, previous) => {
39 unmodified lines
1218 *1219 * @param {Promise|undefined} promise1220 * @param {Function} fn1221 * @return {Promise|undefined}1222 * @api private1222 * @private1223 */12241225 _chainOrCall(promise, fn) {1226 // thenable
9 unmodified lines
1236 *1237 * @param {Promise|undefined} promise1238 * @param {string} event1239 * @return {Promise|undefined}1240 * @api private1240 * @private1241 */12421243 _chainOrCallHooks(promise, event) {1244 let result = promise;
23 unmodified lines
1268 * @param {Promise|undefined} promise1269 * @param {Command} subCommand1270 * @param {string} event1271 * @return {Promise|undefined}1272 * @api private1272 * @private1273 */12741275 _chainOrCallSubCommandHook(promise, subCommand, event) {1276 let result = promise;
10 unmodified lines
1287 /**1288 * Process arguments in context of this command.1289 * Returns action result, in case it is a promise.1290 *1291 * @api private1291 * @private1292 */12931294 _parseCommand(operands, unknown) {1295 const parsed = this.parseOptions(unknown);
9 unmodified lines
1305 if (this._hasImplicitHelpCommand() && operands[0] === this._helpCommandName) {1306 return this._dispatchHelpCommand(operands[1]);1307 }1308 if (this._defaultCommandName) {1309 outputHelpIfRequested(this, unknown); // Run the help for default command from parent rather than passing to default command1309 this._outputHelpIfRequested(unknown); // Run the help for default command from parent rather than passing to default command1310 return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);1311 }1312 if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {1313 // probably missing subcommand and no handler, user needs help (and exit)1314 this.help({ error: true });1315 }13161317 outputHelpIfRequested(this, parsed.unknown);1317 this._outputHelpIfRequested(parsed.unknown);1318 this._checkForMissingMandatoryOptions();1319 this._checkForConflictingOptions();13201321 // We do not always call this check to avoid masking a "better" error, like unknown command.
49 unmodified lines
13711372 /**1373 * Find matching command.1374 *1375 * @api private1375 * @private1376 */1377 _findCommand(name) {1378 if (!name) return undefined;1379 return this.commands.find(cmd => cmd._name === name || cmd._aliases.includes(name));
3 unmodified lines
1383 * Return an option matching `arg` if any.1384 *1385 * @param {string} arg1386 * @return {Option}1387 * @api private1387 * @package internal use only1388 */13891390 _findOption(arg) {1391 return this.options.find(option => option.is(arg));
2 unmodified lines
1394 /**1395 * Display an error message if a mandatory option does not have a value.1396 * Called after checking for help flags in leaf subcommand.1397 *1398 * @api private1398 * @private1399 */14001401 _checkForMissingMandatoryOptions() {1402 // Walk up hierarchy so can call in subcommand after checking for displaying help.
8 unmodified lines
14111412 /**1413 * Display an error message if conflicting options are used together in this.1414 *1415 * @api private1415 * @private1416 */1417 _checkForConflictingLocalOptions() {1418 const definedNonDefaultOptions = this.options.filter(1419 (option) => {
22 unmodified lines
1442 /**1443 * Display an error message if conflicting options are used together.1444 * Called after checking for help flags in leaf subcommand.1445 *1446 * @api private1446 * @private1447 */1448 _checkForConflictingOptions() {1449 // Walk up hierarchy so can call in subcommand after checking for displaying help.1450 this._getCommandAndAncestors().forEach((cmd) => {
195 unmodified lines
1646 /**1647 * Apply any option related environment variables, if option does1648 * not have a value from cli or client code.1649 *1650 * @api private1650 * @private1651 */1652 _parseOptionsEnv() {1653 this.options.forEach((option) => {1654 if (option.envVar && option.envVar in process.env) {
14 unmodified lines
16691670 /**1671 * Apply any implied option values, if option is undefined or default value.1672 *1673 * @api private1673 * @private1674 */1675 _parseOptionsImplied() {1676 const dualHelper = new DualOptions(this.options);1677 const hasCustomOptionValue = (optionKey) => {
15 unmodified lines
1693 /**1694 * Argument `name` is missing.1695 *1696 * @param {string} name1697 * @api private1697 * @private1698 */16991700 missingArgument(name) {1701 const message = `error: missing required argument '${name}'`;
3 unmodified lines
1705 /**1706 * `Option` is missing an argument.1707 *1708 * @param {Option} option1709 * @api private1709 * @private1710 */17111712 optionMissingArgument(option) {1713 const message = `error: option '${option.flags}' argument missing`;
3 unmodified lines
1717 /**1718 * `Option` does not have a value, and is a mandatory option.1719 *1720 * @param {Option} option1721 * @api private1721 * @private1722 */17231724 missingMandatoryOptionValue(option) {1725 const message = `error: required option '${option.flags}' not specified`;
4 unmodified lines
1730 * `Option` conflicts with another option.1731 *1732 * @param {Option} option1733 * @param {Option} conflictingOption1734 * @api private1734 * @private1735 */1736 _conflictingOption(option, conflictingOption) {1737 // The calling code does not know whether a negated option is the source of the1738 // value, so do some work to take an educated guess.
28 unmodified lines
1767 /**1768 * Unknown option `flag`.1769 *1770 * @param {string} flag1771 * @api private1771 * @private1772 */17731774 unknownOption(flag) {1775 if (this._allowUnknownOption) return;
20 unmodified lines
1796 /**1797 * Excess arguments, more than expected.1798 *1799 * @param {string[]} receivedArgs1800 * @api private1800 * @private1801 */18021803 _excessArguments(receivedArgs) {1804 if (this._allowExcessArguments) return;
7 unmodified lines
18121813 /**1814 * Unknown command.1815 *1816 * @api private1816 * @private1817 */18181819 unknownCommand() {1820 const unknownName = this.args[0];
201 unmodified lines
2022 return helper.formatHelp(this, helper);2023 }20242025 /**2026 * @api private2026 * @private2027 */20282029 _getHelpContext(contextOptions) {2030 contextOptions = contextOptions || {};
117 unmodified lines
2148 }2149 });2150 return this;2151 }2152}21522154/**2155 * Output help information if help flags specified2156 *2157 * @param {Command} cmd - command to output help for2158 * @param {Array} args - array of options to search for help flags2159 * @api private2160 */2153 /**2154 * Output help information if help flags specified2155 *2156 * @param {Array} args - array of options to search for help flags2157 * @private2158 */21592162function outputHelpIfRequested(cmd, args) {2163 const helpOption = cmd._hasHelpOption && args.find(arg => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);2164 if (helpOption) {2165 cmd.outputHelp();2166 // (Do not have all displayed text available so only passing placeholder.)2167 cmd._exit(0, 'commander.helpDisplayed', '(outputHelp)');2160 _outputHelpIfRequested(args) {2161 const helpOption = this._hasHelpOption && args.find(arg => arg === this._helpLongFlag || arg === this._helpShortFlag);2162 if (helpOption) {2163 this.outputHelp();2164 // (Do not have all displayed text available so only passing placeholder.)2165 this._exit(0, 'commander.helpDisplayed', '(outputHelp)');2166 }2167 }2168}21692170/**2171 * Scan arguments and increment port number for inspect calls (to avoid conflicts when spawning new command).2172 *2173 * @param {string[]} args - array of arguments from node.execArgv2174 * @returns {string[]}2176 * @api private2175 * @private2176 */21772178function incrementNodeInspectorPort(args) {2179 // Testing for these options:
38 unmodified lines
modified:lib/option.js+5 added-6 removed
158 unmodified lines
159 return this;160 }161162 /**163 * @api private163 * @package internal use only164 */165166 _concatValue(value, previous) {167 if (previous === this.defaultValue || !Array.isArray(previous)) {
41 unmodified lines
209 * Return option name, in a camelcase format that can be used210 * as a object attribute key.211 *212 * @return {string}213 * @api private213 */214215 attributeName() {216 return camelcase(this.name().replace(/^no-/, ''));
3 unmodified lines
220 * Check if `arg` matches the short or long flag.221 *222 * @param {string} arg223 * @return {boolean}225 * @api private224 * @package internal use only225 */226227 is(arg) {228 return this.short === arg || this.long === arg;
4 unmodified lines
233 *234 * Options are one of boolean, negated, required argument, or optional argument.235 *236 * @return {boolean}238 * @api private237 * @package internal use only238 */239240 isBoolean() {241 return !this.required && !this.optional && !this.negate;
51 unmodified lines
293 * Convert string from kebab-case to camelCase.294 *295 * @param {string} str296 * @return {string}298 * @api private297 * @private298 */299300function camelcase(str) {301 return str.split('-').reduce((str, word) => {
3 unmodified lines
305306/**307 * Split the short and long flag out of something like '-m,--mixed <value>'308 *310 * @api private309 * @private310 */311312function splitOptionFlags(flags) {313 let shortFlag;
17 unmodified lines