CmdLineParser: Require plugin option names to start with '-'

This is normally a requirement for args4j options, but in the case of
plugin options, the option name is produced by prefixing with
"--myplugin", so an incorrect name in the @Option annotation in a plugin
will not produce an error. Add a manual check for this case, forcing
options to always be named "--myplugin-o" or "--myplugin--opt".

Change-Id: I9e6810ec5470f001b8e772f046e4d3e8be5f7247
This commit is contained in:
Dave Borowitz
2019-03-14 07:10:54 -07:00
parent e8e13da9ea
commit 3062b66368

View File

@@ -34,6 +34,7 @@
package com.google.gerrit.util.cli;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.gerrit.util.cli.Localizable.localizable;
import com.google.common.base.Strings;
@@ -426,6 +427,7 @@ public class CmdLineParser {
PrefixedOption(String prefix, Option o) {
this.prefix = prefix;
checkArgument(o.name().startsWith("-"), "Option name must start with '-': %s", o);
this.o = o;
}