Class OptionUtils

java.lang.Object
org.xblackcat.sjpu.cli.OptionUtils

public class OptionUtils extends Object
  • Field Details

  • Constructor Details

    • OptionUtils

      public OptionUtils()
  • Method Details

    • parseProgressOutputStream

      public static LogPrintStream parseProgressOutputStream(org.apache.commons.cli.CommandLine line, String optionName) throws InvalidOptionException
      Throws:
      InvalidOptionException
    • parseVerbosity

      public static Verbosity parseVerbosity(org.apache.commons.cli.CommandLine cmd)
    • getReader

      public static BufferedReader getReader(org.apache.commons.cli.CommandLine line, String optionName) throws IOException
      Throws:
      IOException
    • getPrintStream

      public static PrintStream getPrintStream(org.apache.commons.cli.CommandLine line, String fileOptionName) throws IOException
      Throws:
      IOException
    • getPrintStream

      public static PrintStream getPrintStream(org.apache.commons.cli.CommandLine line, boolean stdOutAsDefault, String fileOptionName) throws IOException
      Throws:
      IOException
    • getOutputStream

      public static OutputStream getOutputStream(org.apache.commons.cli.CommandLine line, String fileNameOption, String gzipOption) throws IOException
      Throws:
      IOException
    • getBounds

      public static <T extends Comparable<? super T>> Bounds<T> getBounds(org.apache.commons.cli.CommandLine line, String optionName, String description, Function<String,T> convert, String defaultLowerBound, String defaultUpperBound) throws InvalidOptionException
      Throws:
      InvalidOptionException
    • getBounds

      public static <T extends Comparable<? super T>> Bounds<T> getBounds(org.apache.commons.cli.CommandLine line, String optionName, String description, Function<String,T> convert, T defaultLowerBound, T defaultUpperBound) throws InvalidOptionException
      Throws:
      InvalidOptionException
    • getBounds

      public static Bounds<Integer> getBounds(org.apache.commons.cli.CommandLine line, String optionName, String description, int defaultLowerBound, int defaultUpperBound) throws InvalidOptionException
      Throws:
      InvalidOptionException
    • getStringList

      public static String[] getStringList(org.apache.commons.cli.CommandLine line, String optionName) throws InvalidOptionException
      Parse option from command line to read string list. Values could be specified as comma-separated argument of option or file name. To pass file name as source of string list use @ prefix for option value. IllegalArgumentException will be thrown if option is not set. Examples:

      -<option> "value1,value2,value3"

      -<option> "@source_file_name"

      Parameters:
      line - parsed command line
      optionName - option name
      Returns:
      string list parsed from argument or read from external file
      Throws:
      InvalidOptionException
    • getStringList

      public static String[] getStringList(org.apache.commons.cli.CommandLine line, String optionName, String[] defaultValue) throws InvalidOptionException
      Parse option from command line to read string list. Values could be specified as comma-separated argument of option or file name. To pass file name as source of string list use @ prefix for option value. Examples:

      -<option> "value1,value2,value3"

      -<option> "@source_file_name"

      Parameters:
      line - parsed command line
      optionName - option name
      defaultValue - default value. If default value is null - IllegalArgumentException will be thrown if option is not set
      Returns:
      string list parsed from argument or read from external file
      Throws:
      InvalidOptionException
    • getObjectList

      public static <T> T[] getObjectList(org.apache.commons.cli.CommandLine line, String optionName, T[] defaultValue, Function<String,T> parser, IntFunction<T[]> arrayGenerator) throws InvalidOptionException
      Parse option from command line to read list of custom objects. Values could be specified as comma-separated argument of option or file name. To pass file name as source of string list use @ prefix for option value. Examples:

      -<option> "value1,value2,value3"

      -<option> "@source_file_name"

      Values are parsed by parser function and arrayGenerator should provide correct result array for storing values.

      Parameters:
      line - parsed command line
      optionName - option name
      defaultValue - default value. If default value is null - IllegalArgumentException will be thrown if option is not set
      parser - string-to-object parser
      arrayGenerator - result array generator
      Returns:
      string list parsed from argument or read from external file
      Throws:
      InvalidOptionException
    • getIntOption

      public static int getIntOption(org.apache.commons.cli.CommandLine line, String optionName, String name) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getIntOption

      public static int getIntOption(org.apache.commons.cli.CommandLine line, String optionName, Integer defVal, String valueName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getIntOption

      public static int getIntOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number,Function<String,String>> valueChecker, Integer defVal, String valueName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getLongOption

      public static long getLongOption(org.apache.commons.cli.CommandLine line, String optionName, String name) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getLongOption

      public static long getLongOption(org.apache.commons.cli.CommandLine line, String optionName, Long defVal, String valueName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getLongOption

      public static long getLongOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number,Function<String,String>> valueTester, Long defVal, String valueName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getAmountOption

      public static long getAmountOption(org.apache.commons.cli.CommandLine line, String optionName, String name)
    • getAmountOption

      public static long getAmountOption(org.apache.commons.cli.CommandLine line, String optionName, Long defVal, String valueName)
    • getAmountOption

      public static long getAmountOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number,Function<String,String>> valueTester, Long defVal, String valueName)
    • getDoubleOption

      public static double getDoubleOption(org.apache.commons.cli.CommandLine line, String optionName, String name) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getDoubleOption

      public static double getDoubleOption(org.apache.commons.cli.CommandLine line, String optionName, Double defVal, String valueName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getDoubleOption

      public static double getDoubleOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number,Double> valueChecker, Double defVal, String valueName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • getNumericOption

      public static <T extends Number> T getNumericOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number,T> fieldExtractor, Function<? super T,Function<String,String>> valueTester, T defVal, String valueName) throws org.apache.commons.cli.ParseException
      Throws:
      org.apache.commons.cli.ParseException
    • parseCommandLine

      public static org.apache.commons.cli.CommandLine parseCommandLine(String[] args, org.apache.commons.cli.Options options, String cmdLineSyntax, String description, String... requiredAnyOpt)
    • parseCommandLine

      public static org.apache.commons.cli.CommandLine parseCommandLine(String[] args, boolean showHelpWithoutArgs, org.apache.commons.cli.Options options, String cmdLineSyntax, String description, String... requiredAnyOpt)
    • getStringsAsSet

      public static Set<String> getStringsAsSet(org.apache.commons.cli.CommandLine cmd, String opt)
    • parseSize

      public static long parseSize(String str) throws NumberFormatException
      Throws:
      NumberFormatException