-
Notifications
You must be signed in to change notification settings - Fork 481
Default supported verbs/options should not return non-zero exit code #841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Right, so I took a closer look at the code: The biggest problem is that Rather, the consumer would have to define a return value for help/version and at that point there is not much of a difference between setting a value for those verbs/options or handling the error in a custom function. // current way
static int Main(string[] args)
{
return Parser.Default.ParseArguments<AddOptions, CommitOptions>(args)
.MapResult(
(AddOptions opts) => 0, // value for parsed AddOptions
(CommitOptions opts) => 0, // value for parsed CommitOptions
HandleParseError // function for notParsed/help/version
);
}
static int HandleParseError(IEnumerable<Error> errs)
{
var exitCode = 1;
if (errs.IsHelp() || errs.IsVersion())
exitCode = 0;
return exitCode;
} // alternative way, if .MapResult returned the default value for the given type
static int Main(string[] args)
{
return Parser.Default.ParseArguments<AddOptions, CommitOptions>(args)
.MapResult(
(AddOptions opts) => 0, // value for parsed AddOptions
(CommitOptions opts) => 0, // value for parsed CommitOptions
errs => 1 // value for notParsed
);
}
// alternative way, if the consumer had to define a default value
static int Main(string[] args)
{
return Parser.Default.ParseArguments<AddOptions, CommitOptions>(args)
.MapResult(
0, // value for help/version
(AddOptions opts) => 0, // value for parsed AddOptions
(CommitOptions opts) => 0, // value for parsed CommitOptions
errs => 1 // value for notParsed
);
} Unless the maintainers of this project want the |
This behaviour is very weird, no stablished command line I know would return != for version/help options |
This library should not return a non-zero exit code for the default supported verbs and options:
Executing this code results in the following outputs:
As far as I can tell, those errors can be handled by the consumer as in your code example 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.
The text was updated successfully, but these errors were encountered: