0

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);
}
  1. with a valid param Program.options is initialized with the parameters extracted from command line args => OK
  2. with an invalid command line args, the help is displayed. => OK
  3. with no command line args, the help is not displayed => That's not what I want.

Thank you for your help.

Screenyx
  • 1
  • 1
  • 2
    could you please be more specific than "doesn't work"? do you get any errors, and if so, which ones? how does the program behave and how _should_ it behave? i recommend [taking the tour](https://stackoverflow.com/tour), as well as reading [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [what's on topic](https://stackoverflow.com/help/on-topic). – Franz Gleichmann May 03 '21 at 10:02
  • 1
    Please share a [mcve]. – mjwills May 03 '21 at 10:12
  • I just edit my post to be more specific. Hope you will understand – Screenyx May 03 '21 at 12:01

0 Answers0