Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/CommandLine/Text/HelpText.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -206,7 +206,7 @@ public SentenceBuilder SentenceBuilder
public static HelpText AutoBuild<T>(
ParserResult<T> parserResult,
Func<HelpText, HelpText> onError,
Func<Example, Example> onExample,
Func<Example, Example> onExample,
bool verbsIndex = false,
int maxDisplayWidth = DefaultMaximumLength)
{
Expand DownExpand Up@@ -254,7 +254,7 @@ public static HelpText AutoBuild<T>(

usageAttr.Do(
usage => usage.AddToHelpText(auto, true));

usageLines.Do(
lines => auto.AddPreOptionsLines(lines));

Expand DownExpand Up@@ -519,7 +519,7 @@ public static IEnumerable<string> RenderParsingErrorsTextAsLines<T>(
yield return line.ToString();
}

var mutuallyErrs =
var mutuallyErrs =
formatMutuallyExclusiveSetErrors(
meaningfulErrors.OfType<MutuallyExclusiveSetError>());
if (mutuallyErrs.Length > 0)
Expand DownExpand Up@@ -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
{
Expand Down
12 changes: 12 additions & 0 deletions tests/CommandLine.Tests/Unit/Text/HelpTextTests.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@
using CommandLine.Text;
using FluentAssertions;
using Xunit;
using System.Text;

namespace CommandLine.Tests.Unit.Text
{
Expand DownExpand Up@@ -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());
}
}
}