Fix metaVar printing in REST API help usage

The metaVar used in @Option annotations was not being respected.
Use this value before asking the handler for its default value.

Change-Id: If0193983b9ebbb646ac325f28fefcb667b4f5bec
This commit is contained in:
Shawn Pearce 2013-05-16 12:59:29 -07:00
parent 5c0d6b33ff
commit fec1537a56

View File

@ -34,6 +34,7 @@
package com.google.gerrit.util.cli; package com.google.gerrit.util.cli;
import com.google.common.base.Strings;
import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -153,12 +154,7 @@ public class CmdLineParser {
} }
out.write('='); out.write('=');
String var = handler.getDefaultMetaVariable(); out.write(metaVar(handler, n));
if (handler instanceof EnumOptionHandler) {
var = var.substring(1, var.length() - 1);
var = var.replaceAll(" ", "");
}
out.write(var);
if (!n.required()) { if (!n.required()) {
out.write(']'); out.write(']');
} }
@ -186,6 +182,17 @@ public class CmdLineParser {
} }
} }
private static String metaVar(OptionHandler<?> handler, NamedOptionDef n) {
String var = n.metaVar();
if (Strings.isNullOrEmpty(var)) {
var = handler.getDefaultMetaVariable();
if (handler instanceof EnumOptionHandler) {
var = var.substring(1, var.length() - 1).replace(" ", "");
}
}
return var;
}
public boolean wasHelpRequestedByOption() { public boolean wasHelpRequestedByOption() {
return parser.help.value; return parser.help.value;
} }