CommandLine.HelpRequestedError and CommandLine.VersionRequestedError
Not sure it is already under consideration!
ProgXYZ --version ProgXYZ --help
invokes WithNotParsed and list contains error HelpRequestedError and VersionRequestedError
yes --version expose VersionRequestedError --help expose HelpRequestedError
I just changed my code to handle these.
bool stopProcessing = false;
Parser.Default.ParseArguments<CommandLineOptions>(args)
.WithNotParsed(o =>
{
List<Error> errors = o.ToList();
stopProcessing = errors.Any(e => e.StopsProcessing);
if (errors.Any(e => e.Tag == ErrorType.HelpRequestedError || e.Tag == ErrorType.VersionRequestedError))
{
return;
}
foreach (Error error in errors)
{
Console.WriteLine($"Error command line parameter '{error.Tag}'");
}
})
.WithParsed(o => CommandLineOptions = o);
if (stopProcessing)
{
return 1;
}
I don't understand why this is considered as an error by default ? KoalaBear84, I did the same than you, but to handle "Help requested error", note that apparently we have to test for "HelpVerbRequestedError"
You mean there is something not right in my code yet?
For me, when the application is started with the verb "help", the "error" tag is not e.Tag == ErrorType.HelpRequestedError like in your example, but e.Tag == ErrorType.HelpVerbRequestedError. So, as far as I can see, to avoid to process it (in your case with a console.WriteLine) it's this check that you have to do. But it's just based on my own usage experience, when I encountered the same problem than you.
I stumbled into this too. Imho, --help and --version should not be considered as error. I've just spent 10 minutes to look for an error although there was none hence until I noticed that both mentioned options are just considered as such.
I used the same workaround as @KoalaBear84 which works for me because there is no verb help nor the word version used in my application - only the options --help and --version.
Just an FYI it's actually slightly worse than what's above. help/--help doesn't give you the HelpRequestedError, as shown above, it gives HelpVerbRequestedError whereas version or --version just gives VersionRequestedError. There's definitely a mismatch here.