Skip to content
Permalink
Browse files
[CLI-287] Allow whitespace-only header and footer (#26)
* [CLI-287] Allow whitespace-only header and footer

* [CLI-287] Add tests
  • Loading branch information
MrQubo committed Oct 22, 2021
1 parent 8dcf119 commit 82403d07579665a0c194a638425ac24e08581ac2
Showing 2 changed files with 58 additions and 2 deletions.
@@ -482,13 +482,13 @@ public void printHelp(final PrintWriter pw, final int width, final String cmdLin
printUsage(pw, width, cmdLineSyntax);
}

if (header != null && !header.trim().isEmpty()) {
if (header != null && !header.isEmpty()) {
printWrapped(pw, width, header);
}

printOptions(pw, width, options, leftPad, descPad);

if (footer != null && !footer.trim().isEmpty()) {
if (footer != null && !footer.isEmpty()) {
printWrapped(pw, width, footer);
}
}
@@ -293,6 +293,62 @@ public void testOptionWithoutShortFormat2() {
//@formatter:on
}

@Test
public void testPrintHelpNewlineFooter()
{
final HelpFormatter formatter = new HelpFormatter();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final PrintWriter pw = new PrintWriter(out);

final Options options = new Options();
options.addOption("a", "b");

formatter.printHelp(
pw,
80,
"test" + EOL,
"header" + EOL,
options,
0,
0,
EOL
);
final String expected = "usage: test" + EOL +
"header" + EOL +
"-ab" + EOL +
EOL;
pw.flush();
assertEquals("footer newline", expected, out.toString());
}

@Test
public void testPrintHelpNewlineHeader()
{
final HelpFormatter formatter = new HelpFormatter();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final PrintWriter pw = new PrintWriter(out);

final Options options = new Options();
options.addOption("a", "b");

formatter.printHelp(
pw,
80,
"test" + EOL,
EOL,
options,
0,
0,
"footer" + EOL
);
String expected = "usage: test" + EOL +
EOL +
"-ab" + EOL +
"footer" + EOL;
pw.flush();
assertEquals("header newline", expected, out.toString());
}

@Test
public void testPrintHelpWithEmptySyntax() {
final HelpFormatter formatter = new HelpFormatter();

0 comments on commit 82403d0

Please sign in to comment.