Skip to content
Myr

Add optional summary for short form of subcommand description. (#1726)

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

For backwards compatibility, the description is used for the subcommand listing if the summary is missing. So by default there is no change in existing programs.

authored by John Gee · committed by GitHub · parent d660967 · Browse files · 8 files+97 added−26 removed
This commit

State

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

Diff stats

8 files+97 added−26 removed

  • tests:+45 added−20 removed
  • other:+52 added−6 removed

8 files+97 added−26 removed

modified:lib/command.js+14 added-1 removed
46 unmodified lines
47 this._exitCallback = null;48 this._aliases = [];49 this._combineFlagAndOptionalValue = true;50 this._description = '';51 this._summary = '';52 this._argsDescription = undefined; // legacy53 this._enablePositionalOptions = false;54 this._passThroughOptions = false;55 this._lifeCycleHooks = {}; // a hash of arrays
1711 unmodified lines
1767 return this;1768 }17691770 /**1770 * Set the description to `str`.1771 * Set the description.1772 *1773 * @param {string} [str]1774 * @param {Object} [argsDescription]1775 * @return {string|Command}
7 unmodified lines
1783 return this;1784 }17851786 /**1787 * Set the summary. Used when listed as subcommand of parent.1788 *1789 * @param {string} [str]1790 * @return {string|Command}1791 */1792 summary(str) {1793 if (str === undefined) return this._summary;1794 this._summary = str;1795 return this;1796 }17971798 /**1799 * Set an alias for the command.1800 *1801 * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.1802 *
333 unmodified lines
modified:lib/help.js+3 added-2 removed
213 unmodified lines
214 return cmd.description();215 }216217 /**218 * Get the command description to show in the list of subcommands.218 * Get the subcommand summary to show in the list of subcommands.219 * (Fallback to description for backwards compatiblity.)220 *221 * @param {Command} cmd222 * @returns {string}223 */224225 subcommandDescription(cmd) {226 // @ts-ignore: overloaded return type226 return cmd.description();227 return cmd.summary() || cmd.description();228 }229230 /**231 * Get the option description to show in the list of options.
175 unmodified lines
added:tests/command.summary.test.js+8 added
deleted:tests/help.commandDescription.test.js-20 removed
added:tests/help.subcommandDescription.test.js+37 added
modified:typings/index.d.ts+13 added-1 removed
200 unmodified lines
201 constructor();202203 /** Get the command term to show in the list of subcommands. */204 subcommandTerm(cmd: Command): string;205 /** Get the command description to show in the list of subcommands. */205 /** Get the command summary to show in the list of subcommands. */206 subcommandDescription(cmd: Command): string;207 /** Get the option term to show in the list of options. */208 optionTerm(option: Option): string;209 /** Get the option description to show in the list of options. */
508 unmodified lines
718 */719 description(): string;720721 /**722 * Set the summary. Used when listed as subcommand of parent.723 *724 * @returns `this` command for chaining725 */726727 summary(str: string): this;728 /**729 * Get the summary.730 */731 summary(): string;732733 /**734 * Set an alias for the command.735 *736 * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.737 *
142 unmodified lines
modified:typings/index.test-d.ts+4 added
237 unmodified lines
238expectType<commander.Command>(program.description('my description'));239expectType<string>(program.description());240expectType<commander.Command>(program.description('my description of command with arg foo', { foo: 'foo description' })); // deprecated241242// summary243expectType<commander.Command>(program.summary('my summary'));244expectType<string>(program.summary());245246// alias247expectType<commander.Command>(program.alias('my alias'));248expectType<string>(program.alias());249
219 unmodified lines
modified:Readme.md+18 added-2 removed
33 unmodified lines
34 - [Display help after errors](#display-help-after-errors)35 - [Display help from code](#display-help-from-code)36 - [.name](#name)37 - [.usage](#usage)38 - [.description and .summary](#description-and-summary)39 - [.helpOption(flags, description)](#helpoptionflags-description)40 - [.addHelpCommand()](#addhelpcommand)41 - [More configuration](#more-configuration-2)42 - [Custom event listeners](#custom-event-listeners)
771 unmodified lines
814error: unknown option '--unknown'815(add --help for additional information)816```817817You can also show suggestions after an error for an unknown command or option.818The default behaviour is to suggest correct spelling after an error for an unknown command or option. You819can disable this.820821```js820program.showSuggestionAfterError();822program.showSuggestionAfterError(false);823```824825```console826$ pizza --hepl
40 unmodified lines
867```Text868Usage: my-command [global options] command869```870871### .description and .summary872873The description appears in the help for the command. You can optionally supply a shorter874summary to use when listed as a subcommand of the program.875876```js877program878 .command("duplicate")879 .summary("make a copy")880 .description(`Make a copy of the current project.881This may require additional disk space.882 `);883```884885### .helpOption(flags, description)886887By default every command has a help option. You may change the default help flags and description. Pass false to disable the built-in help option.888
226 unmodified lines