commandlineparser / commandlineparser/commandline
[Wiki PR] Fix Wiki example
- Ngôn ngữ chính
- C#
- Star
- 4.8k
- Fork
- 478
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
[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
}
```
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.