Add custom usage compatibility to help menu#1853
Add custom usage compatibility to help menu#1853hiimjasmine00 wants to merge 2 commits intotj:developfrom
Conversation
|
(The "legacy" comment was that it was fairly simple and different to what is displayed in the subcommand help, but had displayed that way for a long time and I didn't have a reason to change it when I rewrote the help.) |
lib/help.js
Outdated
| const args = cmd._args.map(arg => humanReadableArgName(arg)).join(' '); | ||
| return cmd._name + | ||
| (cmd._aliases[0] ? '|' + cmd._aliases[0] : '') + | ||
| const term = cmd._name + (cmd._aliases[0] ? '|' + cmd._aliases[0] : ''); |
There was a problem hiding this comment.
Minor: "term" is used to describe the whole thing, so I would like a different variable name here. Maybe cmdNames?
|
Some thoughts, no conclusions yet! High level, this is doing same as displaying A high level concern is that in the display of the help for the command, the usage and the description are displayed on separate lines. When listing the subcommands, we add the description directly after the usage: (Side note: by default every command gets The usage generated by Commander is pretty simplistic. Unix commands often show at least all the single letter options, and sometimes multiple lines of different use cases in the synopsis. That isn't the thing we are trying to solve here, but it does suggest that custom usage lines may be longer than the simple default one. For example We had a similar problem with the description, that a long description is good for the full help but may suck when displaying in a list of subcommands. To solve that we added |
If is fairly easy to display full usage, but I acknowledge that if it is extra work. function fullUsage(cmd) {
const cmdNames = cmd.name() + (cmd.alias() ? '|' + cmd.alias() : '');
return cmdNames + ' ' + cmd.usage();
}
program.configureHelp({ subcommandTerm: fullUsage }); |
|
(Good detail in the Pull Request description, thanks.) |
|
I am guessing this is something you wanted in one of your programs. Have you got some examples of what you put in custom command usage? |
|
|
(I am leaving this open for a month to see if gets any feedback from other people.) |
|
I am interested in improving the usage displayed for subcommands. I don't think using the custom usage is the answer though. In the general case I think the usage in the list of subcommands benefits from being terse. The approach we took with the subcommand description was adding an optional Since the goal of using custom usage can be achieved with a reasonably simple override (#1853 (comment)), closing this PR. Thank you for your contributions. |
Pull Request
Problem
The help menu does not display the custom command usage. If there are custom syntax changes that are critical for users to understand the program, this can be problematic.
Solution
Currently, this can be fixed by reconfiguring the helper, which is fine, but it would be nice to have this functionality by default. So, I slightly altered how
subcommandTermoutputs command usage. If that is not set by the user yet, it will default to the usual processing.Final Thoughts
Let me know if this was intentionally implemented, as it appeared that
subcommandTermwas stated to be a "legacy" function despite still being used to list subcommands in the help menu..