Class AbstractMainSupport<A,R>
- Type Parameters:
A- MainArgs type.R- Returned type.
The purpose is to force the adoption of a common pattern for such classes.
Some options are automatically defined and handled:
- help: if passed, help is printed and program is exited.
- version: if passed, version is printed and program is exited.
OverridegetVersion()to define version. - args-list <FILE>: if passed, command line arguments
are read from the designated file and added to other command line arguments.
This is useful when command line is too long.
OverrideaddArgsFileOption(Options)to force its presence.
The file must contains one argument (option of value) per line.
A line that is empty or starts with any number of white spaces followed by '#' and any other characters is a ignored.
Exemple:
# (ignored)
--option1
--option2
--option3
value1
value2
# (ignored)
value3
- Author:
- Damien Carbonne
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic interfaceAbstractMainSupport.Maskable<E extends Enum<E>>static interfaceInterface used to check the validity of an option value. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final AbstractMainSupport.ValueChecker<File>Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing directory.static final AbstractMainSupport.ValueChecker<File>Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing file.static final AbstractMainSupport.ValueChecker<File>Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing file or directory.static final AbstractMainSupport.ValueChecker<File>Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing directory, or isnull.static final AbstractMainSupport.ValueChecker<File>Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing file, or isnull.static final AbstractMainSupport.ValueChecker<File>Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing file or directory, or isnull.static final AbstractMainSupport.ValueChecker<Object>Implementation ofAbstractMainSupport.ValueCheckerthat always accepts and returns the input value.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMainSupport(Class<?> mainClass, org.apache.logging.log4j.Logger logger) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanaddArgsFileOption(org.apache.commons.cli.Options options) ReturnstrueifARGS_FILEoption must be added.static <E extends Enum<E> & OptionEnum>
voidaddGroupedNoArgOptions(org.apache.commons.cli.Options options, Class<E> enumClass, boolean required) static <E extends Enum<E> & OptionEnum>
voidaddNoArgOptions(org.apache.commons.cli.Options options, Class<E> enumClass) protected abstract voidaddSpecificOptions(org.apache.commons.cli.Options options) Creates specific options and add them to an options collection.protected voidaddStandardOptions(org.apache.commons.cli.Options options) protected abstract Aanalyze(org.apache.commons.cli.CommandLine cl) Analyzes the command line.protected org.apache.commons.cli.OptionsCreates options, add standard and specific options and returns them.static <E extends Enum<E> & OptionEnum>
org.apache.commons.cli.OptionGroupcreateGroup(org.apache.commons.cli.Options options, boolean required, E... values) static org.apache.commons.cli.OptionGroupcreateGroup(org.apache.commons.cli.Options options, boolean required, String... opts) static org.apache.commons.cli.OptionGroupcreateGroup(org.apache.commons.cli.Options options, boolean required, org.apache.commons.cli.Option... opts) static <E extends Enum<E> & OptionEnum>
org.apache.commons.cli.OptionGroupcreateGroup(org.apache.commons.cli.Options options, E... values) static org.apache.commons.cli.OptionGroupcreateGroup(org.apache.commons.cli.Options options, String... opts) static org.apache.commons.cli.OptionGroupcreateGroup(org.apache.commons.cli.Options options, org.apache.commons.cli.Option... opts) protected abstract RExecutes the main program.static voidfillValues(org.apache.commons.cli.CommandLine cl, String opt, Collection<String> values) Adds the values of an option to a String collection.static <T> voidfillValues(org.apache.commons.cli.CommandLine cl, String opt, Collection<T> values, Function<String, T> converter) Adds option values to a collection, after converting them.static <T> voidfillValues(org.apache.commons.cli.CommandLine cl, String opt, Collection<T> values, Function<String, T> converter, AbstractMainSupport.ValueChecker<? super T> checker) Adds option values to a collection, after converting and checking them.protected AbstractMainSupport.ExceptionThrowingprotected StringReturns the help footer.protected StringReturns the help header.final org.apache.logging.log4j.Loggerfinal Class<?>static intgetNumberOfParts(String s, String sep) protected org.apache.commons.cli.Optionsstatic FilegetOrCreateValueAsDirectory(org.apache.commons.cli.CommandLine cl, String opt) Returns an option value as a Directory, and tries to create it if it does not exist.static FilegetOrCreateValueAsDirectory(org.apache.commons.cli.CommandLine cl, String opt, File def) Returns an option value as a Directory, and tries to create it if it does not exist.static Stringstatic Stringfinal PathReturns the reference directory as aPath.final MainResultstatic <T> TReturns the conversion of an option value to a type, or a default value.static <T> TgetValue(org.apache.commons.cli.CommandLine cl, String opt, T def, Function<String, T> converter, AbstractMainSupport.ValueChecker<? super T> checker) Returns the checked conversion of an option value to a type, or a checked default value.static bytegetValueAsByte(org.apache.commons.cli.CommandLine cl, String opt, byte def) Returns an option value as a byte.static BytegetValueAsByte(org.apache.commons.cli.CommandLine cl, String opt, Byte def) static chargetValueAsChar(org.apache.commons.cli.CommandLine cl, String opt, char def) Returns an option value as a char.static CharactergetValueAsChar(org.apache.commons.cli.CommandLine cl, String opt, Character def) static CharsetgetValueAsCharset(org.apache.commons.cli.CommandLine cl, String opt) static CharsetgetValueAsCharset(org.apache.commons.cli.CommandLine cl, String opt, Charset def) Returns an option value as a Charset.static doublegetValueAsDouble(org.apache.commons.cli.CommandLine cl, String opt, double def) Returns an option value as a double.static DoublegetValueAsDouble(org.apache.commons.cli.CommandLine cl, String opt, Double def) static <E extends Enum<E>>
EgetValueAsEnum(org.apache.commons.cli.CommandLine cl, String opt, Class<E> enumClass, E def) Returns an option value as a enum.static FilegetValueAsFile(org.apache.commons.cli.CommandLine cl, String opt) Returns an option value as a File.static FilegetValueAsFile(org.apache.commons.cli.CommandLine cl, String opt, AbstractMainSupport.ValueChecker<? super File> checker) Returns an option as a File.static FilegetValueAsFile(org.apache.commons.cli.CommandLine cl, String opt, File def) Returns an option value as a File.static FilegetValueAsFile(org.apache.commons.cli.CommandLine cl, String opt, File def, AbstractMainSupport.ValueChecker<? super File> checker) Returns an option as a File.static floatgetValueAsFloat(org.apache.commons.cli.CommandLine cl, String opt, float def) Returns an option value as a float.static FloatgetValueAsFloat(org.apache.commons.cli.CommandLine cl, String opt, Float def) static intgetValueAsInt(org.apache.commons.cli.CommandLine cl, String opt, int def) Returns an option value as an int.static IntegergetValueAsInt(org.apache.commons.cli.CommandLine cl, String opt, Integer def) static longgetValueAsLong(org.apache.commons.cli.CommandLine cl, String opt, long def) Returns an option value as a long.static LonggetValueAsLong(org.apache.commons.cli.CommandLine cl, String opt, Long def) getValueAsResolvedFile(org.apache.commons.cli.CommandLine cl, String opt) getValueAsResolvedFile(org.apache.commons.cli.CommandLine cl, String opt, AbstractMainSupport.ValueChecker<? super File> checker) Returns an option as a resolved file.getValueAsResolvedFile(org.apache.commons.cli.CommandLine cl, String opt, File def) getValueAsResolvedFile(org.apache.commons.cli.CommandLine cl, String opt, File def, AbstractMainSupport.ValueChecker<? super File> checker) Returns an option as a resolved file.static shortgetValueAsShort(org.apache.commons.cli.CommandLine cl, String opt, short def) Returns an option value as a short.static ShortgetValueAsShort(org.apache.commons.cli.CommandLine cl, String opt, Short def) static StringgetValueAsString(org.apache.commons.cli.CommandLine cl, String opt, String def) Returns an option value as a string.static URLgetValueAsURL(org.apache.commons.cli.CommandLine cl, String opt) static URLgetValueAsURL(org.apache.commons.cli.CommandLine cl, String opt, URL def) Returns an option value as an URL.Returns the values of an option as a String List.static <T> List<T>Returns the values of an option, converted, as a List.static <T> List<T>getValues(org.apache.commons.cli.CommandLine cl, String opt, Function<String, T> converter, AbstractMainSupport.ValueChecker<? super T> checker) Returns the values of an option, converted and checked, as a List.protected StringReturns the version.final booleanDefault main program.protected voidprotected void(package private) static StringRemoves the comment part of a string.resolveToReferencePath(File file) static <E extends Enum<E> & OptionEnum>
voidsetMask(org.apache.commons.cli.CommandLine cl, Class<E> enumClass, AbstractMainSupport.Maskable<E> maskable)
-
Field Details
-
DEFAULT_PARTS_SEPARATOR
- See Also:
-
ARGS_FILE
- See Also:
-
ARGS_FILE_CHARSET
- See Also:
-
CHARSET
- See Also:
-
DRIVER
- See Also:
-
HELP
- See Also:
-
HELP_WIDTH
- See Also:
-
INPUT
- See Also:
-
INPUT_DIR
- See Also:
-
OUTPUT
- See Also:
-
OUTPUT_DIR
- See Also:
-
PASSWORD
- See Also:
-
PATH
- See Also:
-
PREFIX
- See Also:
-
TMP_DIR
- See Also:
-
URL
- See Also:
-
USER
- See Also:
-
VERSION
- See Also:
-
IS_TRUE
Implementation ofAbstractMainSupport.ValueCheckerthat always accepts and returns the input value. -
IS_FILE
Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing file.Note: It will fail when value is
null. -
IS_DIRECTORY
Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing directory.Note: It will fail when value is
null. -
IS_FILE_OR_DIRECTORY
Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing file or directory.Note: It will fail when value is
null. -
IS_NULL_OR_FILE
Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing file, or isnull.Note: It will succeed when value is
null. -
IS_NULL_OR_DIRECTORY
Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing directory, or isnull.Note: It will succeed when value is
null. -
IS_NULL_OR_FILE_OR_DIRECTORY
Implementation ofAbstractMainSupport.ValueCheckerchecking that the value is an existing file or directory, or isnull.Note: It will succeed when value is
null.
-
-
Constructor Details
-
AbstractMainSupport
-
-
Method Details
-
addArgsFileOption
protected boolean addArgsFileOption(org.apache.commons.cli.Options options) ReturnstrueifARGS_FILEoption must be added.The default implementation returns
trueif one option contains multiple values.- Parameters:
options- The options.- Returns:
trueifARGS_FILEoption must be added.
-
addStandardOptions
protected void addStandardOptions(org.apache.commons.cli.Options options) -
getMainClass
-
getLogger
public final org.apache.logging.log4j.Logger getLogger() -
getVersion
Returns the version.If
nullis returned (default implementation), no version option is available.- Returns:
- The version.
-
getHelpHeader
Returns the help header.If
nullis returned (default implementation), no help header is printed.- Returns:
- The help header.
-
addSpecificOptions
protected abstract void addSpecificOptions(org.apache.commons.cli.Options options) Creates specific options and add them to an options collection.The standard options must not be added.
- Parameters:
options- The options.
-
analyze
protected abstract A analyze(org.apache.commons.cli.CommandLine cl) throws org.apache.commons.cli.ParseException Analyzes the command line.These options are already handled:
- help
- version
- args-file
- Parameters:
cl- The command line.- Returns:
- A MainARgs instance.
- Throws:
org.apache.commons.cli.ParseException- When command line parsing has a problem.
-
execute
Executes the main program.- Parameters:
margs- The main arguments.- Returns:
- The optional result.
- Throws:
Exception- When program has a problem.
-
addNoArgOptions
public static <E extends Enum<E> & OptionEnum> void addNoArgOptions(org.apache.commons.cli.Options options, Class<E> enumClass) -
addGroupedNoArgOptions
public static <E extends Enum<E> & OptionEnum> void addGroupedNoArgOptions(org.apache.commons.cli.Options options, Class<E> enumClass, boolean required) -
createGroup
public static org.apache.commons.cli.OptionGroup createGroup(org.apache.commons.cli.Options options, boolean required, String... opts) -
createGroup
public static org.apache.commons.cli.OptionGroup createGroup(org.apache.commons.cli.Options options, String... opts) -
createGroup
public static org.apache.commons.cli.OptionGroup createGroup(org.apache.commons.cli.Options options, boolean required, org.apache.commons.cli.Option... opts) -
createGroup
public static org.apache.commons.cli.OptionGroup createGroup(org.apache.commons.cli.Options options, org.apache.commons.cli.Option... opts) -
createGroup
@SafeVarargs public static <E extends Enum<E> & OptionEnum> org.apache.commons.cli.OptionGroup createGroup(org.apache.commons.cli.Options options, boolean required, E... values) -
createGroup
@SafeVarargs public static <E extends Enum<E> & OptionEnum> org.apache.commons.cli.OptionGroup createGroup(org.apache.commons.cli.Options options, E... values) -
setMask
public static <E extends Enum<E> & OptionEnum> void setMask(org.apache.commons.cli.CommandLine cl, Class<E> enumClass, AbstractMainSupport.Maskable<E> maskable) -
removeComments
Removes the comment part of a string.A comment starts with any number of white spaces followed by '#'
- Parameters:
s- The string- Returns:
swith comments removed.
-
main
Default main program.This does the following things:
- Build options.
- Parse the command line strings and creates a CommandLine instance.
- Analyze the CommandLine instance and create a MainArgs instance.
- Calls execute with the MainArgs instance.
- Parameters:
args- The command line arguments.- Returns:
- The optional result.
-
getResult
-
hasArgsFile
public final boolean hasArgsFile()- Returns:
trueif an args file was passed and analyzed.
This shall not be called beforemain(String[])is called.
-
getReferencePath
Returns the reference directory as aPath.It is the directory that contains args-file, if this option has been used, or the current directory otherwise.
- Returns:
- The reference directory.
-
resolveToReferencePath
-
getExceptionThrowing
- Returns:
- When exceptions shall be thrown.
Default to
AbstractMainSupport.ExceptionThrowing.EXECUTION.
-
buildOptions
protected org.apache.commons.cli.Options buildOptions()Creates options, add standard and specific options and returns them.- Returns:
- The options.
-
getOptionsAsOptional
protected org.apache.commons.cli.Options getOptionsAsOptional()- Returns:
- Build all options and make them optional.
-
printHelp
-
printVersion
protected void printVersion() -
getValue
public static <T> T getValue(org.apache.commons.cli.CommandLine cl, String opt, T def, Function<String, T> converter, AbstractMainSupport.ValueChecker<? super T> checker) throws org.apache.commons.cli.ParseExceptionReturns the checked conversion of an option value to a type, or a checked default value.- If option is present:
- tries to convert the option value to
<T>usingconverter.
If conversion fails, aParseExceptionis thrown. - then checks the conversion result using
checker.
If check fails, aParseExceptionis thrown. - then returns the conversion result.
- tries to convert the option value to
- If option is absent:
- checks the
defusingchecker.
If check fails, aParseExceptionis thrown. - returns
def.
- checks the
checkershould acceptdef, whether it isnullor not.- Type Parameters:
T- The returned value type.- Parameters:
cl- The command line.opt- The option name.def- Default value. MAY BE null.converter- Function used to convert a String to the expected type.checker- The value checker.- Returns:
- The checked conversion of the option value to
<T>type or checkeddef. - Throws:
org.apache.commons.cli.ParseException- If option value could not be converted, or check failed.
- If option is present:
-
getValue
public static <T> T getValue(org.apache.commons.cli.CommandLine cl, String opt, T def, Function<String, T> converter) throws org.apache.commons.cli.ParseExceptionReturns the conversion of an option value to a type, or a default value.- If the option is present:
- tries to convert the option value to
<T>usingconverter.
If conversion fails, aParseExceptionis thrown. - then returns the conversion result.
- tries to convert the option value to
- If the option is absent: returns
def.
getValue(cl, opt, def, converter, IS_TRUE).- Type Parameters:
T- The returned value type.- Parameters:
cl- The command line.opt- The option name.def- Default value. MAY BE null.converter- Function used to convert a String to the expected type.- Returns:
- The conversion of the option value to
<T>type ordef. - Throws:
org.apache.commons.cli.ParseException- If option value could not be converted.
- If the option is present:
-
fillValues
public static <T> void fillValues(org.apache.commons.cli.CommandLine cl, String opt, Collection<T> values, Function<String, T> converter, AbstractMainSupport.ValueChecker<? super T> checker) throws org.apache.commons.cli.ParseExceptionAdds option values to a collection, after converting and checking them.- Type Parameters:
T- The value type.- Parameters:
cl- The command line.opt- The option name.values- The collection of values.converter- Function used to convert a String to the expected type.checker- The value checker.- Throws:
org.apache.commons.cli.ParseException- When a conversion or check failed.
-
fillValues
public static <T> void fillValues(org.apache.commons.cli.CommandLine cl, String opt, Collection<T> values, Function<String, T> converter) throws org.apache.commons.cli.ParseExceptionAdds option values to a collection, after converting them.Note: this is equivalent to calling
fillValues(cl, opt, values, converter, IS_TRUE).- Type Parameters:
T- The value type.- Parameters:
cl- The command line.opt- The option name.values- The collection of values.converter- Function used to convert a String to the expected type.- Throws:
org.apache.commons.cli.ParseException- When a conversion failed.
-
getValues
public static <T> List<T> getValues(org.apache.commons.cli.CommandLine cl, String opt, Function<String, T> converter, AbstractMainSupport.ValueChecker<? super T> checker) throws org.apache.commons.cli.ParseExceptionReturns the values of an option, converted and checked, as a List.- Type Parameters:
T- The value type.- Parameters:
cl- The command line.opt- The option name.converter- Function used to convert a String to the expected type.checker- The value checker.- Returns:
- A List of values.
- Throws:
org.apache.commons.cli.ParseException- When a conversion or check failed.
-
getValues
public static <T> List<T> getValues(org.apache.commons.cli.CommandLine cl, String opt, Function<String, T> converter) throws org.apache.commons.cli.ParseExceptionReturns the values of an option, converted, as a List.Note: this is equivalent to calling
getValues(cl, opt, converter, IS_TRUE).- Type Parameters:
T- The value type.- Parameters:
cl- The command line.opt- The option name.converter- Function used to convert a String to the expected type.- Returns:
- A List of values.
- Throws:
org.apache.commons.cli.ParseException- When a conversion failed.
-
fillValues
public static void fillValues(org.apache.commons.cli.CommandLine cl, String opt, Collection<String> values) Adds the values of an option to a String collection.- Parameters:
cl- The command line.opt- The option name.values- The collection of values.
-
getValues
Returns the values of an option as a String List.- Parameters:
cl- The command line.opt- The option name.- Returns:
- The values of option
optas a String List.
-
getValueAsResolvedFile
public File getValueAsResolvedFile(org.apache.commons.cli.CommandLine cl, String opt, File def, AbstractMainSupport.ValueChecker<? super File> checker) throws org.apache.commons.cli.ParseException Returns an option as a resolved file.- Converts option to a File or use default value.
- If this result is
null, checks it and returnsnull. - Otherwise, resolve this result using
getReferencePath(), checks the resolution and returns it.
- Parameters:
cl- The command line.opt- The option name.def- The default value.checker- The checker.- Returns:
- The checked resolved option value or checked default value as a file.
- Throws:
org.apache.commons.cli.ParseException- When conversion failed or check failed.
-
getValueAsResolvedFile
public File getValueAsResolvedFile(org.apache.commons.cli.CommandLine cl, String opt, AbstractMainSupport.ValueChecker<? super File> checker) throws org.apache.commons.cli.ParseException Returns an option as a resolved file.Note: this is equivalent to
getValueAsResolvedFile(cl, opt, null, checker).- Parameters:
cl- The command line.opt- The option name.checker- The checker.- Returns:
- The checked resolved option value or checked
nullas a file. - Throws:
org.apache.commons.cli.ParseException- When conversion failed or check failed.
-
getValueAsResolvedFile
public File getValueAsResolvedFile(org.apache.commons.cli.CommandLine cl, String opt, File def) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsResolvedFile
public File getValueAsResolvedFile(org.apache.commons.cli.CommandLine cl, String opt) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsFile
public static File getValueAsFile(org.apache.commons.cli.CommandLine cl, String opt, File def, AbstractMainSupport.ValueChecker<? super File> checker) throws org.apache.commons.cli.ParseException Returns an option as a File.Note: if option is optional,
checkershould acceptdef, whether it isnullor not.- Parameters:
cl- The command line.opt- The option name.def- The default value.checker- The checker.- Returns:
- The checked conversion of option to a File or the checked default value.
- Throws:
org.apache.commons.cli.ParseException- If option value could not be converted to a File, or check failed.
-
getValueAsFile
public static File getValueAsFile(org.apache.commons.cli.CommandLine cl, String opt, AbstractMainSupport.ValueChecker<? super File> checker) throws org.apache.commons.cli.ParseException Returns an option as a File.Note: if option is optional,
checkershould acceptnull.Note: this is equivalent to
getValueAsFile(cl, opt, null, checker).- Parameters:
cl- The command line.opt- The option name.checker- The checker.- Returns:
- The checked conversion of option to a File or the checked
null. - Throws:
org.apache.commons.cli.ParseException- If option value could not be converted to a File, or check failed.
-
getValueAsFile
public static File getValueAsFile(org.apache.commons.cli.CommandLine cl, String opt, File def) throws org.apache.commons.cli.ParseException Returns an option value as a File.If option is absent, returns a default value.
Result isnullonly when option does not exist and default value isnull.Note: this is equivalent to
getValueAsFile(cl, opt, def, IS_TRUE).- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a File.
- Throws:
org.apache.commons.cli.ParseException- If result could not be produced.
-
getValueAsFile
public static File getValueAsFile(org.apache.commons.cli.CommandLine cl, String opt) throws org.apache.commons.cli.ParseException Returns an option value as a File.If option is absent, returns
null.Note: this is equivalent to
getValueAsFile(cl, opt, null, IS_TRUE).- Parameters:
cl- The command line.opt- The option name.- Returns:
- The option value as a File.
- Throws:
org.apache.commons.cli.ParseException- If result could not be produced.
-
getOrCreateValueAsDirectory
public static File getOrCreateValueAsDirectory(org.apache.commons.cli.CommandLine cl, String opt, File def) throws org.apache.commons.cli.ParseException Returns an option value as a Directory, and tries to create it if it does not exist.- Parameters:
cl- The command line.opt- The option name.def- The default value.- Returns:
- The option value as a Directory, possibly creating it.
- Throws:
org.apache.commons.cli.ParseException- If result could not be produced.
-
getOrCreateValueAsDirectory
public static File getOrCreateValueAsDirectory(org.apache.commons.cli.CommandLine cl, String opt) throws org.apache.commons.cli.ParseException Returns an option value as a Directory, and tries to create it if it does not exist.- Parameters:
cl- The command line.opt- The option name.- Returns:
- The option value as a Directory, possibly creating it.
- Throws:
org.apache.commons.cli.ParseException- If result could not be produced.
-
getValueAsURL
public static URL getValueAsURL(org.apache.commons.cli.CommandLine cl, String opt, URL def) throws org.apache.commons.cli.ParseException Returns an option value as an URL.If option is absent, returns a default value (possibly null).
If option is present and can be converted to an URL, returns this conversion.
Otherwise, raises an exception.- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value or default value.
- Throws:
org.apache.commons.cli.ParseException- If option is present and can not be converted to a valid URL.
-
getValueAsURL
public static URL getValueAsURL(org.apache.commons.cli.CommandLine cl, String opt) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsCharset
public static Charset getValueAsCharset(org.apache.commons.cli.CommandLine cl, String opt, Charset def) throws org.apache.commons.cli.ParseException Returns an option value as a Charset.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a Charset.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as a Charset.
-
getValueAsCharset
public static Charset getValueAsCharset(org.apache.commons.cli.CommandLine cl, String opt) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsString
public static String getValueAsString(org.apache.commons.cli.CommandLine cl, String opt, String def) Returns an option value as a string.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a string.
-
getValueAsChar
public static char getValueAsChar(org.apache.commons.cli.CommandLine cl, String opt, char def) throws org.apache.commons.cli.ParseException Returns an option value as a char.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a char.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as a char.
-
getValueAsChar
public static Character getValueAsChar(org.apache.commons.cli.CommandLine cl, String opt, Character def) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsLong
public static long getValueAsLong(org.apache.commons.cli.CommandLine cl, String opt, long def) throws org.apache.commons.cli.ParseException Returns an option value as a long.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a long.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as a long.
-
getValueAsLong
public static Long getValueAsLong(org.apache.commons.cli.CommandLine cl, String opt, Long def) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsInt
public static int getValueAsInt(org.apache.commons.cli.CommandLine cl, String opt, int def) throws org.apache.commons.cli.ParseException Returns an option value as an int.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as an int.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as an int.
-
getValueAsInt
public static Integer getValueAsInt(org.apache.commons.cli.CommandLine cl, String opt, Integer def) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsShort
public static short getValueAsShort(org.apache.commons.cli.CommandLine cl, String opt, short def) throws org.apache.commons.cli.ParseException Returns an option value as a short.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a short.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as a short.
-
getValueAsShort
public static Short getValueAsShort(org.apache.commons.cli.CommandLine cl, String opt, Short def) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsByte
public static byte getValueAsByte(org.apache.commons.cli.CommandLine cl, String opt, byte def) throws org.apache.commons.cli.ParseException Returns an option value as a byte.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a byte.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as a byte.
-
getValueAsByte
public static Byte getValueAsByte(org.apache.commons.cli.CommandLine cl, String opt, Byte def) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsDouble
public static double getValueAsDouble(org.apache.commons.cli.CommandLine cl, String opt, double def) throws org.apache.commons.cli.ParseException Returns an option value as a double.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a double.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as a double.
-
getValueAsDouble
public static Double getValueAsDouble(org.apache.commons.cli.CommandLine cl, String opt, Double def) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsFloat
public static float getValueAsFloat(org.apache.commons.cli.CommandLine cl, String opt, float def) throws org.apache.commons.cli.ParseException Returns an option value as a float.If option is absent, returns a default value.
- Parameters:
cl- The command line.opt- The option name.def- Default value.- Returns:
- The option value as a float.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as a float.
-
getValueAsFloat
public static Float getValueAsFloat(org.apache.commons.cli.CommandLine cl, String opt, Float def) throws org.apache.commons.cli.ParseException - Throws:
org.apache.commons.cli.ParseException
-
getValueAsEnum
public static <E extends Enum<E>> E getValueAsEnum(org.apache.commons.cli.CommandLine cl, String opt, Class<E> enumClass, E def) throws org.apache.commons.cli.ParseException Returns an option value as a enum.If option is absent, returns a default value.
- Type Parameters:
E- The enum type.- Parameters:
cl- The command line.opt- The option name.enumClass- Enum classdef- Default value.- Returns:
- The option value as an enum.
- Throws:
org.apache.commons.cli.ParseException- If the option value can not be parsed as an enum value.
-
getNumberOfParts
-
getPart
-
getPart
-