Skip to content

Commit

Permalink
including log info for invalid values scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-franco authored and remkop committed Jun 27, 2022
1 parent 412b7da commit c1af2c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7826,8 +7826,9 @@ public UsageMessageSpec width(int newValue) {
public UsageMessageSpec longOptionsMaxWidth(int newValue) {
if (newValue >= DEFAULT_USAGE_LONG_OPTIONS_WIDTH && newValue <= width() - DEFAULT_USAGE_LONG_OPTIONS_WIDTH) {
longOptionsMaxWidth = newValue;
} else {
CommandLine.tracer().info("Invalid usage long options max width %d. Value must not exceed width(%d) - %d", newValue, width(), DEFAULT_USAGE_LONG_OPTIONS_WIDTH);
}

return this;
}

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/picocli/HelpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4389,21 +4389,29 @@ public void testSetLongOptionsColumnLengthMinimum_ModifiesSpec() {
public void testUsageMessageSpec_LongOptionsColumnLengthMinimum_Minimum20() {
CommandLine cmd = new CommandLine(CommandSpec.create());
cmd.setUsageHelpLongOptionsMaxWidth(20);
TestUtil.setTraceLevel(CommandLine.TraceLevel.INFO);

CommandLine returnValue = cmd.setUsageHelpLongOptionsMaxWidth(19);

assertEquals(20, cmd.getUsageHelpLongOptionsMaxWidth());
assertEquals(20, cmd.getCommandSpec().usageMessage().longOptionsMaxWidth());

String expected = "Invalid usage long options max width 19. Value must not exceed width(80) - 20";
assertTrue(systemErrRule.getLog(), systemErrRule.getLog().contains(expected));
}

@Test
public void testUsageMessageSpec_LongOptionsColumnLengthMinimum_MaxWidthMinus20() {
UsageMessageSpec spec = CommandSpec.create().usageMessage();
spec.longOptionsMaxWidth(spec.width() - 20);
assertEquals(60, spec.longOptionsMaxWidth());
TestUtil.setTraceLevel(CommandLine.TraceLevel.INFO);

spec.longOptionsMaxWidth(61);
assertEquals(60, spec.longOptionsMaxWidth());

String expected = "Invalid usage long options max width 61. Value must not exceed width(80) - 20";
assertTrue(systemErrRule.getLog(), systemErrRule.getLog().contains(expected));
}

@Test
Expand Down

0 comments on commit c1af2c7

Please sign in to comment.