Skip to content
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

Error message isn't passed through #113

Closed
ericnewton76 opened this issue Nov 4, 2017 · 1 comment
Closed

Error message isn't passed through #113

ericnewton76 opened this issue Nov 4, 2017 · 1 comment

Comments

@ericnewton76
Copy link
Member

Issue by EmmaZhu
Tuesday Feb 28, 2017 at 07:20 GMT
Originally opened as gsscoder/commandline#417


For example, I have a customized parameter defined like following:

public class MyParameters
{
public MyParameters(string init)
{
throw new InvalidOperationException("Some error message");
}
public string Value { get; private set; }
}

I'd want to show the accurate error message when the parameter value user input is incorrect. But seems the error message is always like:

Option 'option1' is defined with a bad format.

Is there anyway I can get the error message passed through?

@ericnewton76
Copy link
Member Author

Comment by nemec
Saturday Mar 04, 2017 at 06:15 GMT


Can you post a minimal reproduction of the issue, with a complete options class and the args array you're passing to the compiler? Also, which version of the library are you using?

From what you've mentioned so far, and assuming you're using the version in master, I think you will need to insert your custom error text when building the help screen:

result.WithNotParsed(errs =>
{
	HelpText.AutoBuild(result, help =>
	{
		help.AddPreOptionsLine("Some error message");
		return help;
	}, e => e)
	.ToString()
	.Dump();
});

You can do whatever you want in the first delegate to AutoBuild, including displaying custom messages.

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

No branches or pull requests

2 participants