I am trying to utilize the OptionSet
class in the following way:
string resultsFileName = null;
bool isHelp = false;
var p = new OptionSet() {
{ "r=|resultsFile=", "The file with the results", v => { resultsFileName = v; } }
{ "h|help", "Show this help", v => { isHelp = (v != null); } },
};
try
{
p.Parse(args);
}
catch (OptionException e)
{
Console.WriteLine("Invalid arguments: " + e.Message);
ShowHelp(p);
return;
}
Thus, resultsFile
option is expected to be required (according to documentation: http://www.ndesk.org/doc/ndesk-options/NDesk.Options/OptionValueType.html). However, when I run the program as is (i.e. with no command line arguments) the exception is not thrown. Please assist.
Update: It looks in debugger like when no command line options are provided, the private void AssertValid (int index)
method will be never reached to throw new OptionException
.