Skip to content

Commit

Permalink
Fixed backwards compatiblity fail: ParameterDescription.getDefault() …
Browse files Browse the repository at this point in the history
…must not produce different result as existing code relies on current behavior
  • Loading branch information
mkarg committed Oct 2, 2023
1 parent bffc92d commit 6e44352
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void appendAllParametersDetails(StringBuilder out, int indentCount, Strin
if (hasDescription) {
wrapDescription(out, indentCount, s(indentCount) + description);
}
Object def = pd.getDefault();
Object def = pd.getDefaultValueDescription();

if (pd.isDynamicParameter()) {
String syntax = "Syntax: " + parameter.names()[0] + "key" + parameter.getAssignment() + "value";
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/beust/jcommander/ParameterDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,14 @@ public String getLongestName() {
return longestName;
}

public Object getDefault() {
return defaultObject;
}

/**
* @return defaultValueDescription, if description is empty string, return default Object.
*/
public Object getDefault() {
public Object getDefaultValueDescription() {
return parameterAnnotation == null ? defaultObject : parameterAnnotation.defaultValueDescription().isEmpty() ? defaultObject : parameterAnnotation.defaultValueDescription();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void appendAllParametersDetails(StringBuilder out, int indentCount, Strin

// Generate description
String description = pd.getDescription();
Object def = pd.getDefault();
Object def = pd.getDefaultValueDescription();

if (pd.isDynamicParameter()) {
String syntax = "(syntax: " + parameter.names()[0] + "key" + parameter.getAssignment() + "value)";
Expand Down

0 comments on commit 6e44352

Please sign in to comment.