commandlineparser / commandlineparser/commandline

Method for Assembling Custom Help Info

オープン
#446 コメント 2 件 リアクション 2 件 担当者 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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。