Object
CommandOptions
Provides access to command line options. Options have key-value structure.
This class is only relying on Properties
and so it is thread-safe.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds new optionstatic CommandOptions
collectOptions
(CommandOptions.Config config, String[] args) Collect command options from list of arguments.static CommandOptions
collectOptions
(String[] args) Similar tocollectOptions(String[])
except uses defaultCommandOptions.Config
settingsSome options may be optional.getOptionDouble
(String optionName) Some options may be optional.getOptionInt
(String optionName) Some options may be optional.getRequiredOption
(String optionName) If given option is not available it throwsArgumentParsingException
with missing option name.boolean
isOptionTrue
(String optionName) Check if optionName is set to "true": -optionName=truetoString()
-
Constructor Details
-
CommandOptions
- See Also:
-
-
Method Details
-
collectOptions
public static CommandOptions collectOptions(CommandOptions.Config config, String[] args) throws ArgumentParsingException Collect command options from list of arguments. Can be used with main(String[] args)Each option may have zero or one argument.
If option has no argument then it is added with an empty string as a value.
Each option inside args should start from "-", or "--".
Options may accept arguments in one of the following ways: -option arg, -option=arg
When options are collected then leading "-" is removed.
- Throws:
ArgumentParsingException
-
collectOptions
Similar tocollectOptions(String[])
except uses defaultCommandOptions.Config
settings- Throws:
ArgumentParsingException
-
getRequiredOption
If given option is not available it throwsArgumentParsingException
with missing option name.It is recommended to catch
ArgumentParsingException
in the main() function itself and show user usage information.- Throws:
ArgumentParsingException
-
getOption
Some options may be optional. Use this method to obtain them. -
getOptionInt
Some options may be optional. Use this method to obtain them. -
getOptionDouble
Some options may be optional. Use this method to obtain them. -
isOptionTrue
Check if optionName is set to "true": -optionName=true -
addOption
Adds new option -
toString
-