commandlineparser / commandlineparser/commandline
Method for Assembling Custom Help Info
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 478
- PR merge metrics
- No merged PRs in 30d
Description
# Problem
The `HelpText` displays the Package Id. I would like to replace that with the Product name and the Description.
# Investigation
I looked through the source code and found this was being done inside the `HelpText.AutoBuild` method, but this method is deep in a chain of abstraction. I could be missing something, but it seemed difficult to extract it to build a custom build method.
# Proposal
I understand this is a lot of changes to how things work and I don't have the experience of what all the pieces of source code are doing, but this is my rough whiteboard level idea of a solution.
## Add HelpText to ParserSettings
This `HelpText` object would allow users to set their own `HelpText` object to be used by the `DisplayHelp` method. Creating default fallbacks seems common in this library, so a similar technique can be used here. If the `ParserSettings` provides a `HelpText` instance, use that, otherwise create and use a default.
## Create Action HelpText.Build
The `HelpText.Build` method would be used by `HelpText.AutoBuild` to generate the output of the help. It can accept options such as `verbsIndex` and `maxDisplayWidth`. This method can then be defined to create custom display behavior.
The following pseudocode illustrates my intentions for this method:
```C#
// HelpText
public static something AutoBuild(HelpText) {
if(HelpText) {
// Do setup.
HelpText.Build();
}
}
// Somewhere else.
HelpText.Build = (options) => {
// Do string building.
}
```
Things like the verb list could be passed in as arguments to the delegate to simplify things.
```C#
(verbs) => {
if(verbs != null) {
foreach(var verb in verbs) {
builder.Add(" {0}", verb);
}
}
}
```
# Conclusion
I think this method could be made backwards compatible and would offer a straight forward way to format help text in a completely custom way while still getting to utilize the auto detection of the help verb and the --help option.
Thanks
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.