-
-
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.
Expand help customisation with .addHelpText (#1296)
* Add new help events * Add context for new help events * Rename and use help context * Suppress help output * Slight tidy of legacy callback handling * Shift help contextOptions up to public API * Fix some spelling errors * Start adding tests. Fix groupHelp. * Test help event order * Add tests on context * Add missing semicolon * Add context.error tests * First cut at README adding events and removing callbacks * Add typings and parameter descriptions * Change from --help to postHelp event * Update and add custom help examples * Make help listener example more realistic * Update example * Call the old callback, deprecated * First cut at .addHelp() * Change name to addHelpText * First round of tests for addHelpText * Simplify help event context, remove log * Assign write directly * Add end-to-end and context checks for addHelpText * Put back write wrapper to fix unit test * Fix write mocks for help-as-error output * Ignore falsy values for AddHelpText * Remove the help override from addHelpText as not good fit * Convert example to addHelpText * Update README * Add info about new .help param * Remove excess space * Update more examples * Remove references to override * Update docs with .addHelpText
- Loading branch information
1 parent
693a40f
commit d26a26d
Showing
13 changed files
with
476 additions
and
100 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
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,33 @@ | ||
#!/usr/bin/env node | ||
|
||
// This example shows using addHelpText. | ||
|
||
// const { Command } = require('commander'); // (normal include) | ||
const { Command } = require('../'); // include commander in git clone of commander repo | ||
const program = new Command(); | ||
|
||
program.name('awesome'); | ||
|
||
program | ||
.addHelpText('beforeAll', 'A W E S O M E\n') | ||
.addHelpText('afterAll', (context) => { | ||
if (context.error) { | ||
return '\nHelp being displayed for an error'; | ||
} | ||
return '\nSee web site for further help'; | ||
}); | ||
|
||
program | ||
.command('extra') | ||
.addHelpText('before', 'Note: the extra command does not do anything') | ||
.addHelpText('after', ` | ||
Examples: | ||
awesome extra --help | ||
awesome help extra`); | ||
|
||
program.parse(); | ||
|
||
// Try the following: | ||
// node custom-help-text.js --help | ||
// node custom-help-text.js extra --help | ||
// node custom-help-text.js |
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
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
Oops, something went wrong.