diff --git a/core/java/src/net/i2p/util/CommandLine.java b/core/java/src/net/i2p/util/CommandLine.java index 1a12e6199..0b22ba86d 100644 --- a/core/java/src/net/i2p/util/CommandLine.java +++ b/core/java/src/net/i2p/util/CommandLine.java @@ -19,6 +19,7 @@ import net.i2p.CoreVersion; public class CommandLine { protected static final List CLASSES = Arrays.asList(new String[] { + "help", "freenet.support.CPUInformation.CPUID", "net.i2p.CoreVersion", "net.i2p.client.naming.LookupDest", @@ -64,15 +65,33 @@ public class CommandLine { /** will only return if command not found */ protected static void exec(String args[], List classes) { + boolean help = false; String cmd = args[0].toLowerCase(Locale.US); + if (cmd.equals("help")) { + if (args.length != 2) + return; + cmd = args[1].toLowerCase(Locale.US); + args[1] = "-?"; + help = true; + } for (String cls : classes) { String ccmd = cls.substring(cls.lastIndexOf('.') + 1).toLowerCase(Locale.US); if (cmd.equals(ccmd)) { try { + Class c = Class.forName(cls, true, ClassLoader.getSystemClassLoader()); + if (help) { + // if it has a usage() method, call that instead + try { + Method usage = c.getDeclaredMethod("usage", (Class[]) null); + usage.setAccessible(true); + usage.invoke(null); + System.exit(0); + } catch (Exception e) {} + // else fall through to try main("-?") + } + Method main = c.getMethod("main", String[].class); String[] cargs = new String[args.length - 1]; System.arraycopy(args, 1, cargs, 0, args.length - 1); - Class c = Class.forName(cls, true, ClassLoader.getSystemClassLoader()); - Method main = c.getMethod("main", String[].class); main.invoke(null, (Object) cargs); System.exit(0); } catch (Exception e) { @@ -100,6 +119,6 @@ public class CommandLine { for (String cmd : cmds) { System.err.println(" " + cmd); } - System.err.println("Enter command for detailed help."); + System.err.println("Enter \"help command\" for detailed help."); } }