This code using the CommandLineParser library works. However, as soon as I don’t set a parameter, I can’t get the result of the return of the method DisplayHelp. My code works when I have parameters but don't when there aren't. This is my code :
int result;
var parser = new CommandLine.Parser(with => with.HelpWriter = null);
var parserResult = parser.ParseArguments<ProgramOptions>(args);
ProgramOptions opts = null;
Program.options = Parser.Default.ParseArguments<ProgramOptions>(args)
.WithParsed(options => { opts = options; })
.WithNotParsed(errs => DisplayHelp(parserResult, errs));
if ((opts == null) || (args.Length == 0))
{
result = (int)ApplicationResult.HelpRequested;
}
else
{
result = MainWithOptions(opts);
}
- with a valid param Program.options is initialized with the parameters extracted from command line args => OK
- with an invalid command line args, the help is displayed. => OK
- with no command line args, the help is not displayed => That's not what I want.
Thank you for your help.