Package com.jenkov.cliargs
Class CliArgs
java.lang.Object
com.jenkov.cliargs.CliArgs
Utility class for parsing command line arguments.
Provides methods to handle switches and their values from command line input.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarg(int index) Retrieves the argument at the specified index.String[]args()Returns the original arguments array.voidParses the given arguments array.switchDoubleValue(String switchName) Retrieves the double value of a switch.switchDoubleValue(String switchName, Double defaultValue) Retrieves the double value of a switch, with a default value.switchLongValue(String switchName) Retrieves the long value of a switch.switchLongValue(String switchName, Long defaultValue) Retrieves the long value of a switch, with a default value.<T> TswitchPojo(Class<T> pojoClass) Creates a POJO instance and fills it with switch values based on its fields.booleanswitchPresent(String switchName) Checks if the specified switch is present in the arguments.switchValue(String switchName) Retrieves the value of a switch.switchValue(String switchName, String defaultValue) Retrieves the value of a switch, with a default value if not found.String[]switchValues(String switchName) Retrieves the array of values for a switch.String[]targets()Returns the array of targets (non-switch arguments).
-
Constructor Details
-
CliArgs
Constructs a CliArgs instance and parses the given arguments.- Parameters:
args- the command line arguments array to parse
-
-
Method Details
-
parse
Parses the given arguments array.- Parameters:
arguments- the arguments to parse
-
args
Returns the original arguments array.- Returns:
- the arguments array
-
arg
Retrieves the argument at the specified index.- Parameters:
index- the index of the argument- Returns:
- the argument at the index
-
switchPresent
Checks if the specified switch is present in the arguments.- Parameters:
switchName- the name of the switch- Returns:
- true if the switch is present, false otherwise
-
switchValue
Retrieves the value of a switch.- Parameters:
switchName- the name of the switch- Returns:
- the switch value or null if not found
-
switchValue
Retrieves the value of a switch, with a default value if not found.- Parameters:
switchName- the name of the switchdefaultValue- the default value to return if switch is not found- Returns:
- the switch value or the default value
-
switchLongValue
Retrieves the long value of a switch.- Parameters:
switchName- the name of the switch- Returns:
- the switch value as Long or null
-
switchLongValue
Retrieves the long value of a switch, with a default value.- Parameters:
switchName- the name of the switchdefaultValue- the default value to return if switch is not found or parsing fails- Returns:
- the switch value as Long or the default value
-
switchDoubleValue
Retrieves the double value of a switch.- Parameters:
switchName- the name of the switch- Returns:
- the switch value as Double or null
-
switchDoubleValue
Retrieves the double value of a switch, with a default value.- Parameters:
switchName- the name of the switchdefaultValue- the default value to return if switch is not found or parsing fails- Returns:
- the switch value as Double or the default value
-
switchValues
Retrieves the array of values for a switch.- Parameters:
switchName- the name of the switch- Returns:
- the array of switch values, or empty array if not found
-
switchPojo
Creates a POJO instance and fills it with switch values based on its fields.- Type Parameters:
T- the type of the POJO- Parameters:
pojoClass- the class of the POJO to create- Returns:
- the instantiated POJO with fields set from switches
- Throws:
RuntimeException- if instantiation or field access fails
-
targets
Returns the array of targets (non-switch arguments).- Returns:
- the array of target arguments
-