Class OptionsUtils
java.lang.Object
ubic.gemma.cli.util.OptionsUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAutoOption(org.apache.commons.cli.Options options, String optionName, String longOptionName, String description, String noOptionName, String longNoOptionName, String noDescription) static voidaddAutoOption(org.apache.commons.cli.Options options, String optionName, String longOptionName, String description, String noOptionName, String longNoOptionName, String noDescription, String defaultDescription) Add an option with three possible values:true,false, ornull.static voidaddDateOption(String name, String longOpt, String desc, org.apache.commons.cli.Options options) Add a date option with support for fuzzy dates (i.e.static <T extends Enum<T>>
voidaddEnumOption(org.apache.commons.cli.Options options, String optionName, String longOption, String description, Class<T> enumClass) Add an enumerated option with localized descriptions.static <T extends Enum<T>>
voidaddEnumOption(org.apache.commons.cli.Options options, String optionName, String longOption, String description, Class<T> enumClass, EnumMap<T, org.springframework.context.MessageSourceResolvable> descriptions) Add an enumerated option with descriptions.static <T extends Enum<T>>
voidaddEnumSetOption(org.apache.commons.cli.Options options, String optionName, String longOption, String description, Class<T> enumClass) static Predicate<org.apache.commons.cli.CommandLine> Make sure that all the given predicates are true.static Predicate<org.apache.commons.cli.CommandLine> Make sure that at least one of the given predicate is true.static StringformatOption(String opt, String longOpt) static StringformatOption(org.apache.commons.cli.Option opt) static StringformatOption(org.apache.commons.cli.Options options, String optionName) Format an option for display.static BooleangetAutoOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, String noOptionName) static <T extends Enum<T>>
TgetEnumOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName) Obtain the value of an enumerated option.static <T extends Enum<T>>
TgetEnumOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) Obtain the value of an enumerated option and if present, make sure that it satisfies a predicate.getEnumSetOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName) static StringgetOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) Obtain the value of an option and if present, make sure that it satisfies a predicate.static String[]getOptionValues(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) static <T> TgetParsedOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) static booleanhasAnyOption(org.apache.commons.cli.CommandLine commandLine, String... options) Check if any of the given options is present in the command line.static booleanhasOption(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) Check if an option is present, and if so make sure that the predicate is satisfied.static booleanisFileOption(org.apache.commons.cli.Option o) static Predicate<org.apache.commons.cli.CommandLine> Make sure that none of the given predicates are true.static Predicate<org.apache.commons.cli.CommandLine> Make sure that the given predicate is satisfied.static Predicate<org.apache.commons.cli.CommandLine> Make sure that the given option is present.static Predicate<org.apache.commons.cli.CommandLine> Make sure that the given option is missing.
-
Constructor Details
-
OptionsUtils
public OptionsUtils()
-
-
Method Details
-
addDateOption
-
addAutoOption
-
addAutoOption
public static void addAutoOption(org.apache.commons.cli.Options options, String optionName, String longOptionName, String description, String noOptionName, String longNoOptionName, String noDescription, String defaultDescription) Add an option with three possible values:true,false, ornull.Use
getAutoOptionValue(CommandLine, String, String)to retrieve its value later on.- Parameters:
defaultDescription- description of the default behavior when neither option is specified
-
formatOption
-
getAutoOptionValue
-
addEnumOption
public static <T extends Enum<T>> void addEnumOption(org.apache.commons.cli.Options options, String optionName, String longOption, String description, Class<T> enumClass) Add an enumerated option with localized descriptions.The code pattern for the message source is
<enum class name>.<enum value>.label. -
addEnumOption
-
addEnumSetOption
-
getEnumOptionValue
@Nullable public static <T extends Enum<T>> T getEnumOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName) throws org.apache.commons.cli.ParseException Obtain the value of an enumerated option.The option must have been previously declared with
addEnumOption(Options, String, String, String, Class).- Throws:
org.apache.commons.cli.ParseException
-
getEnumSetOptionValue
-
getEnumOptionValue
@Nullable public static <T extends Enum<T>> T getEnumOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) throws org.apache.commons.cli.ParseException Obtain the value of an enumerated option and if present, make sure that it satisfies a predicate.The option must have been previously declared with
addEnumOption(Options, String, String, String, Class).- Throws:
org.apache.commons.cli.ParseException
-
getOptionValue
@Nullable public static String getOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) throws org.apache.commons.cli.ParseException Obtain the value of an option and if present, make sure that it satisfies a predicate.- Throws:
org.apache.commons.cli.ParseException
-
getOptionValues
-
getParsedOptionValue
-
hasOption
public static boolean hasOption(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) throws org.apache.commons.cli.ParseException Check if an option is present, and if so make sure that the predicate is satisfied.The predicate can be any
Predicate, but using the ones defined in this class will produce more informative error messages.- Throws:
org.apache.commons.cli.ParseException
-
hasAnyOption
public static boolean hasAnyOption(org.apache.commons.cli.CommandLine commandLine, String... options) Check if any of the given options is present in the command line. -
requires
-
anyOf
@SafeVarargs public static Predicate<org.apache.commons.cli.CommandLine> anyOf(Predicate<org.apache.commons.cli.CommandLine>... optionNames) Make sure that at least one of the given predicate is true. -
allOf
@SafeVarargs public static Predicate<org.apache.commons.cli.CommandLine> allOf(Predicate<org.apache.commons.cli.CommandLine>... optionNames) Make sure that all the given predicates are true. -
noneOf
@SafeVarargs public static Predicate<org.apache.commons.cli.CommandLine> noneOf(Predicate<org.apache.commons.cli.CommandLine>... optionNames) Make sure that none of the given predicates are true. -
toBeSet
-
toBeUnset
-
formatOption
-
formatOption
-
isFileOption
public static boolean isFileOption(org.apache.commons.cli.Option o)
-