-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor help internals into separate interface/class (#1365)
* Start filling out HelpUtils to try pattern * Shift the largestFoo routines into helper * Update generation of Commands section of help * Rework helpInformation in consistent new style * Remove unused routines * Make columns part of HelpUtils * Offer a light weight override to HelpUtils * Tweak comment * Add chain test for helpUtilOverrides * Add itemIndent as another proof of concept of allowing overrides * Avoid Utils contraction * Update comments * Switch columns from function to data property * Remove itemIndent(), not useful enough alone or as a pattern for now * Make _helpToolsOverrides inherited * Improve naming for termWidth * Move usage into HelpTools * Add term and description routines to HelpTools so symmetrical pattern * Name the magic numbers * More consistent naming * Remove reference to removed routine * Move help formatting into HelpTools * Fix typescript-checkJS errors * Simpler naming * Slightly simplify code * Add getter/setter to assist overrides * Add sort overrides * First cut at TypeScript definitions for Help, no TSDoc yet * Replace pad and low level indents with modern calls * Rename and rework type for HelpConfiguration * Combine optionalWrap and wrap * Add createHelp to TypeScript definition * Add test-all script * More carefully make concrete help option for displaying * Fix test with valid parameters for custom help * Start adding Help tests * Add largestCommandTermLength tests * Add more Help tests * Add commandUsage tests * Add test for commandDescription * Add missing Command properties, and default description to empty string * Add tests for optionDescription * Add padWidth tests * Add sort tests * Add columns and wrap tests * Add test for legacy commandTerm behaviour * Add TypeScript usage tests for Help * Refactor Help tests into separate files * Add tests for createHelp and configureHelp * Add JSDoc for Help. Rename methods. Delete @api public as default. * Add TSDoc for Help * Test special caes of implicit help flags * Clarify method naming * Shift the Usage prefix into formatHelp * Add Help class mention and reorder help * Add simple configure-help example * Add example file to README * Rename to sortSubcommands to match other naming * Do not weaken configuration type, user can extend as required * Do not cache implicit help command calculation so safer (no need, not being thrashed) * Add JSDoc for configureHelp * Add TSDoc * Add missing TSDoc * Switch option sort to use attributeName, with negative after positive * No need for string template literal * No need for string template literal
- Loading branch information
1 parent
b0c5884
commit 19ae912
Showing
28 changed files
with
1,439 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// const commander = require('commander'); // (normal include) | ||
const commander = require('../'); // include commander in git clone of commander repo | ||
|
||
const program = new commander.Command(); | ||
|
||
// This example shows a simple use of configureHelp. | ||
// This is used as an example in the README. | ||
|
||
program.configureHelp({ | ||
sortSubcommands: true, | ||
subcommandTerm: (cmd) => cmd.name() // Just show the name, instead of short usage. | ||
}); | ||
|
||
program.command('zebra <herd-size>', 'African equines with distinctive black-and-white striped coats'); | ||
program.command('aardvark [colour]', 'medium-sized, burrowing, nocturnal mammal'); | ||
program | ||
.command('beaver', 'large, semiaquatic rodent') | ||
.option('--pond') | ||
.option('--river'); | ||
|
||
program.parse(); | ||
|
||
// Try the following: | ||
// node configure-help.js --help |
Oops, something went wrong.