HelpOption[Attribute]

It's currently the only attribute that is applied to a method. Inherits from CommandLine.BaseOptionAttribute so that you can define both names, but as default its short name is null and help is its long name.
Here is an example.

C#:

class Options
{
    // ...
    [HelpOption(HelpText = "Dispaly this help screen.")]
    public string GetUsage()
    {
        var help = new StringBuilder();
        help.AppendLine("Guide Application Help Screen!");
        return help;
    }
    // ...
}

As you can see the method signature is very simple: public string AnyName() (but I suggest GetUsage). The method must be an instance method. In particular conditions, the parser will call this method to get the help screen to be presented to the user (more on this topic later).
Obviously you are free to use it how, where and when it sees fit.

C#:

var options = new Options;
// ... here the parsing process ... 
if (!options.Gui)
    Console.Error.Write(options.GetUsage());
else
    MessageBox.Show(options.GetUsage());

Of course you can display an help screen much more complex than the one built here using the System.Text.StringBuilder type in this simple way. The types contained in CommandLine.Text are dedicated to this purpose. This will be explained in depth more ahead.

Last edited May 15, 2012 at 8:14 AM by gsscoder, version 6

Comments

novaterata Apr 15, 2013 at 5:44 PM 
nickonjohn is correct, and that is not a HelpText instance, its a StringBuilder, which must be returned with .ToString() The QuickStart code samples don't compile either.

gsscoder Jun 2, 2012 at 6:03 AM 
No, you can return directly HelpText instance, it will automatically casted to System.String. See sample and templates.

Wernight May 1, 2012 at 10:44 AM 
It seem that 'MyProgam --help' doesn't display the help.

nickonjohn Mar 10, 2011 at 10:19 PM 
In the first code box it should be "return help.ToString();" not "return help".
Great library. Thanks.