Klasse CommandLine
CmdArgOptions.
Example of working with a command-line with two options and a custom exception type:
CommandLine commandLine = new CommandLine()
.setExceptionType(MyApplicationException.class)
.addOption(Option.builder(String.class)
.name("req1")
.required(true)
.defaultValue("default")
.build())
.addOption(Option.builder()
.name("opt1")
.required(false)
.build())
.parse();
- Seit:
- 1.0.0 - 2022-04-29
- Autor:
- David M., Markus S.
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibunggetArg(char _optionName) Returns an option value using the options short name.<T> TReturns an option value using the options short name and converting the value to the given type.<T> TReturns an option value using the options short name and converting the value to the given type.<T> TgetArg(CmdArgOption<T> _option) Returns the value associated with argument option.<T> TgetArg(CmdArgOption<T> _option, T _default) Returns the value associated with argument option.getArg(CharSequence _optionName) Returns an option value using the options name.<T> TgetArg(CharSequence _optionName, Class<T> _type) Returns an option value using the options name and converting the value to the given type.<T> TgetArg(CharSequence _optionName, Class<T> _type, T _default) Returns an option value using the options name and converting the value to the given type.intgetArgCount(CmdArgOption<?> _option) Returns the number of occurrences of the given option.<T> List<T> Returns all option values using the options short name and converting the values to the given type.<T> List<T> getArgs(CmdArgOption<T> _option) Returns the value associated with argument option.<T> List<T> getArgs(CmdArgOption<T> _option, T _default) Returns the value associated with argument option.<T> List<T> getArgs(CharSequence _optionName, Class<T> _type) Returns all option values using the options name and converting the values to the given type.booleanhasArg(char _arg) Checks if the given option was at least used once in the command line.booleanhasArg(CmdArgOption<?> _option) Checks if the given option was at least used once in the command line.booleanChecks if the given option was at least used once in the command line.Parses the given arguments.protected CommandLineself()Reference to ourselves for chaining.Von Klasse geerbte Methoden com.github.hypfvieh.cli.parser.AbstractBaseCommandLine
addOption, addOptions, getArgumentHelp, getDupArgs, getExceptionType, getKnownArgs, getLogger, getLongOptPattern, getLongOptPrefix, getOption, getOptions, getShortOptPattern, getShortOptPrefix, getUnknownArgs, getUnknownTokens, getUsage, hasArg, hasOption, hasOption, isFailOnDupArg, isFailOnUnknownArg, isFailOnUnknownToken, isParsed, logResults, printUsage, printUsage, registerConverter, setParsed, withExceptionType, withFailOnDupArg, withFailOnUnknownArg, withFailOnUnknownToken, withHelpFormatter, withLongOptPrefix, withShortOptPrefix, withUsageFormatter
-
Konstruktordetails
-
CommandLine
public CommandLine()
-
-
Methodendetails
-
self
Reference to ourselves for chaining.- Angegeben von:
selfin KlasseAbstractBaseCommandLine<CommandLine>- Gibt zurück:
- this
-
parse
Parses the given arguments.- Parameter:
_args- arguments to read- Gibt zurück:
- this
-
getArg
Returns the value associated with argument option.If no value is present, the default value of that option is returned (and might by
null).
If the option does not support values or option was not set, null is returned.
If the option is a repeatable option, the value of the first occurrence is returned.- Typparameter:
T- type of option value- Parameter:
_option- option- Gibt zurück:
- value, maybe
null
-
getArg
Returns the value associated with argument option.If no value is present, the given default value is used.
If the given default is alsonull, the default of that option is returned (and might bynull). If the option does not support values or if the option was not set,nullis returned.
- Typparameter:
T- type of option value- Parameter:
_option- option_default- default to use when no value present (overrides default specified in option)- Gibt zurück:
- value, maybe
null
-
getArgs
Returns the value associated with argument option.If no value is present, the default value of that option is returned (and might by
null). If the option does not support values or if the option was not set,nullis returned.
- Typparameter:
T- type of option value- Parameter:
_option- option- Gibt zurück:
- List, maybe empty or
null
-
getArgs
Returns the value associated with argument option.If no value is present, the given default value is used.
If the given default is alsonull, the default of that option is returned (and might bynull). If the option does not support values or if the option was not set,nullis returned.
- Typparameter:
T- type of option value- Parameter:
_option- option_default- default to use when no value present (overrides default specified in option)- Gibt zurück:
- List, maybe empty or
null
-
getArg
Returns an option value using the options name.- Parameter:
_optionName- option name- Gibt zurück:
- value or null if option has no value
- Löst aus:
RuntimeException- if option is unknown or command line was not parsed before
-
getArg
Returns an option value using the options short name.- Parameter:
_optionName- option short name- Gibt zurück:
- value or null if option has no value
- Löst aus:
RuntimeException- if option is unknown or command line was not parsed before
-
getArg
Returns an option value using the options name and converting the value to the given type.
Will use the configured converter to convert the value.
If given type is not the same as the type specified inCmdArgOptionan exception is thrown.- Typparameter:
T- data type of argument- Parameter:
_optionName- option short name_type- expected value type_default- default to use if option not set (and not required)- Gibt zurück:
- value or null if option has no value
- Löst aus:
RuntimeException- if option is unknown or command line was not parsedRuntimeException- if type class is not the type defined inCmdArgOption- Seit:
- 1.0.1 - 2022-05-24
-
getArg
Returns an option value using the options name and converting the value to the given type.
Will use the configured converter to convert the value.
If given type is not the same as the type specified inCmdArgOptionan exception is thrown.- Typparameter:
T- data type of argument- Parameter:
_optionName- option short name_type- expected value type- Gibt zurück:
- value or null if option has no value or was not set
- Löst aus:
RuntimeException- if option is unknown or command line was not parsedRuntimeException- if type class is not the type defined inCmdArgOption- Seit:
- 1.0.1 - 2022-05-24
-
getArg
Returns an option value using the options short name and converting the value to the given type.
Will use the configured converter to convert the value.
If given type is not the same as the type specified inCmdArgOptionan exception is thrown.- Typparameter:
T- type of option value- Parameter:
_optionName- option short name_type- expected value type- Gibt zurück:
- value or null if option has no value
- Löst aus:
RuntimeException- if option is unknown or command line was not parsedRuntimeException- if type class is not the type defined inCmdArgOption- Seit:
- 1.0.1 - 2022-05-24
-
getArg
Returns an option value using the options short name and converting the value to the given type.
Will use the configured converter to convert the value.
If given type is not the same as the type specified inCmdArgOptionan exception is thrown.- Typparameter:
T- data type of argument- Parameter:
_optionName- option short name_type- expected value type_default- default to use if option not set (and not required)- Gibt zurück:
- value or null if option has no value
- Löst aus:
RuntimeException- if option is unknown or command line was not parsedRuntimeException- if type class is not the type defined inCmdArgOption- Seit:
- 1.0.1 - 2022-05-24
-
getArgs
Returns all option values using the options name and converting the values to the given type.
Will use the configured converter to convert the value.
If given type is not the same as the type specified inCmdArgOptionan exception is thrown.- Typparameter:
T- data type of argument- Parameter:
_optionName- option short name_type- expected value type- Gibt zurück:
- value or null if option has no value
- Löst aus:
RuntimeException- if option is unknown or command line was not parsedRuntimeException- if type class is not the type defined inCmdArgOption- Seit:
- 1.0.1 - 2022-05-24
-
getArgs
Returns all option values using the options short name and converting the values to the given type.
Will use the configured converter to convert the value.
If given type is not the same as the type specified inCmdArgOptionan exception is thrown.- Typparameter:
T- data type of argument- Parameter:
_optionName- option short name_type- expected value type- Gibt zurück:
- value or null if option has no value
- Löst aus:
RuntimeException- if option is unknown or command line was not parsedRuntimeException- if type class is not the type defined inCmdArgOption- Seit:
- 1.0.1 - 2022-05-24
-
hasArg
Checks if the given option was at least used once in the command line.- Parameter:
_option- option to check- Gibt zurück:
- true if it was used at least once, false otherwise
-
hasArg
Checks if the given option was at least used once in the command line.Will only check if the string argument was found as option name, will not check with short name.
- Parameter:
_arg- option to check- Gibt zurück:
- true if it was used at least once, false otherwise
-
hasArg
public boolean hasArg(char _arg) Checks if the given option was at least used once in the command line.Will only check if the char argument was found as short option.
- Parameter:
_arg- option to check- Gibt zurück:
- true if it was used at least once, false otherwise
-
getArgCount
Returns the number of occurrences of the given option.If the option was never set, 0 is returned.
- Parameter:
_option- option- Gibt zurück:
- number of occurrences
-