keytool new help
# HG changeset patch
# User weijun
# Date 1250851695 -28800
# Node ID 54bf14e5d79db454b251e5615f80defc49d966df
# Parent d2ca42467613db506c7e062c1686847812be647c
6324292: keytool -help is unhelpful
Reviewed-by: nobody
--- a/src/share/classes/sun/security/tools/KeyTool.java Fri Aug 21 17:55:15 2009 +0800
+++ b/src/share/classes/sun/security/tools/KeyTool.java Fri Aug 21 18:48:15 2009 +0800
@@ -229,6 +229,15 @@
return;
}
+ if (collator.compare(args[0], "-help") == 0) {
+ if (args.length > 1) {
+ usage(args[1]);
+ } else {
+ usage();
+ }
+ return;
+ }
+
int i=0;
for (i=0; (i < args.length) && args[i].startsWith("-"); i++) {
@@ -247,9 +256,6 @@
} else if (collator.compare(flags, "-genkey") == 0 ||
collator.compare(flags, "-genkeypair") == 0) {
command = GENKEYPAIR;
- } else if (collator.compare(flags, "-help") == 0) {
- usage();
- return;
} else if (collator.compare(flags, "-identitydb") == 0) { // obsolete
command = IDENTITYDB;
} else if (collator.compare(flags, "-import") == 0 ||
@@ -3683,10 +3689,68 @@
return ext;
}
+ String[][] commands = {
+ {"-genkeypair", "Generates keypairs", "KsStV"},
+ {"-genseckey", "Generates secret keys", "KsSt"},
+ {"-gencert", "Generates certificates", "V"},
+ };
+ String[][] options = {
+ {"Ks", "-keystore", "Specifies the keystore file, NONE if storetype is pkcs11"},
+ {"St", "-storetype", "Specfiies the keystore type"},
+ {"V", "-v", "Verbose output"},
+ };
+
+ private void usage() {
+ System.err.println("Keystore and certificate management tool");
+ System.err.println();
+ System.err.println("Commands:");
+ System.err.println();
+ for (String[] c: commands) {
+ System.err.printf(" %-20s%s\n", c[0], c[1]);
+ }
+ System.err.println();
+ System.err.println("Use \"keytool -help command-name\" for usage of command-name");
+ }
+
+ private void usage(String command) {
+ for (String[] c: commands) {
+ if (collator.compare(c[0], command) == 0) {
+ System.err.println("keytool " + c[0] + " [OPTION]...");
+ System.err.println();
+ System.err.println(c[1]);
+ System.err.println();
+ System.err.println("Options:");
+ System.err.println();
+ int pos = 0;
+ while (true) {
+ int i = pos+1;
+ for (; i<c[2].length(); i++) {
+ if (Character.isUpperCase(c[2].charAt(i))) {
+ break;
+ }
+ }
+ String abbr = c[2].substring(pos, i);
+ for (String[] opt: options) {
+ if (collator.compare(opt[0], abbr) == 0) {
+ System.err.printf(" %-20s%s\n", opt[1], opt[2]);
+ break;
+ }
+ }
+ if (i == c[2].length()) break;
+ pos = i;
+ }
+ return;
+ }
+ }
+ System.err.println("Cannot find command " + command);
+ System.err.println();
+ tinyHelp();
+ }
+
/**
* Prints the usage of this tool.
*/
- private void usage() {
+ private void usage2() {
System.err.println(rb.getString("keytool usage:\n"));
System.err.println(rb.getString