Move newOption method to a new public class
Change-Id: Ieac80706db729dee16bfde46e3b9f44ab7ac3006
This commit is contained in:
@@ -38,7 +38,6 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||||||
import static com.google.gerrit.util.cli.Localizable.localizable;
|
import static com.google.gerrit.util.cli.Localizable.localizable;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
import com.google.auto.value.AutoAnnotation;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ListMultimap;
|
import com.google.common.collect.ListMultimap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -424,7 +423,7 @@ public class CmdLineParser {
|
|||||||
requireNonNull(prefix);
|
requireNonNull(prefix);
|
||||||
checkArgument(o.name().startsWith("-"), "Option name must start with '-': %s", o);
|
checkArgument(o.name().startsWith("-"), "Option name must start with '-': %s", o);
|
||||||
String[] aliases = Arrays.stream(o.aliases()).map(prefix::concat).toArray(String[]::new);
|
String[] aliases = Arrays.stream(o.aliases()).map(prefix::concat).toArray(String[]::new);
|
||||||
return newOption(
|
return OptionUtil.newOption(
|
||||||
prefix + o.name(),
|
prefix + o.name(),
|
||||||
aliases,
|
aliases,
|
||||||
o.usage(),
|
o.usage(),
|
||||||
@@ -437,22 +436,6 @@ public class CmdLineParser {
|
|||||||
new String[0]);
|
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 {
|
public class MyParser extends org.kohsuke.args4j.CmdLineParser {
|
||||||
boolean help;
|
boolean help;
|
||||||
|
|
||||||
@@ -640,7 +623,7 @@ public class CmdLineParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Option newHelpOption() {
|
private Option newHelpOption() {
|
||||||
return newOption(
|
return OptionUtil.newOption(
|
||||||
"--help",
|
"--help",
|
||||||
new String[] {"-h"},
|
new String[] {"-h"},
|
||||||
"display this help text",
|
"display this help text",
|
||||||
|
|||||||
39
java/com/google/gerrit/util/cli/OptionUtil.java
Normal file
39
java/com/google/gerrit/util/cli/OptionUtil.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user