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

parameters with argument should throw error if arment is omitted #66

Open
sheam opened this issue Jun 3, 2016 · 2 comments
Open

parameters with argument should throw error if arment is omitted #66

sheam opened this issue Jun 3, 2016 · 2 comments

Comments

@sheam
Copy link

sheam commented Jun 3, 2016

If my parameter requires an argument, I would like an error to be thrown if that argument is not supplied.

I tried detecting this in the callback, but the callback never gets called if the argument is not supplied. Essentially it treats it as if the parameter was never supplied.

i.e.,

If the 't' parameter requires a numeric value and should be called like: myapp.exe -t 5, but
myapp.exe -t
is the same as
myapp.exe.

This can lead to some unexpected behavior.

@siywilliams
Copy link
Member

I think I might add a OnError callback that gets called when a problem is found with the setup switch.

For example:

fclp.Setup<int>("id")
   .Required()
   .OnError(Exception e => Console.WriteLine(e.ToString));

For now you can access any errors that occurred during the parsing process in the result object:

ICommandLineParserResult result = fclp.Parse(args);

if(result.HasErrors) {
   foreach(var error in result.Errors) {
      Console.WriteLine(error.ToString());
   }
}

@codingyourlife
Copy link

I'm new to this command line parser but quite like it so far. This feature is really missing.

Also required parameters should somehow be indicated when using SetupHelp(). The workaround works but the ToString() message only shows the exception name which could be smarter I guess.

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

No branches or pull requests

3 participants