How to print HelpText attribute in GetUsage method

Jul 11, 2011 at 8:22 PM

Hi,

In my options class I have some options, for example:

 

        [OptionArray("f", "files", Required = false, HelpText = "A space seperated list of files ot upload.")]
        public string[] InputFiles = null;

 

If the ParseArguments method fails how do I display the value of HelpText attribute to the user?

Jul 12, 2011 at 6:56 AM

Dear CommandLine.dll user,

please check the sample included in the project distribution.

Anyway you should create a method with a specific signature in your target instance and use the HelpText type.

[HelpOption(
        HelpText = "Dispaly this help screen.")]
public string GetUsage()
{
    var help = new HelpText(Program._headingInfo);
    help.AdditionalNewLineAfterOption = true;
    help.Copyright = new CopyrightInfo("Giacomo Stelluti Scala", 2005, 2011);
    help.AddPreOptionsLine("This is free software. You may redistribute copies of it under the terms of");
    help.AddPreOptionsLine("the MIT License <http://www.opensource.org/licenses/mit-license.php>.");
    help.AddPreOptionsLine("Usage: SampleApp -rMyData.in -wMyData.out --calculate");
    help.AddPreOptionsLine(string.Format("       SampleApp -rMyData.in -i -j{0} file0.def file1.def", 9.7));
    help.AddPreOptionsLine("       SampleApp -rMath.xml -wReport.bin -o *;/;+;-");
    help.AddOptions(this);

    return help;
}

When you add a method like this the parser will print the help in the specified TextWriter (see CommandLineParser constructor).

I hope this snippet can help you...

Regards,

Giacomo

Jul 12, 2011 at 4:53 PM

Thank you! This did what I was looking for.

I suggest using this in the quick start guide documentation. I'd thinking everyone wants to print the option explanations.

Jul 12, 2011 at 4:56 PM

Ah I see it's briefly mentioned. It would of been more obvious to me if the snippet above was also included. Thanks.

Jul 13, 2011 at 9:07 AM
Edited Jul 13, 2011 at 9:10 AM

Dear antize,

you're right, but as you can read (here, http://commandline.codeplex.com/documentation) the documentation section is not complete. --(Sorry!)--

I'm very busy with ordinary job and please take into consideration to make a donation to get a specific request done in few time. A symbolic small donation will motivate the author to fulfill a request in the following days and make it a priority.

Thank you for the support!

Regards,

Giacomo

P.S.: Donations are made using PayPal at this URL: https://www.paypal.com/it/cgi-bin/webscr?cmd=_flow&SESSION=ytNIsPlcuFfEi8vLJkP64xxONZSsSe7SM13mSXU1-B_2O0BZuYAy4yAeISG&dispatch=5885d80a13c0db1f8e263663d3faee8deaa77efc63a6eb429928d42bdf5d9d2c.