commandline icon indicating copy to clipboard operation
commandline copied to clipboard

How to supply multiple custom options?

Open ptr727 opened this issue 8 years ago • 1 comments

In the v2 branch, I want to ignore case, but I want to keep the default help output. How do I combine multiple custom options in the constructor? Or how do I override default current values?

Parser parser = new Parser(with => with.CaseSensitive = false);
Parser parser1 = new Parser(with => with.HelpWriter = Console.Error);
// Parser parser = new Parser(with.CaseSensitive = false and with.HelpWriter = Console.Error); 
ParserResult<Options> result = parser.ParseArguments<Options>(args);

If I try to modify the settings, I get an exception at runtime:

Parser parser = new Parser();
parser.Settings.CaseSensitive = false;
parser.Settings.HelpWriter = Console.Error;
System.InvalidOperationException occurred
  HResult=0x80131509
  Message=Operation is not valid due to the current state of the object.
  Source=CommandLine
  StackTrace:
   at CommandLine.Infrastructure.PopsicleSetter.Set[T](Boolean consumed, T& field, T value)
   at CommandLine.ParserSettings.set_CaseSensitive(Boolean value)
   at Plex.Program.Main(String[] args) in C:\Users\piete\OneDrive\Projects\Plex\Plex\Program.cs:line 31

ptr727 avatar May 22 '17 20:05 ptr727

Ok, I figured it out:

            Parser parser = new Parser(with =>
            {
                with.CaseSensitive = false;
                with.HelpWriter = Console.Error;
            });

ptr727 avatar May 23 '17 14:05 ptr727