Class OptionsUtils

java.lang.Object
ubic.gemma.cli.util.OptionsUtils

public class OptionsUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addAutoOption(org.apache.commons.cli.Options options, String optionName, String longOptionName, String description, String noOptionName, String longNoOptionName, String noDescription)
    Add an option with three possible values: true, false, or null.
    static void
    addDateOption(String name, String longOpt, String desc, org.apache.commons.cli.Options options)
    Add a date option with support for fuzzy dates (i.e. one month ago).
    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.
    static <T extends Enum<T>>
    void
    addEnumOption(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>>
    void
    addEnumSetOption(org.apache.commons.cli.Options options, String optionName, String longOption, String description, Class<T> enumClass)
     
    static Predicate<org.apache.commons.cli.CommandLine>
    allOf(Predicate<org.apache.commons.cli.CommandLine>... optionNames)
    Make sure that all the given predicates are true.
    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.
    static String
    formatOption(org.apache.commons.cli.Options options, String optionName)
    Format an option for display.
    static Boolean
    getAutoOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, String noOptionName)
     
    static <T extends Enum<T>>
    T
    getEnumOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName)
    Obtain the value of an enumerated option.
    static <T extends Enum<T>>
    T
    getEnumOptionValue(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.
    static <T extends Enum<T>>
    EnumSet<T>
    getEnumSetOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName)
     
    static String
    getOptionValue(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> T
    getParsedOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate)
     
    static boolean
    hasAnyOption(org.apache.commons.cli.CommandLine commandLine, String... options)
    Check if any of the given options is present in the command line.
    static boolean
    hasOption(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 Predicate<org.apache.commons.cli.CommandLine>
    noneOf(Predicate<org.apache.commons.cli.CommandLine>... optionNames)
    Make sure that none of the given predicates are true.
    static Predicate<org.apache.commons.cli.CommandLine>
    requires(Predicate<org.apache.commons.cli.CommandLine> predicate)
    Make sure that the given predicate is satisfied.
    static Predicate<org.apache.commons.cli.CommandLine>
    toBeSet(String optionName)
    Make sure that the given option is present.
    static Predicate<org.apache.commons.cli.CommandLine>
    toBeUnset(String optionName)
    Make sure that the given option is missing.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OptionsUtils

      public OptionsUtils()
  • Method Details

    • addDateOption

      public static void addDateOption(String name, @Nullable String longOpt, String desc, org.apache.commons.cli.Options options)
      Add a date option with support for fuzzy dates (i.e. one month ago).
      See Also:
      • OptionsUtils.DateConverterImpl
    • addAutoOption

      public static void addAutoOption(org.apache.commons.cli.Options options, String optionName, String longOptionName, String description, String noOptionName, String longNoOptionName, String noDescription)
      Add an option with three possible values: true, false, or null.

      Use getAutoOptionValue(CommandLine, String, String) to retrieve its value later on.

    • formatOption

      public static String formatOption(org.apache.commons.cli.Options options, String optionName)
      Format an option for display.
    • getAutoOptionValue

      @Nullable public static Boolean getAutoOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, String noOptionName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • 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

      public static <T extends Enum<T>> void addEnumOption(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.
    • addEnumSetOption

      public static <T extends Enum<T>> void addEnumSetOption(org.apache.commons.cli.Options options, String optionName, String longOption, String description, Class<T> enumClass)
    • 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

      @Nullable public static <T extends Enum<T>> EnumSet<T> getEnumSetOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • 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

      @Nullable public static String[] getOptionValues(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getParsedOptionValue

      @Nullable public static <T> T getParsedOptionValue(org.apache.commons.cli.CommandLine commandLine, String optionName, Predicate<org.apache.commons.cli.CommandLine> predicate) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
      See Also:
    • 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

      public static Predicate<org.apache.commons.cli.CommandLine> requires(Predicate<org.apache.commons.cli.CommandLine> predicate)
      Make sure that the given predicate is satisfied.

      This is useful as a top-level predicate as it prepents "requires " to the description.

    • 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

      public static Predicate<org.apache.commons.cli.CommandLine> toBeSet(String optionName)
      Make sure that the given option is present.
    • toBeUnset

      public static Predicate<org.apache.commons.cli.CommandLine> toBeUnset(String optionName)
      Make sure that the given option is missing.