Move newOption method to a new public class
Change-Id: Ieac80706db729dee16bfde46e3b9f44ab7ac3006
diff --git a/java/com/google/gerrit/util/cli/CmdLineParser.java b/java/com/google/gerrit/util/cli/CmdLineParser.java
index 4634b00..1c16133 100644
--- a/java/com/google/gerrit/util/cli/CmdLineParser.java
+++ b/java/com/google/gerrit/util/cli/CmdLineParser.java
@@ -38,7 +38,6 @@
import static com.google.gerrit.util.cli.Localizable.localizable;
import static java.util.Objects.requireNonNull;
-import com.google.auto.value.AutoAnnotation;
import com.google.common.base.Strings;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
@@ -424,7 +423,7 @@
requireNonNull(prefix);
checkArgument(o.name().startsWith("-"), "Option name must start with '-': %s", o);
String[] aliases = Arrays.stream(o.aliases()).map(prefix::concat).toArray(String[]::new);
- return newOption(
+ return OptionUtil.newOption(
prefix + o.name(),
aliases,
o.usage(),
@@ -437,22 +436,6 @@
new String[0]);
}
- @AutoAnnotation
- private static Option newOption(
- String name,
- String[] aliases,
- String usage,
- String metaVar,
- boolean required,
- boolean help,
- boolean hidden,
- Class<? extends OptionHandler> handler,
- String[] depends,
- String[] forbids) {
- return new AutoAnnotation_CmdLineParser_newOption(
- name, aliases, usage, metaVar, required, help, hidden, handler, depends, forbids);
- }
-
public class MyParser extends org.kohsuke.args4j.CmdLineParser {
boolean help;
@@ -640,7 +623,7 @@
}
private Option newHelpOption() {
- return newOption(
+ return OptionUtil.newOption(
"--help",
new String[] {"-h"},
"display this help text",
diff --git a/java/com/google/gerrit/util/cli/OptionUtil.java b/java/com/google/gerrit/util/cli/OptionUtil.java
new file mode 100644
index 0000000..1125a0d
--- /dev/null
+++ b/java/com/google/gerrit/util/cli/OptionUtil.java
@@ -0,0 +1,39 @@
+// Copyright (C) 2019 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.util.cli;
+
+import com.google.auto.value.AutoAnnotation;
+import org.kohsuke.args4j.Option;
+import org.kohsuke.args4j.spi.OptionHandler;
+
+/** Utilities to support creating new {@link Option} instances. */
+public class OptionUtil {
+ @AutoAnnotation
+ @SuppressWarnings("rawtypes")
+ public static Option newOption(
+ String name,
+ String[] aliases,
+ String usage,
+ String metaVar,
+ boolean required,
+ boolean help,
+ boolean hidden,
+ Class<? extends OptionHandler> handler,
+ String[] depends,
+ String[] forbids) {
+ return new AutoAnnotation_OptionUtil_newOption(
+ name, aliases, usage, metaVar, required, help, hidden, handler, depends, forbids);
+ }
+}