commandlineparser / commandlineparser/commandline
How to get or implement prefix for version number
- 主要語言
- C#
- 星號
- 4.8k
- 分支
- 478
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hello all,
I am wondering how to add a custom prefix to the version information that gets printed both with the ```--help``` and ```--version``` options.
For the version ```2.0.0-beta``` an user-implemented prefix shall be added to get for both options an output like ```Myapp v2.0.0-beta``` or ```Myapp customprefix2.0.0-beta```.
For ```--help``` I could override ```HelpText.Heading``` which is an option, but not the preferred way I would do it.
For ```--version``` I did not find an option for overriding. Did I miss something reading the documentation?
Would it be correct to extend the following method with a configuration option like ```versionPrefix``` (which could be a private variable or a parameter of the ```HeadingInfo``` method)?
https://github.com/commandlineparser/commandline/blob/d443a51aeb3a418425e970542b3b96e9da5f62e2/src/CommandLine/Text/HeadingInfo.cs#L28-L34
```
public HeadingInfo(string programName, string versionPrefix, string version = null)
{
if (string.IsNullOrWhiteSpace(programName)) throw new ArgumentException("programName");
if (versionPrefix == null) throw new ArgumentException("versionPrefix");
this.programName = programName;
this.version = string.IsNullOrWhiteSpace(version) ? null : versionPrefix + version;
}
```
```
private string versionPrefix;
///
/// Gets or sets an optional prefix when displaying the version information.
///
public string VersionPrefix
{
get { return versionPrefix; }
set { versionPrefix = string.IsNullOrWhiteSpace(value) ? string.Empty : value; }
}
```
Where can the configuration option be assigned and how is the preferred way to route it into the HeadingInfo class?
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
Start with src/CommandLine/Text/HeadingInfo.cs at the referenced constructor and trace how HeadingInfo is used for --help and --version output. Compare the existing HelpText.Heading configuration with the missing version configuration, then verify that a user-supplied prefix appears in both outputs without changing the version when no prefix is set.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- csharp
- 領域
- cli
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100