Class PatternOptionBuilder

java.lang.Object
org.apache.commons.cli.PatternOptionBuilder

public class PatternOptionBuilder extends Object
Allows Options to be created from a single String. The pattern contains various single character flags and via an optional punctuation character, their expected type.
Overview of PatternOptionBuilder patterns
a -a flag
b@ -b [class name]
c> -c [file name]
d+ -d [class name] (creates object via empty constructor)
e% -e [number] (creates Double/Long instance depending on existing of a '.')
f/ -f [URL]
g: -g [string]

For example, the following allows command line flags of '-v -p string-value -f /dir/file'. The exclamation mark precede a mandatory option.

 Options options = PatternOptionBuilder.parsePattern("vp:!f/");
 

TODO These need to break out to OptionType and also to be pluggable.

  • Field Details

  • Constructor Details

    • PatternOptionBuilder

      Deprecated.
      Will be private or class will be final.
      Deprecated, only provides static methods.
  • Method Details

    • getValueClass

      @Deprecated public static Object getValueClass(char ch)
      Deprecated.
      Retrieve the class that ch represents.
      Parameters:
      ch - the specified character
      Returns:
      The class that ch represents
    • getValueType

      public static Class<?> getValueType(char ch)
      Retrieve the class that ch represents.
      Parameters:
      ch - the specified character
      Returns:
      The class that ch represents
      Since:
      1.7.0
    • isValueCode

      public static boolean isValueCode(char ch)
      Returns whether ch is a value code, i.e. whether it represents a class in a pattern.
      Parameters:
      ch - the specified character
      Returns:
      true if ch is a value code, otherwise false.
    • parsePattern

      public static Options parsePattern(String pattern)
      Returns the Options instance represented by pattern.
      Parameters:
      pattern - the pattern string
      Returns:
      The Options instance