Browse Source

RFC: Ugly fix for i18n of metaVar CLI arguments

This patch possibly ties to a specific version of args4j.

Bug: 318286
Change-Id: I05d4ecf6bd25deec7fb2efbfa61913f4ec4e04e5
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
stable-1.1
Robin Rosenberg 14 years ago
parent
commit
529a348961
  1. 31
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
  2. 36
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/CmdLineParser.java

31
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java

@ -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;

36
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/CmdLineParser.java

@ -43,12 +43,17 @@
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);
}
}

Loading…
Cancel
Save