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
Provenance
- Commit
37c9398- Tree
f469439- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
c876dee
3 files changed+54 added−56 removed
modified:lib/argument.js+2 added-2 removed
50 unmodified lines5152535455555657585971 unmodified lines1311321331341351351361371381398 unmodified lines50 unmodified lines return this._name; }
/** * @api private * @package internal use only */
_concatValue(value, previous) { if (previous === this.defaultValue || !Array.isArray(previous)) {71 unmodified lines * Takes an argument and returns its human readable equivalent for help usage. * * @param {Argument} arg * @return {string} * @api private * @private */
function humanReadableArgName(arg) { const nameOutput = arg.name() + (arg.variadic === true ? '...' : '');8 unmodified linesmodified:lib/command.js+47 added-48 removed
109 unmodified lines110 }111 112 /**113 * @returns {Command[]}114- * @api private114+ * @private115 */116 117 _getCommandAndAncestors() {118 const result = [];275 unmodified lines394 }395 396 /**397 * @return {boolean}398- * @api private398+ * @package internal use only399 */400 401 _hasImplicitHelpCommand() {402 if (this._addImplicitHelpCommand === undefined) {52 unmodified lines455 * @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 */461 462 _exit(exitCode, code, message) {463 if (this._exitCallback) {57 unmodified lines521 * @param {Option | Argument} target522 * @param {string} value523 * @param {any} previous524 * @param {string} invalidArgumentMessage525- * @api private525+ * @private526 */527 528 _callParseArg(target, value, previous, invalidArgumentMessage) {529 try {77 unmodified lines607 608 /**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 lines768 return this;769 }770 771 /**772- * @api private772+ * @private773 */774 775 _checkForBrokenPassThrough() {776 if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {99 unmodified lines876 /**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 */882 883 _prepareUserArgs(argv, parseOptions) {884 if (argv !== undefined && !Array.isArray(argv)) {94 unmodified lines979 980 /**981 * Execute a sub-command executable.982 *983- * @api private983+ * @private984 */985 986 _executeSubCommand(subcommand, args) {987 args = args.slice();116 unmodified lines1104 this.runningCommand = proc;1105 }1106 1107 /**1108- * @api private1108+ * @private1109 */1110 1111 _dispatchSubcommand(commandName, operands, unknown) {1112 const subCommand = this._findCommand(commandName);14 unmodified lines1127 /**1128 * Invoke help directly if possible, or dispatch if necessary.1129 * e.g. help foo1130 *1131- * @api private1131+ * @private1132 */1133 1134 _dispatchHelpCommand(subcommandName) {1135 if (!subcommandName) {12 unmodified lines1148 1149 /**1150 * Check this.args against expected this._args.1151 *1152- * @api private1152+ * @private1153 */1154 1155 _checkNumberOfArguments() {1156 // too few13 unmodified lines1170 1171 /**1172 * Process this.args using this._args and save as this.processedArgs!1173 *1174- * @api private1174+ * @private1175 */1176 1177 _processArguments() {1178 const myParseArg = (argument, value, previous) => {39 unmodified lines1218 *1219 * @param {Promise|undefined} promise1220 * @param {Function} fn1221 * @return {Promise|undefined}1222- * @api private1222+ * @private1223 */1224 1225 _chainOrCall(promise, fn) {1226 // thenable9 unmodified lines1236 *1237 * @param {Promise|undefined} promise1238 * @param {string} event1239 * @return {Promise|undefined}1240- * @api private1240+ * @private1241 */1242 1243 _chainOrCallHooks(promise, event) {1244 let result = promise;23 unmodified lines1268 * @param {Promise|undefined} promise1269 * @param {Command} subCommand1270 * @param {string} event1271 * @return {Promise|undefined}1272- * @api private1272+ * @private1273 */1274 1275 _chainOrCallSubCommandHook(promise, subCommand, event) {1276 let result = promise;10 unmodified lines1287 /**1288 * Process arguments in context of this command.1289 * Returns action result, in case it is a promise.1290 *1291- * @api private1291+ * @private1292 */1293 1294 _parseCommand(operands, unknown) {1295 const parsed = this.parseOptions(unknown);9 unmodified lines1305 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 }1316 1317- outputHelpIfRequested(this, parsed.unknown);1317+ this._outputHelpIfRequested(parsed.unknown);1318 this._checkForMissingMandatoryOptions();1319 this._checkForConflictingOptions();1320 1321 // We do not always call this check to avoid masking a "better" error, like unknown command.49 unmodified lines1371 1372 /**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 lines1383 * Return an option matching `arg` if any.1384 *1385 * @param {string} arg1386 * @return {Option}1387- * @api private1387+ * @package internal use only1388 */1389 1390 _findOption(arg) {1391 return this.options.find(option => option.is(arg));2 unmodified lines1394 /**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 */1400 1401 _checkForMissingMandatoryOptions() {1402 // Walk up hierarchy so can call in subcommand after checking for displaying help.8 unmodified lines1411 1412 /**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 lines1442 /**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 lines1646 /**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 lines1669 1670 /**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 lines1693 /**1694 * Argument `name` is missing.1695 *1696 * @param {string} name1697- * @api private1697+ * @private1698 */1699 1700 missingArgument(name) {1701 const message = `error: missing required argument '${name}'`;3 unmodified lines1705 /**1706 * `Option` is missing an argument.1707 *1708 * @param {Option} option1709- * @api private1709+ * @private1710 */1711 1712 optionMissingArgument(option) {1713 const message = `error: option '${option.flags}' argument missing`;3 unmodified lines1717 /**1718 * `Option` does not have a value, and is a mandatory option.1719 *1720 * @param {Option} option1721- * @api private1721+ * @private1722 */1723 1724 missingMandatoryOptionValue(option) {1725 const message = `error: required option '${option.flags}' not specified`;4 unmodified lines1730 * `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 lines1767 /**1768 * Unknown option `flag`.1769 *1770 * @param {string} flag1771- * @api private1771+ * @private1772 */1773 1774 unknownOption(flag) {1775 if (this._allowUnknownOption) return;20 unmodified lines1796 /**1797 * Excess arguments, more than expected.1798 *1799 * @param {string[]} receivedArgs1800- * @api private1800+ * @private1801 */1802 1803 _excessArguments(receivedArgs) {1804 if (this._allowExcessArguments) return;7 unmodified lines1812 1813 /**1814 * Unknown command.1815 *1816- * @api private1816+ * @private1817 */1818 1819 unknownCommand() {1820 const unknownName = this.args[0];201 unmodified lines2022 return helper.formatHelp(this, helper);2023 }2024 2025 /**2026- * @api private2026+ * @private2027 */2028 2029 _getHelpContext(contextOptions) {2030 contextOptions = contextOptions || {};117 unmodified lines2148 }2149 });2150 return this;2151 }2152-}2152 2154-/**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+ */2159 2162-function 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 }2169 2170 /**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 */2177 2178 function incrementNodeInspectorPort(args) {2179 // Testing for these options:38 unmodified linesmodified:lib/option.js+5 added-6 removed
158 unmodified lines159 return this;160 }161 162 /**163- * @api private163+ * @package internal use only164 */165 166 _concatValue(value, previous) {167 if (previous === this.defaultValue || !Array.isArray(previous)) {41 unmodified lines209 * Return option name, in a camelcase format that can be used210 * as a object attribute key.211 *212 * @return {string}213- * @api private213 */214 215 attributeName() {216 return camelcase(this.name().replace(/^no-/, ''));3 unmodified lines220 * Check if `arg` matches the short or long flag.221 *222 * @param {string} arg223 * @return {boolean}225- * @api private224+ * @package internal use only225 */226 227 is(arg) {228 return this.short === arg || this.long === arg;4 unmodified lines233 *234 * Options are one of boolean, negated, required argument, or optional argument.235 *236 * @return {boolean}238- * @api private237+ * @package internal use only238 */239 240 isBoolean() {241 return !this.required && !this.optional && !this.negate;51 unmodified lines293 * Convert string from kebab-case to camelCase.294 *295 * @param {string} str296 * @return {string}298- * @api private297+ * @private298 */299 300 function camelcase(str) {301 return str.split('-').reduce((str, word) => {3 unmodified lines305 306 /**307 * Split the short and long flag out of something like '-m,--mixed <value>'308 *310- * @api private309+ * @private310 */311 312 function splitOptionFlags(flags) {313 let shortFlag;17 unmodified lines