commandlineparser / commandlineparser/commandline

Default supported verbs/options should not return non-zero exit code

Offen
#841 2 Kommentare 7 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
4.8k
Forks
478
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

This library should not return a non-zero exit code for the default supported verbs and options:

- help
- version
- --help
- --version

```csharp
using System;
using CommandLine;

public class Program
{
[Verb("add", HelpText = "Add file contents to the index.")]
class AddOptions
{
[Option(Default = false, HelpText = "Prints all messages to standard output.")]
public bool Verbose { get; set; }
}

[Verb("commit", HelpText = "Record changes to the repository.")]
class CommitOptions
{
}

static int Main(string[] args)
{
var exitCode = Parser.Default.ParseArguments(args)
.MapResult(
(AddOptions opts) => 0,
(CommitOptions opts) => 0,
errs => 1
);

Console.WriteLine($"exitCode = {exitCode}");
return exitCode;
}
}
```

Executing this code results in the following outputs:
```
> ConsoleApp1.exe version
ConsoleApp1 1.0.0.0
exitCode = 1

> ConsoleApp1.exe help
ConsoleApp1 1.0.0.0
Copyright c 2022

add Add file contents to the index.

commit Record changes to the repository.

help Display more information on a specific command.

version Display version information.

exitCode = 1

> ConsoleApp1.exe --version
ConsoleApp1 1.0.0.0
exitCode = 1

> ConsoleApp1.exe --help
ConsoleApp1 1.0.0.0
Copyright c 2022

add Add file contents to the index.

commit Record changes to the repository.

help Display more information on a specific command.

version Display version information.

exitCode = 1

> ConsoleApp1.exe help add
ConsoleApp1 1.0.0.0
Copyright c 2022

--verbose (Default: false) Prints all messages to standard output.

--help Display this help screen.

--version Display version information.

exitCode = 1

> ConsoleApp1.exe add --version
ConsoleApp1 1.0.0.0
exitCode = 1

> ConsoleApp1.exe add --help
ConsoleApp1 1.0.0.0
Copyright c 2022

--verbose (Default: false) Prints all messages to standard output.

--help Display this help screen.

--version Display version information.

exitCode = 1
```

As far as I can tell, those errors can be handled by the consumer as in your [code example](https://dotnetfiddle.net/wrcAxr) or by doing it like suggested in #660.

However, since those verbs/options are **supported** they should not result in an error and therefore also should not require to be handled by the consumer.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.