Skip to content

Commit

Permalink
Handling specific message for invalid scenarios
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 c1af2c7 commit 132f1ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -7824,10 +7824,12 @@ public UsageMessageSpec width(int newValue) {
* @return this {@code UsageMessageSpec} for method chaining
* @since 4.2 */
public UsageMessageSpec longOptionsMaxWidth(int newValue) {
if (newValue >= DEFAULT_USAGE_LONG_OPTIONS_WIDTH && newValue <= width() - DEFAULT_USAGE_LONG_OPTIONS_WIDTH) {
longOptionsMaxWidth = newValue;
if (newValue < DEFAULT_USAGE_LONG_OPTIONS_WIDTH) {
CommandLine.tracer().info("Invalid usage long options max width %d. Minimum value is %d", newValue, DEFAULT_USAGE_LONG_OPTIONS_WIDTH);
} else if (newValue > width() - DEFAULT_USAGE_LONG_OPTIONS_WIDTH) {
CommandLine.tracer().info("Invalid usage long options max width %d. Value must not exceed width(%d) - %d", newValue , width(), DEFAULT_USAGE_LONG_OPTIONS_WIDTH);
} 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);
longOptionsMaxWidth = newValue;
}
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/picocli/HelpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4396,7 +4396,7 @@ public void testUsageMessageSpec_LongOptionsColumnLengthMinimum_Minimum20() {
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";
String expected = "Invalid usage long options max width 19. Minimum value is 20";
assertTrue(systemErrRule.getLog(), systemErrRule.getLog().contains(expected));
}

Expand Down

0 comments on commit 132f1ab

Please sign in to comment.