Skip to content

Commit 02dd7c2

Browse files
committed
Switching from the IllegalStateException to trying hard to work. A better user experience and didn't end up with the code being any more evil. CLI-162
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/branches/cli-1.x@748461 13f79535-47bb-0310-9956-ffa450edef68
1 parent ac6e754 commit 02dd7c2

2 files changed

Lines changed: 38 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,7 @@ protected StringBuffer renderWrappedText(StringBuffer sb, int width,
822822
if (nextLineTabStop >= width)
823823
{
824824
// stops infinite loop happening
825-
throw new IllegalStateException("Total width is less than the width of the argument and indent " +
826-
"- no room for the description");
825+
nextLineTabStop = width - 1;
827826
}
828827

829828
// all following lines must be padded with nextLineTabStop space

src/test/org/apache/commons/cli/bug/BugCLI162Test.java

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,44 @@ public void testLongLineChunking() throws ParseException, IOException {
259259
" yes.\n" +
260260
"Footer\n";
261261
assertEquals( "Long arguments did not split as expected", expected, sw.toString() );
262+
}
262263

263-
try {
264-
formatter.printHelp(new PrintWriter(sw), 22, this.getClass().getName(), "Header", options, 0, 5, "Footer");
265-
fail("IllegalStateException expected");
266-
} catch(IllegalStateException ise) {
267-
// expected
268-
}
269-
264+
public void testLongLineChunkingIndentIgnored() throws ParseException, IOException {
265+
Options options = new Options();
266+
options.addOption("x", "extralongarg", false, "This description is Long." );
267+
HelpFormatter formatter = new HelpFormatter();
268+
StringWriter sw = new StringWriter();
269+
formatter.printHelp(new PrintWriter(sw), 22, this.getClass().getName(), "Header", options, 0, 5, "Footer");
270+
String expected = "usage:\n" +
271+
" org.apache.comm\n" +
272+
" ons.cli.bug.Bug\n" +
273+
" CLI162Test\n" +
274+
"Header\n" +
275+
"-x,--extralongarg\n" +
276+
" T\n" +
277+
" h\n" +
278+
" i\n" +
279+
" s\n" +
280+
" d\n" +
281+
" e\n" +
282+
" s\n" +
283+
" c\n" +
284+
" r\n" +
285+
" i\n" +
286+
" p\n" +
287+
" t\n" +
288+
" i\n" +
289+
" o\n" +
290+
" n\n" +
291+
" i\n" +
292+
" s\n" +
293+
" L\n" +
294+
" o\n" +
295+
" n\n" +
296+
" g\n" +
297+
" .\n" +
298+
"Footer\n";
299+
assertEquals( "Long arguments did not split as expected", expected, sw.toString() );
270300
}
271301

272302
}

0 commit comments

Comments
 (0)