From fec1537a56adec51751853e87be96f394f127833 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Thu, 16 May 2013 12:59:29 -0700 Subject: [PATCH] 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 --- .../google/gerrit/util/cli/CmdLineParser.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gerrit-util-cli/src/main/java/com/google/gerrit/util/cli/CmdLineParser.java b/gerrit-util-cli/src/main/java/com/google/gerrit/util/cli/CmdLineParser.java index 69598ce12e..5f6130c9e7 100644 --- a/gerrit-util-cli/src/main/java/com/google/gerrit/util/cli/CmdLineParser.java +++ b/gerrit-util-cli/src/main/java/com/google/gerrit/util/cli/CmdLineParser.java @@ -34,6 +34,7 @@ package com.google.gerrit.util.cli; +import com.google.common.base.Strings; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -153,12 +154,7 @@ public class CmdLineParser { } out.write('='); - String var = handler.getDefaultMetaVariable(); - if (handler instanceof EnumOptionHandler) { - var = var.substring(1, var.length() - 1); - var = var.replaceAll(" ", ""); - } - out.write(var); + out.write(metaVar(handler, n)); if (!n.required()) { 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() { return parser.help.value; }