Skip to content

AddPreOptionsLine() incorrectly wrapping when adding multi-line string (like in the wiki example "Handling Parsing Errors") #69

Open
@turch

Description

@turch

Using the sample code in https://github.com/gsscoder/commandline/wiki/Display-A-Help-Screen section "Handling Parsing Errors" to print errors:

RenderParsingErrorsText() returns a string with linebreaks if there are multiple errors. When passed to Add<>OptionsLine, it is wrapped every 80 characters regardless of newlines, causing incorrect wrapping.

[ParserState]
public IParserState LastParserState { get; set; }

[Option('a', "qwe", Required = true)]
public string a { get; set; }

[Option('b', "asd", Required = true)]
public double b { get; set; }

[Option('c', "zxc", Required = true)]
public bool c { get; set; }

[HelpOption]
public string GetUsage()
{
    var help = new HelpText();
    // ...
    if (this.LastParserState.Errors.Count > 0)
    {
        var errors = help.RenderParsingErrorsText(this, 2); // indent with two spaces
        if (!string.IsNullOrEmpty(errors))
        {
            help.AddPreOptionsLine(string.Concat("\n", "ERROR(S):"));
            help.AddPreOptionsLine(errors);
        }
    }
    // ...
    return help;

}
>foo.exe

ERROR(S):
  -a/--qwe required option is missing.
  -b/--asd required option is 
missing.
  -c/--zxc required option is missing.

As you can see, the second error line gets incorrectly wrapped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions