OSDN Git Service

Initial release to sourceforge
[dvibrowser/dvi2epub.git] / src / jp / sourceforge / dvibrowser / dvi2epub / cmd / Option.java
index ee13345..e05187e 100644 (file)
@@ -34,10 +34,15 @@ package jp.sourceforge.dvibrowser.dvi2epub.cmd;
 
 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;
@@ -45,9 +50,27 @@ public class Option {
        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() {
@@ -58,6 +81,11 @@ public class Option {
                return longName;
        }
        
+       public String getLongNameForHelp() {
+               return longNameForHelp;
+       }
+
+       
        public boolean matches(String optionName)
        {
                if (shortName != null && shortName.equals(optionName)) {
@@ -79,4 +107,8 @@ public class Option {
        public Method getMethod() {
                return method;
        }
+
+       public String getShortNameForHelp() {
+               return shortNameForHelp;
+       }
 }