commandlineparser / commandlineparser/commandline

Method for Assembling Custom Help Info

未关闭
#446 2 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
4.8k
派生
478
PR 合并指标
30 天内没有已合并 PR

描述

# 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

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先跟踪 HelpText.AutoBuild 在 DisplayHelp 中的调用路径,并检查 ParserSettings 的使用方式。将提案中的自定义 HelpText 和 Build 入口点与现有的抽象链进行比较。当用户可以提供自定义帮助格式,同时现有的自动帮助行为保持向后兼容时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp
领域
cli
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。