Commandline: Can't find ParseArgumentsStrict method from samples

Created on 10 Jan 2018  路  2Comments  路  Source: commandlineparser/commandline

Can't find ParseArgumentsStrict method from samples

version 2.2

Most helpful comment

Sorry, it was removed in the rewrite to the latest version. We need to fix that example to look more like the verb examples, which are more up to date. Consuming the arguments should look something like this:

int Main(string[] args) {
  return CommandLine.Parser.Default.ParseArguments<Options>(args)
    .WithNotParsed(errs => {
        // do something with the errors
        })
        .WithParsed(opt => {
        // do things with options
        });
}

If you miss ParseArgumentsStrict, you can basically replicate it with the following code:

var writer = new StringWriter();
var parser = new Parser(conf => conf.HelpWriter = writer);
var result = parser.ParseArguments<Options>(args);
result.WithNotParsed(_ => {
    Console.WriteLine(writer.ToString());
    System.Environment.Exit(1);
})
.WithParsed(opt => {
    // do things with options
});

All 2 comments

Me either. I stepped back 1 version.

Sorry, it was removed in the rewrite to the latest version. We need to fix that example to look more like the verb examples, which are more up to date. Consuming the arguments should look something like this:

int Main(string[] args) {
  return CommandLine.Parser.Default.ParseArguments<Options>(args)
    .WithNotParsed(errs => {
        // do something with the errors
        })
        .WithParsed(opt => {
        // do things with options
        });
}

If you miss ParseArgumentsStrict, you can basically replicate it with the following code:

var writer = new StringWriter();
var parser = new Parser(conf => conf.HelpWriter = writer);
var result = parser.ParseArguments<Options>(args);
result.WithNotParsed(_ => {
    Console.WriteLine(writer.ToString());
    System.Environment.Exit(1);
})
.WithParsed(opt => {
    // do things with options
});
Was this page helpful?
0 / 5 - 0 ratings