commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Incomplete HelpText returned from AutoBuild

Open caipigott opened this issue 7 years ago • 6 comments

Here is an extract of my CommandLineOption class

[Option('m', "monitor", DefaultValue = 0, HelpText = "The ID of the monitor on which the the application should be shown (use 0 for the primary screen).")] public int Monitor { get; set; } [Option('t', "takt", DefaultValue = "", HelpText = "The station/takt identification.")] public string Station { get; set; } [Option('w', "window", DefaultValue = false, HelpText = "Start with normal application window (not fullscreen).")] public bool NormalWindow { get; set; }

To create the text for the error window i use this

[HelpOption] public string GetUsage() { string usage = HelpText.AutoBuild(this, current => HelpText.DefaultParsingErrorsHandler(this, current)); return usage.Replace("\r\n\r\n", "\r\n"); // Removing empty rows }

Unfortunatelly the HelpText of the Options is incomplete and i couldn't find a reason why

helpfileerror

caipigott avatar Oct 27 '16 08:10 caipigott

Hi, what version of the library are you using? If you aren't using the latest prerelease, could you try it out?

nemec avatar Nov 05 '16 06:11 nemec

Hello,

i'm using the lastest Version from NuGet Packages (Version: 1.9.71)

commandline

Is there a newer Version which i could try?

caipigott avatar Nov 09 '16 11:11 caipigott

You'll need to enable prerelease packages, then you can update to the latest 2.x beta.

nemec avatar Nov 09 '16 16:11 nemec

Hello,

thanks, now i could find the prerelease Version. I uninstalled the old one and installed the new. Unfortunatelly now i can't compile my project anymore as some of the options aren't available anymore. Could someone help to make it work again?

commanlineprerelease

Thanks in advance, Caipi

caipigott avatar Nov 10 '16 09:11 caipigott

Hi, try something like this instead, things have changed a lot in v2.0

void Main()
{
    var parser = new Parser();

    var result = parser.ParseArguments<Options>("--arp --StatusWidth 10 --logged-cultures=EN,ES,IT".Split());

    result.WithNotParsed(errs =>
    {
        HelpText.AutoBuild(result, h =>
        {
            h.AddOptions(result);
            Console.WriteLine(h);
            return h;
        }, e =>
        {
            Console.WriteLine(e.HelpText);
            return e;
        });
    });
    result.WithParsed(o =>
    {
        o.Dump();
    });
}

public class Options
{
    [Option("StatusWidth", Default=0, HelpText="Set stuff")]
    public int StatusWidth { get; set; }

    [Option("logged-cultures", HelpText="Logged cultures")]
    public IEnumerable<string> LoggedCultureStrings { get; set; }
}

nemec avatar Nov 11 '16 05:11 nemec

Using 1.9.71.2 The HelpText.AddOptions(..) function changes the options object in some way (I don't figure out what happen).

You can use this code snipped to avoid the problem:

[HelpOption]
public string GetUsage() {
  var help = new HelpText();
  //...
  help.AddOptions(this.MemberwiseClone());
  // ...
  return help;
}

silbaer avatar Feb 20 '17 12:02 silbaer