diff --git a/src/CommandLine/Text/HelpText.cs b/src/CommandLine/Text/HelpText.cs index 68f7af3b..eaa6ade5 100644 --- a/src/CommandLine/Text/HelpText.cs +++ b/src/CommandLine/Text/HelpText.cs @@ -206,7 +206,7 @@ public SentenceBuilder SentenceBuilder public static HelpText AutoBuild( ParserResult parserResult, Func onError, - Func onExample, + Func onExample, bool verbsIndex = false, int maxDisplayWidth = DefaultMaximumLength) { @@ -254,7 +254,7 @@ public static HelpText AutoBuild( usageAttr.Do( usage => usage.AddToHelpText(auto, true)); - + usageLines.Do( lines => auto.AddPreOptionsLines(lines)); @@ -519,7 +519,7 @@ public static IEnumerable RenderParsingErrorsTextAsLines( yield return line.ToString(); } - var mutuallyErrs = + var mutuallyErrs = formatMutuallyExclusiveSetErrors( meaningfulErrors.OfType()); if (mutuallyErrs.Length > 0) @@ -619,8 +619,25 @@ public override string ToString() .ToString(); } - private static void AddLine(StringBuilder builder, string value, int maximumLength) + internal static void AddLine(StringBuilder builder, string value, int maximumLength) { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + if (maximumLength < 1) + { + throw new ArgumentOutOfRangeException(nameof(value)); + } + + value = value.Trim(); + builder.AppendWhen(builder.Length > 0, Environment.NewLine); do { diff --git a/tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs b/tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs index 6d7e8099..e041026a 100644 --- a/tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs +++ b/tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs @@ -12,6 +12,7 @@ using CommandLine.Text; using FluentAssertions; using Xunit; +using System.Text; namespace CommandLine.Tests.Unit.Text { @@ -657,5 +658,16 @@ public void AutoBuild_with_assembly_company_attribute_only() ReflectionHelper.SetAttributeOverride(null); } } + + [Fact] + public void Add_line_with_two_empty_spaces_at_the_end() + { + StringBuilder b = new StringBuilder(); + HelpText.AddLine(b, + "Test ", + 1); + + Assert.Equal("T" + Environment.NewLine + "e" + Environment.NewLine + "s" + Environment.NewLine + "t", b.ToString()); + } } }