nemec / clipr

Command Line Interface ParseR for .Net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Public method to print the parser help message

efficks opened this issue · comments

We should be able to print the parser help message in our code.
Like print_usage in Python (https://docs.python.org/2/library/optparse.html#other-methods)

commented

Thanks to your commit in #9, it should be easy to implement in the parser. Currently, if you want to get the help message for the parser, I would recommend keeping the IHelpGenerator around and calling it directly, like this:

var opts = new Options();
var help = new AutomaticHelpGenerator<Options>();
var parser = new CliParser<Options>(opts, help);
[...]
Console.Error.Write(help.GetUsage());

I've intentionally avoided writing to the Console anywhere but the Strict* methods (which are more conveniences than general purpose methods) to allow the user (you) to control where the data goes.

What kind of use case are you trying to print the usage for?

var data = Parse("--verbose");
if(ParseFailed())
{
    PrintUsage();
}

or

var data = Parse("--help");
if(TriggeredHelp())
{
    PrintUsage();
}

Or something else entirely?

Ok, thank you for the hint. I didn't though to do this.