Skip to content

CommandLine.HelpRequestedError and CommandLine.VersionRequestedError #630

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

Open
dineshlappathy opened this issue May 15, 2020 · 7 comments
Open
Labels

Comments

@dineshlappathy
Copy link

Not sure it is already under consideration!

ProgXYZ --version
ProgXYZ --help

invokes WithNotParsed and list contains error HelpRequestedError and VersionRequestedError

@moh-hassan
Copy link
Collaborator

yes
--version expose VersionRequestedError
--help expose HelpRequestedError

@KoalaBear84
Copy link

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;
}

@AFract
Copy link

AFract commented Mar 8, 2021

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"

@KoalaBear84
Copy link

You mean there is something not right in my code yet?

@AFract
Copy link

AFract commented Mar 8, 2021

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.

@Siam1205
Copy link

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.

@JimSuplizio
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants