import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class Option {
- private final String shortName;
- private final String longName;
+ public static final Pattern PAT_SHORT_PARAM = Pattern.compile("([a-zA-Z0-9])(<.*>)");
+ public static final Pattern PAT_LONG_PARAM = Pattern.compile("([-_a-zA-Z0-9]+)=(.*)");
+
+ private final String shortName, shortNameForHelp;
+ private final String longName, longNameForHelp;
private final Annotation annotation;
private final String description;
private final Method method;
public Option(Annotation annotation, Method method, String shortName, String longName, String description) {
this.annotation = annotation;
this.method = method;
- this.shortName = shortName;
- this.longName = longName;
+ this.shortNameForHelp = shortName;
+ this.longNameForHelp = longName;
this.description = description;
+ {
+ Matcher mat = PAT_SHORT_PARAM.matcher(getShortNameForHelp());
+ if (mat.matches()) {
+ this.shortName = mat.group(1);
+ } else {
+ this.shortName = getShortNameForHelp();
+ }
+ }
+ {
+ Matcher mat = PAT_LONG_PARAM.matcher(longNameForHelp);
+ {
+ if (mat.matches()) {
+ this.longName = mat.group(1);
+ } else {
+ this.longName = longNameForHelp;
+ }
+ }
+ }
}
public String getShortName() {
return longName;
}
+ public String getLongNameForHelp() {
+ return longNameForHelp;
+ }
+
+
public boolean matches(String optionName)
{
if (shortName != null && shortName.equals(optionName)) {
public Method getMethod() {
return method;
}
+
+ public String getShortNameForHelp() {
+ return shortNameForHelp;
+ }
}