Mandatory field not throwing CommandLineException


I have a field in the target-class:
[ValueArgument(typeof(string), 'q', "query", Optional = false,
Description = "LDAP query", FullDescription = "", Example = "(&(objectCategory=User)(initials=*))")]
public string Query;
but the followind code does not throw the exception, if the parameter is not supplied (in fact, I just call /? in the commandline):
var parser = new CommandLineParser.CommandLineParser
AcceptSlash = true,
ShowUsageOnEmptyCommandline = true,
CheckMandatoryArguments = true,
IgnoreCase = true,
AcceptEqualSignSyntaxForValueArguments = true
var command = new ExportCommand();
return command.Execute(); //this line is being executed instead, but parameters have not been supplied!
Closed Apr 27, 2014 at 8:13 PM by Trupik


uTILLIty wrote Mar 11, 2012 at 3:24 PM

I found the problem. If you set ShowUsageOnEmptyCommandline to TRUE, there is NO WAY of knowning if all parameters were supplied or not, since there was no exception ever thrown. I would suggest to either throw an exception in ParseCommandLine, or return a bool indicating that parsing failed.

wrote Feb 14, 2013 at 6:34 PM

Trupik wrote Apr 27, 2014 at 8:13 PM

If the built-in behaviour does not suit you, I suggest you set ShowUsageOnEmptyCommandline to false. If you indeed want to show usage for empty command line, you can do it explicitly, stg like:

if (args.Length == 0)

wrote Apr 27, 2014 at 8:13 PM

Trupik wrote Apr 27, 2014 at 8:34 PM

I've also added ParsingSucceeded flag that you can check after ParseCommandLine is called.