Package org.xblackcat.sjpu.cli
Class OptionUtils
java.lang.Object
org.xblackcat.sjpu.cli.OptionUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionChecker for value to be positive, zero or -1Checker for positive valuestatic Function<String,LocalDateTime> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longgetAmountOption(org.apache.commons.cli.CommandLine line, String optionName, Long defVal, String valueName) static longgetAmountOption(org.apache.commons.cli.CommandLine line, String optionName, String name) static longgetAmountOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number, Function<String, String>> valueTester, Long defVal, String valueName) getBounds(org.apache.commons.cli.CommandLine line, String optionName, String description, int defaultLowerBound, int defaultUpperBound) 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) 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) static doublegetDoubleOption(org.apache.commons.cli.CommandLine line, String optionName, Double defVal, String valueName) static doublegetDoubleOption(org.apache.commons.cli.CommandLine line, String optionName, String name) static doublegetDoubleOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number, Double> valueChecker, Double defVal, String valueName) static intgetIntOption(org.apache.commons.cli.CommandLine line, String optionName, Integer defVal, String valueName) static intgetIntOption(org.apache.commons.cli.CommandLine line, String optionName, String name) static intgetIntOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number, Function<String, String>> valueChecker, Integer defVal, String valueName) static longgetLongOption(org.apache.commons.cli.CommandLine line, String optionName, Long defVal, String valueName) static longgetLongOption(org.apache.commons.cli.CommandLine line, String optionName, String name) static longgetLongOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number, Function<String, String>> valueTester, Long defVal, String valueName) static <T extends Number>
TgetNumericOption(org.apache.commons.cli.CommandLine line, String optionName, Function<Number, T> fieldExtractor, Function<? super T, Function<String, String>> valueTester, T defVal, String valueName) static <T> T[]getObjectList(org.apache.commons.cli.CommandLine line, String optionName, T[] defaultValue, Function<String, T> parser, IntFunction<T[]> arrayGenerator) Parse option from command line to read list of custom objects.static OutputStreamgetOutputStream(org.apache.commons.cli.CommandLine line, String fileNameOption, String gzipOption) static PrintStreamgetPrintStream(org.apache.commons.cli.CommandLine line, boolean stdOutAsDefault, String fileOptionName) static PrintStreamgetPrintStream(org.apache.commons.cli.CommandLine line, String fileOptionName) static BufferedReaderstatic String[]getStringList(org.apache.commons.cli.CommandLine line, String optionName) Parse option from command line to read string list.static String[]getStringList(org.apache.commons.cli.CommandLine line, String optionName, String[] defaultValue) Parse option from command line to read string list.getStringsAsSet(org.apache.commons.cli.CommandLine cmd, String opt) static org.apache.commons.cli.CommandLineparseCommandLine(String[] args, boolean showHelpWithoutArgs, org.apache.commons.cli.Options options, String cmdLineSyntax, String description, String... requiredAnyOpt) static org.apache.commons.cli.CommandLineparseCommandLine(String[] args, org.apache.commons.cli.Options options, String cmdLineSyntax, String description, String... requiredAnyOpt) static LogPrintStreamparseProgressOutputStream(org.apache.commons.cli.CommandLine line, String optionName) static longstatic VerbosityparseVerbosity(org.apache.commons.cli.CommandLine cmd)
-
Field Details
-
POSITIVE_VALUE_CHECK
Checker for positive value -
LIMIT_VALUE_CHECK
Checker for value to be positive, zero or -1 -
ANY_VALUE_CHECK
-
PERCENT_VALUE_CHECK
-
TO_TIME_PERIOD_BOUND_PARSER
-
TO_DURATION_BOUND_PARSER
-
-
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
-
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 lineoptionName- 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 lineoptionName- option namedefaultValue- 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 InvalidOptionExceptionParse 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 lineoptionName- option namedefaultValue- default value. If default value is null - IllegalArgumentException will be thrown if option is not setparser- string-to-object parserarrayGenerator- 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, throws org.apache.commons.cli.ParseExceptionString>> valueChecker, Integer defVal, String valueName) - 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, throws org.apache.commons.cli.ParseExceptionString>> valueTester, Long defVal, String valueName) - Throws:
org.apache.commons.cli.ParseException
-
getAmountOption
-
getAmountOption
-
getAmountOption
-
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, throws org.apache.commons.cli.ParseExceptionFunction<String, String>> valueTester, T defVal, String valueName) - Throws:
org.apache.commons.cli.ParseException
-
parseCommandLine
-
parseCommandLine
-
getStringsAsSet
-
parseSize
- Throws:
NumberFormatException
-