Follow jsdoc and tsdoc more closely, especially @example (#1562)
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 5517d25 · Browse files · 2 files·+159 added−157 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+159 added−157 removed
- other:+159 added−157 removed
Provenance
- Commit
56c4108- Tree
6b459ac- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
5517d25
2 files changed+159 added−157 removed
modified:lib/command.js+72 added-80 removed
105 unmodified lines106 * Define a command.107 *108 * There are two styles of command: pay attention to where to put the description.109 *110- * Examples:110+ * @example111+ * // Command implemented using action handler (description is supplied separately to `.command`)112+ * program113+ * .command('clone <source> [destination]')114+ * .description('clone a repository into a newly created directory')115+ * .action((source, destination) => {116+ * console.log('clone command called');117+ * });118 *112- * // Command implemented using action handler (description is supplied separately to `.command`)113- * program114- * .command('clone <source> [destination]')115- * .description('clone a repository into a newly created directory')116- * .action((source, destination) => {117- * console.log('clone command called');118- * });119+ * // Command implemented using separate executable file (description is second parameter to `.command`)120+ * program121+ * .command('start <service>', 'start named service')122+ * .command('stop [service]', 'stop named service, or all if no name supplied');123 *120- * // Command implemented using separate executable file (description is second parameter to `.command`)121- * program122- * .command('start <service>', 'start named service')123- * .command('stop [service]', 'stop named service, or all if no name supplied');124- *124 * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`125 * @param {Object|string} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)126 * @param {Object} [execOpts] - configuration options (for executable)127 * @return {Command} returns new command for action handler, or `this` for executable command71 unmodified lines199 * applications. You can also customise the display of errors by overriding outputError.200 *201 * The configuration properties are all functions:202 *204- * // functions to change where being written, stdout and stderr205- * writeOut(str)206- * writeErr(str)207- * // matching functions to specify width for wrapping help208- * getOutHelpWidth()209- * getErrHelpWidth()210- * // functions based on what is being written out211- * outputError(str, write) // used for displaying errors, and not used for displaying help203+ * // functions to change where being written, stdout and stderr204+ * writeOut(str)205+ * writeErr(str)206+ * // matching functions to specify width for wrapping help207+ * getOutHelpWidth()208+ * getErrHelpWidth()209+ * // functions based on what is being written out210+ * outputError(str, write) // used for displaying errors, and not used for displaying help211 *212 * @param {Object} [configuration] - configuration options213 * @return {Command|Object} `this` command for chaining, or stored configuration214 */72 unmodified lines287 * The default is that the argument is required, and you can explicitly288 * indicate this with <> around the name. Put [] around the name for an optional argument.289 *290 * @example291+ * program.argument('<input-file>');292+ * program.argument('[output-file]');293 *293- * program.argument('<input-file>');294- * program.argument('[output-file]');295- *294 * @param {string} name295 * @param {string} [description]296 * @param {Function|*} [fn] - custom argument processing function297 * @param {*} [defaultValue]15 unmodified lines313 *314 * See also .argument().315 *316 * @example317+ * program.arguments('<cmd> [env]');318 *320- * program.arguments('<cmd> [env]');321- *319 * @param {string} names320 * @return {Command} `this` command for chaining321 */322 122 unmodified lines445 446 /**447 * Register callback `fn` for the command.448 *452- * Examples:449+ * @example450+ * program451+ * .command('help')452+ * .description('display verbose help')453+ * .action(function() {454+ * // output help here455+ * });456 *454- * program455- * .command('help')456- * .description('display verbose help')457- * .action(function() {458- * // output help here459- * });460- *457 * @param {Function} fn458 * @return {Command} `this` command for chaining459 */460 129 unmodified lines590 * The `flags` string contains the short and/or long flags,591 * separated by comma, a pipe or space. The following are all valid592 * all will output this way when `--help` is used.593 *598- * "-p, --pepper"599- * "-p|--pepper"600- * "-p --pepper"594+ * "-p, --pepper"595+ * "-p|--pepper"596+ * "-p --pepper"597 *602- * Examples:598+ * @example599+ * // simple boolean defaulting to undefined600+ * program.option('-p, --pepper', 'add pepper');601 *604- * // simple boolean defaulting to undefined605- * program.option('-p, --pepper', 'add pepper');602+ * program.pepper603+ * // => undefined604 *607- * program.pepper608- * // => undefined605+ * --pepper606+ * program.pepper607+ * // => true608 *610- * --pepper611- * program.pepper612- * // => true609+ * // simple boolean defaulting to true (unless non-negated option is also defined)610+ * program.option('-C, --no-cheese', 'remove cheese');611 *614- * // simple boolean defaulting to true (unless non-negated option is also defined)615- * program.option('-C, --no-cheese', 'remove cheese');612+ * program.cheese613+ * // => true614 *617- * program.cheese618- * // => true615+ * --no-cheese616+ * program.cheese617+ * // => false618 *620- * --no-cheese621- * program.cheese622- * // => false619+ * // required argument620+ * program.option('-C, --chdir <path>', 'change the working directory');621 *624- * // required argument625- * program.option('-C, --chdir <path>', 'change the working directory');622+ * --chdir /tmp623+ * program.chdir624+ * // => "/tmp"625 *627- * --chdir /tmp628- * program.chdir629- * // => "/tmp"626+ * // optional argument627+ * program.option('-c, --cheese [type]', 'add cheese [marble]');628 *631- * // optional argument632- * program.option('-c, --cheese [type]', 'add cheese [marble]');633- *629 * @param {string} flags630 * @param {string} [description]631 * @param {Function|*} [fn] - custom option processing function or default value632 * @param {*} [defaultValue]23 unmodified lines656 657 /**658 * Alter parsing of short flags with optional values.659 *665- * Examples:660+ * @example661+ * // for `.option('-f,--flag [value]'):662+ * program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour663+ * program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`664 *667- * // for `.option('-f,--flag [value]'):668- * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour669- * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`670- *665 * @param {Boolean} [combine=true] - if `true` or omitted, an optional value can be specified directly after the flag.666 */667 combineFlagAndOptionalValue(combine = true) {668 this._combineFlagAndOptionalValue = !!combine;159 unmodified lines828 *829 * The default expectation is that the arguments are from node and have the application as argv[0]830 * and the script being run in argv[1], with user parameters after that.831 *838- * Examples:832+ * @example833+ * program.parse(process.argv);834+ * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions835+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]836 *840- * program.parse(process.argv);841- * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions842- * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]843- *837 * @param {string[]} [argv] - optional, defaults to process.argv838 * @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron839 * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'840 * @return {Command} `this` command for chaining13 unmodified lines854 *855 * The default expectation is that the arguments are from node and have the application as argv[0]856 * and the script being run in argv[1], with user parameters after that.857 *865- * Examples:858+ * @example859+ * await program.parseAsync(process.argv);860+ * await program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions861+ * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]862 *867- * await program.parseAsync(process.argv);868- * await program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions869- * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]870- *863 * @param {string[]} [argv]864 * @param {Object} [parseOptions]865 * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'866 * @return {Promise}380 unmodified lines1247 * and return argv split into operands and unknown arguments.1248 *1249 * Examples:1250 *1259- * argv => operands, unknown1260- * --known kkk op => [op], []1261- * op --known kkk => [op], []1262- * sub --unknown uuu op => [sub], [--unknown uuu op]1263- * sub -- --unknown uuu op => [sub --unknown uuu op], []1251+ * argv => operands, unknown1252+ * --known kkk op => [op], []1253+ * op --known kkk => [op], []1254+ * sub --unknown uuu op => [sub], [--unknown uuu op]1255+ * sub -- --unknown uuu op => [sub --unknown uuu op], []1256 *1257 * @param {String[]} argv1258 * @return {{operands: String[], unknown: String[]}}1259 */584 unmodified linesmodified:typings/index.d.ts+87 added-77 removed
11 unmodified lines12 nestedError?: string;13 14 /**15 * Constructs the CommanderError class16- * @param {number} exitCode suggested exit code which could be used with process.exit17- * @param {string} code an id string representing the error18- * @param {string} message human-readable description of the error16+ * @param exitCode - suggested exit code which could be used with process.exit17+ * @param code - an id string representing the error18+ * @param message - human-readable description of the error19 * @constructor20 */21 constructor(exitCode: number, code: string, message: string);22 }23 24 export class InvalidArgumentError extends CommanderError {25 /**26 * Constructs the InvalidArgumentError class27- * @param {string} [message] explanation of why argument is invalid27+ * @param message - explanation of why argument is invalid28 * @constructor29 */30 constructor(message: string);31 }7 unmodified lines39 /**40 * Initialize a new command argument with the given name and description.41 * The default is that the argument is required, and you can explicitly42 * indicate this with <> around the name. Put [] around the name for an optional argument.43- *44- * @param {string} name45- * @param {string} [description]43 */44 constructor(arg: string, description?: string);45 46 /**190 unmodified lines237 * The command description is supplied using `.description`, not as a parameter to `.command`.238 *239 * @example240 * ```ts244- * program245- * .command('clone <source> [destination]')246- * .description('clone a repository into a newly created directory')247- * .action((source, destination) => {248- * console.log('clone command called');249- * });241+ * program242+ * .command('clone <source> [destination]')243+ * .description('clone a repository into a newly created directory')244+ * .action((source, destination) => {245+ * console.log('clone command called');246+ * });247 * ```248 *249 * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`250 * @param opts - configuration options51 unmodified lines302 * The default is that the argument is required, and you can explicitly303 * indicate this with <> around the name. Put [] around the name for an optional argument.304 *305 * @example306+ * ```307+ * program.argument('<input-file>');308+ * program.argument('[output-file]');309+ * ```310 *310- * program.argument('<input-file>');311- * program.argument('[output-file]');312- *311 * @returns `this` command for chaining312 */313 argument<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;314 argument(name: string, description?: string, defaultValue?: unknown): this;10 unmodified lines325 *326 * See also .argument().327 *328 * @example329+ * ```330+ * program.arguments('<cmd> [env]');331+ * ```332 *332- * program.arguments('<cmd> [env]');333- *333 * @returns `this` command for chaining334 */335 arguments(names: string): this;336 337 /**338 * Override default decision whether to add implicit help command.339 *340+ * @example341+ * ```341- * addHelpCommand() // force on342- * addHelpCommand(false); // force off343- * addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details342+ * addHelpCommand() // force on343+ * addHelpCommand(false); // force off344+ * addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details345+ * ```346 *347 * @returns `this` command for chaining348 */349 addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this;26 unmodified lines376 * The default output goes to stdout and stderr. You can customise this for special377 * applications. You can also customise the display of errors by overriding outputError.378 *379 * The configuration properties are all functions:378- *379- * // functions to change where being written, stdout and stderr380- * writeOut(str)381- * writeErr(str)382- * // matching functions to specify width for wrapping help383- * getOutHelpWidth()384- * getErrHelpWidth()385- * // functions based on what is being written out386- * outputError(str, write) // used for displaying errors, and not used for displaying help380+ * ```381+ * // functions to change where being written, stdout and stderr382+ * writeOut(str)383+ * writeErr(str)384+ * // matching functions to specify width for wrapping help385+ * getOutHelpWidth()386+ * getErrHelpWidth()387+ * // functions based on what is being written out388+ * outputError(str, write) // used for displaying errors, and not used for displaying help389+ * ```390 */391 configureOutput(configuration: OutputConfiguration): this;392 /** Get configuration */393 configureOutput(): OutputConfiguration;13 unmodified lines407 /**408 * Register callback `fn` for the command.409 *410 * @example411+ * ```408- * program409- * .command('help')410- * .description('display verbose help')411- * .action(function() {412- * // output help here413- * });412+ * program413+ * .command('help')414+ * .description('display verbose help')415+ * .action(function() {416+ * // output help here417+ * });418+ * ```419 *420 * @returns `this` command for chaining421 */422 action(fn: (...args: any[]) => void | Promise<void>): this;5 unmodified lines428 * The `flags` string contains the short and/or long flags,429 * separated by comma, a pipe or space. The following are all valid430 * all will output this way when `--help` is used.431 *427- * "-p, --pepper"428- * "-p|--pepper"429- * "-p --pepper"432+ * "-p, --pepper"433+ * "-p|--pepper"434+ * "-p --pepper"435 *436 * @example437+ * ```432- * // simple boolean defaulting to false433- * program.option('-p, --pepper', 'add pepper');438+ * // simple boolean defaulting to false439+ * program.option('-p, --pepper', 'add pepper');440 *435- * --pepper436- * program.pepper437- * // => Boolean441+ * --pepper442+ * program.pepper443+ * // => Boolean444 *439- * // simple boolean defaulting to true440- * program.option('-C, --no-cheese', 'remove cheese');445+ * // simple boolean defaulting to true446+ * program.option('-C, --no-cheese', 'remove cheese');447 *442- * program.cheese443- * // => true448+ * program.cheese449+ * // => true450 *445- * --no-cheese446- * program.cheese447- * // => false451+ * --no-cheese452+ * program.cheese453+ * // => false454 *449- * // required argument450- * program.option('-C, --chdir <path>', 'change the working directory');455+ * // required argument456+ * program.option('-C, --chdir <path>', 'change the working directory');457 *452- * --chdir /tmp453- * program.chdir454- * // => "/tmp"458+ * --chdir /tmp459+ * program.chdir460+ * // => "/tmp"461 *456- * // optional argument457- * program.option('-c, --cheese [type]', 'add cheese [marble]');462+ * // optional argument463+ * program.option('-c, --cheese [type]', 'add cheese [marble]');464+ * ```465 *466 * @returns `this` command for chaining467 */468 option(flags: string, description?: string, defaultValue?: string | boolean): this;51 unmodified lines520 /**521 * Alter parsing of short flags with optional values.522 *523 * @example524+ * ```517- * // for `.option('-f,--flag [value]'):518- * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour519- * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`525+ * // for `.option('-f,--flag [value]'):526+ * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour527+ * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`528+ * ```529 *530 * @returns `this` command for chaining531 */532 combineFlagAndOptionalValue(combine?: boolean): this;38 unmodified lines571 *572 * The default expectation is that the arguments are from node and have the application as argv[0]573 * and the script being run in argv[1], with user parameters after that.574 *566- * Examples:575+ * @example576+ * ```577+ * program.parse(process.argv);578+ * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions579+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]580+ * ```581 *568- * program.parse(process.argv);569- * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions570- * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]571- *582 * @returns `this` command for chaining583 */584 parse(argv?: string[], options?: ParseOptions): this;585 4 unmodified lines590 *591 * The default expectation is that the arguments are from node and have the application as argv[0]592 * and the script being run in argv[1], with user parameters after that.593 *584- * Examples:594+ * @example595+ * ```596+ * program.parseAsync(process.argv);597+ * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions598+ * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]599+ * ```600 *586- * program.parseAsync(process.argv);587- * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions588- * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]589- *601 * @returns Promise602 */603 parseAsync(argv?: string[], options?: ParseOptions): Promise<this>;604 605 /**606 * Parse options from `argv` removing known options,607 * and return argv split into operands and unknown arguments.608 *598- * @example599- * argv => operands, unknown600- * --known kkk op => [op], []601- * op --known kkk => [op], []602- * sub --unknown uuu op => [sub], [--unknown uuu op]603- * sub -- --unknown uuu op => [sub --unknown uuu op], []609+ * argv => operands, unknown610+ * --known kkk op => [op], []611+ * op --known kkk => [op], []612+ * sub --unknown uuu op => [sub], [--unknown uuu op]613+ * sub -- --unknown uuu op => [sub --unknown uuu op], []614 */615 parseOptions(argv: string[]): ParseOptionsResult;616 617 /**132 unmodified lines