]> source.dussan.org Git - jgit.git/commitdiff
RFC: Ugly fix for i18n of metaVar CLI arguments 58/3758/1
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Sun, 19 Jun 2011 22:55:13 +0000 (00:55 +0200)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Sun, 19 Jun 2011 22:55:13 +0000 (00:55 +0200)
This patch possibly ties to a specific version of args4j.

Bug: 318286
Change-Id: I05d4ecf6bd25deec7fb2efbfa61913f4ec4e04e5
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/CmdLineParser.java

index cf57f20b7ba5d8f48fc0953aa41352b9f1264836..d82ff499f9085f114b853de117a8eb0f2f73eb77 100644 (file)
@@ -113,12 +113,43 @@ public class CLIText extends TranslationBundle {
        /***/ public String mergeConflict;
        /***/ public String mergeFailed;
        /***/ public String mergeMadeBy;
+       /***/ public String metaVar_KEY;
+       /***/ public String metaVar_arg;
+       /***/ public String metaVar_author;
+       /***/ public String metaVar_bucket;
        /***/ public String metaVar_command;
+       /***/ public String metaVar_commandDetail;
+       /***/ public String metaVar_commitOrTag;
+       /***/ public String metaVar_commitPaths;
        /***/ public String metaVar_commitish;
+       /***/ public String metaVar_configFile;
+       /***/ public String metaVar_connProp;
+       /***/ public String metaVar_diffAlg;
+       /***/ public String metaVar_directory;
+       /***/ public String metaVar_file;
+       /***/ public String metaVar_gitDir;
+       /***/ public String metaVar_hostName;
+       /***/ public String metaVar_linesOfContext;
+       /***/ public String metaVar_message;
+       /***/ public String metaVar_n;
+       /***/ public String metaVar_name;
        /***/ public String metaVar_object;
+       /***/ public String metaVar_op;
+       /***/ public String metaVar_pass;
+       /***/ public String metaVar_path;
        /***/ public String metaVar_paths;
+       /***/ public String metaVar_port;
+       /***/ public String metaVar_ref;
+       /***/ public String metaVar_refs;
        /***/ public String metaVar_refspec;
+       /***/ public String metaVar_remoteName;
+       /***/ public String metaVar_seconds;
+       /***/ public String metaVar_service;
        /***/ public String metaVar_treeish;
+       /***/ public String metaVar_uriish;
+       /***/ public String metaVar_url;
+       /***/ public String metaVar_user;
+       /***/ public String metaVar_version;
        /***/ public String mostCommonlyUsedCommandsAre;
        /***/ public String needApprovalToDestroyCurrentRepository;
        /***/ public String noGitRepositoryConfigured;
index 7e61fb0418bc0928bc93c28072a90ed5e640df55..b14130f4aa7ef562cc24f6087c5967dbd0a2cda2 100644 (file)
 
 package org.eclipse.jgit.pgm.opt;
 
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 
 import org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.CmdLineException;
 import org.kohsuke.args4j.IllegalAnnotationError;
+import org.kohsuke.args4j.NamedOptionDef;
 import org.kohsuke.args4j.Option;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Setter;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.pgm.CLIText;
@@ -175,4 +180,35 @@ public class CmdLineParser extends org.kohsuke.args4j.CmdLineParser {
        public RevWalk getRevWalkGently() {
                return walk;
        }
+
+       static class MyOptionDef extends OptionDef {
+
+               public MyOptionDef(OptionDef o) {
+                       super(o.usage(), o.metaVar(), o.required(), o.handler(), o
+                                       .isMultiValued());
+               }
+
+               @Override
+               public String toString() {
+                       if (metaVar() == null)
+                               return "ARG";
+                       try {
+                               Field field = CLIText.class.getField(metaVar());
+                               String ret = field.get(CLIText.get()).toString();
+                               return ret;
+                       } catch (Exception e) {
+                               e.printStackTrace(System.err);
+                               return metaVar();
+                       }
+               }
+       }
+
+       @Override
+       protected OptionHandler createOptionHandler(OptionDef o, Setter setter) {
+               if (o instanceof NamedOptionDef)
+                       return super.createOptionHandler(o, setter);
+               else
+                       return super.createOptionHandler(new MyOptionDef(o), setter);
+
+       }
 }