commandlineparser / commandlineparser/commandline
[Wiki PR] Fix Wiki example
- 主要语言
- C#
- 星标
- 4.8k
- 派生
- 478
- PR 合并指标
- 30 天内没有已合并 PR
描述
[Wiki Example location](https://github.com/commandlineparser/commandline/wiki/HelpText-Configuration#example-1)
Original example:
```csharp
static void Main(string[] args)
{
var parser = new CommandLine.Parser(with => with.HelpWriter = null);
var parserResult = parser.ParseArguments(args);
parserResult
.WithParsed(options => Run(options))
.WithNotParsed(errs => DisplayHelp(parserResult, errs));
}
static void DisplayHelp(ParserResult result)
{
var helpText = HelpText.AutoBuild(result, h =>
{
h.AdditionalNewLineAfterOption = false;
h.Heading = "Myapp 2.0.0-beta"; //change header
h.Copyright = "Copyright (c) 2019 Global.com"; //change copyright text
return HelpText.DefaultParsingErrorsHandler(result, h);
}, e => e);
Console.WriteLine(helpText);
}
private static void Run(Options options)
{
//do stuff
}
```
[Provided .NET Fiddle example](https://dotnetfiddle.net/8GgWPP)
```csharp
static void Main(string[] args)
{
var parser = new CommandLine.Parser(with => with.HelpWriter = null);
var parserResult = parser.ParseArguments(args);
parserResult
.WithParsed(options => Run(options))
.WithNotParsed(errs => DisplayHelp(parserResult, errs));
}
static void DisplayHelp(ParserResult result, IEnumerable errs)
{
var helpText = HelpText.AutoBuild(result, h =>
{
h.AdditionalNewLineAfterOption = false;
h.Heading = "Myapp 2.0.0-beta"; //change header
h.Copyright = "Copyright (c) 2019 Global.com"; //change copyright text
return HelpText.DefaultParsingErrorsHandler(result, h);
}, e => e);
Console.WriteLine(helpText);
}
private static void Run(Options options)
{
//do stuff
}
```
Suggested fix
```csharp
static void Main(string[] args)
{
var parser = new CommandLine.Parser(with => with.HelpWriter = null);
var parserResult = parser.ParseArguments(args);
parserResult
.WithParsed(options => Run(options))
.WithNotParsed(_ => DisplayHelp(parserResult));
}
static void DisplayHelp(ParserResult result)
{
var helpText = HelpText.AutoBuild(result, h =>
{
h.AdditionalNewLineAfterOption = false;
h.Heading = "Myapp 2.0.0-beta"; //change header
h.Copyright = "Copyright (c) 2019 Global.com"; //change copyright text
return HelpText.DefaultParsingErrorsHandler(result, h);
}, e => e);
Console.WriteLine(helpText);
}
private static void Run(Options options)
{
//do stuff
}
```
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。