How to print HelpText attribute in GetUsage method

Jul 11, 2011 at 8:22 PM


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.

        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 <>.");
    help.AddPreOptionsLine("Usage: SampleApp -wMyData.out --calculate");
    help.AddPreOptionsLine(string.Format("       SampleApp -i -j{0} file0.def file1.def", 9.7));
    help.AddPreOptionsLine("       SampleApp -rMath.xml -wReport.bin -o *;/;+;-");

    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...



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, 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!



P.S.: Donations are made using PayPal at this URL: