Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ericnewton76 opened this issue Nov 4, 2017 · 2 comments
Milestone

Comments

@ericnewton76
Copy link
Member

Issue by turch
Wednesday Mar 13, 2013 at 21:07 GMT
Originally opened as gsscoder/commandline#69


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.

@ericnewton76
Copy link
Member Author

Comment by gsscoder
Thursday Mar 14, 2013 at 06:07 GMT


Hi, thanks for reporting.

Same question, you're working on development or stable branch?

@ericnewton76 ericnewton76 added this to the 2.0.x-stable milestone Nov 4, 2017
@ericnewton76
Copy link
Member Author

Comment by turch
Thursday Mar 14, 2013 at 15:52 GMT


Same answer, master branch :)

I haven't made any changes to my fork since this would be more than a one-line change that would probably be made irrelevant by the development branch changes.

ericnewton76 pushed a commit that referenced this issue Apr 4, 2018
moh-hassan pushed a commit that referenced this issue Jun 30, 2019
Test maintainance: add missed tests and removing xUnit1013 warning (#…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants