Skip to content

Commit 4f40737

Browse files
committed
Applying J. Lewis Muir's patch from CLI-151 fixing HelpFormatter so it wraps properly on multiple lines
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/branches/cli-1.x@654428 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6a6bb48 commit 4f40737

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/java/org/apache/commons/cli/HelpFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ protected StringBuffer renderWrappedText(StringBuffer sb, int width,
809809
while (true)
810810
{
811811
text = padding + text.substring(pos).trim();
812-
pos = findWrapPos(text, width, nextLineTabStop);
812+
pos = findWrapPos(text, width, 0);
813813

814814
if (pos == -1)
815815
{

src/test/org/apache/commons/cli/HelpFormatterTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ public void testPrintWrapped()
8383
hf.renderWrappedText(sb, 12, 4, text);
8484
assertEquals("single line padded text", expected, sb.toString());
8585

86+
text = " -p,--period <PERIOD> PERIOD is time duration of form " +
87+
"DATE[-DATE] where DATE has form YYYY[MM[DD]]";
88+
89+
sb.setLength(0);
90+
expected = " -p,--period <PERIOD> PERIOD is time duration of" +
91+
hf.getNewLine() +
92+
" form DATE[-DATE] where DATE" +
93+
hf.getNewLine() +
94+
" has form YYYY[MM[DD]]";
95+
hf.renderWrappedText(sb, 53, 24, text);
96+
assertEquals("single line padded text 2", expected, sb.toString());
97+
8698
text =
8799
"aaaa aaaa aaaa" + hf.getNewLine() +
88100
"aaaaaa" + hf.getNewLine() +

0 commit comments

Comments
 (0)