Expand help customisation with .addHelpText#1296
Expand help customisation with .addHelpText#1296shadowspawn merged 39 commits intotj:release/7.xfrom
Conversation
|
Hi there, one thing I badly wanted from commander was the ability to group commands and options in help output, for readability. I implemented it as a quick hack here: https://github.com/westhom/commander.js/compare/c5a5e7b7..86a1980b. For commands, you can call I was going to open a PR for this but it looks like help is being revamped. It could be nice to have a grouping option like that. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
To be safe, the change to use The other changes are backwards compatible, as the |
This comment has been minimized.
This comment has been minimized.
|
I am happier with how this is looking now with an explicit routine which is more readable than an event listener, and leaving the ability to override the built-in help out of this routine. |
|
I deprecated the callbacks to |
|
Could you merge |
|
Oops, will do. I was merging 6.1 into the PR so the diff against develop looked better, missed doing 7.x too. |
|
I have merged |
|
Only a (minor) issue in the new version:
A little confusing. If case 1 should behave as Besides this minor issue, the new version is excellent. Thanks! |
|
Case 2 is a special case. If there is an empty string then nothing is output. This is to support a function generating the string deciding that there is nothing to be displayed. |
|
OK, understand. Maybe adding a line to documentation stating this could be useful. Something like this at the end of the Custom help paragraph: “If the string or the output of the function is an empty string, nothing is output, otherwise the string is output followed by a newline”. |
Pull Request
Problem
stdouteven when being displayed as an "error"See #1225 for collected custom help issues, and #997 for error output.
Solution
Add
.addHelpText()which takes a position as first parameter, and a string to add or a function returning a string. Position is 'before' or 'after' to affect just this command, and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.For example:
Also:
.help()and.outputHelp()can be passed{ error: true }to write to stderr..help()and.outputHelp().on('--help')ChangeLog
.addHelpText()to add text before or after the built-in help, for just current command or also for all subcommands (Expand help customisation with .addHelpText #1296).help()and.outputHelp()(removed from README).on('--help')(removed from README)