commandlineparser / commandlineparser/commandline

[Wiki PR] Fix Wiki example

Ouverte
#697 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
C#
Étoiles
4.8k
Forks
478
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

[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
}
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.