Skip to content

Commit

Permalink
Fixed #471 @param(default = ) (#518)
Browse files Browse the repository at this point in the history
Fixes #471 by implementing optional `defaultValueDescription` parameter which overrides the automatic description.
  • Loading branch information
fsd654qyl authored Oct 2, 2023
1 parent e7bd5fc commit caeb4ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/com/beust/jcommander/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
*/
String description() default "";

/**
* Description of default value.
*/
String defaultValueDescription() default "";

/**
* Whether this option is required.
*/
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/beust/jcommander/ParameterDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,15 @@ public String getLongestName() {
return longestName;
}

/**
* @return defaultValueDescription, if description is empty string, return default Object.
*/
public Object getDefault() {
return defaultObject;
String defaultDescription = parameterAnnotation.defaultValueDescription();
if (defaultDescription.isEmpty())
return defaultObject;
else
return defaultDescription;
}

public String getDescription() {
Expand Down

0 comments on commit caeb4ea

Please sign in to comment.