- java.lang.Object
-
- com.aoapps.lang.util.GetOpt
-
public final class GetOpt extends Object
General-purpose command line argument processor. Supports options in the "--option=value" format.booleanoptions default to true if no value provided. Also supports a single "--" that is used to separate parameters from non-parameters. All arguments start with -- before the "--" must be valid parameters.- Author:
- AO Industries, Inc.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<String>getArguments(String[] args)Gets all of the non-parameter arguments.static <T> TgetOpt(String[] args, String name, Class<T> type)Gets an argument of the provided type.static <T> Tparse(String value, Class<T> type)Parses a String value to the provided type.
-
-
-
Method Detail
-
parse
public static <T> T parse(String value, Class<T> type)
Parses a String value to the provided type. Values are converted by:- Special handling for primitive types
public static valueOf(String)method- public constructor with single
Stringparameter
-
getOpt
public static <T> T getOpt(String[] args, String name, Class<T> type)
Gets an argument of the provided type. If the argument is found multiple times, only the most recent value is used. The argument should be in the form --name= value. Boolean arguments are unique in that the value is optional, when not provided it defaults totrue. "--" may be used to separate parameters from arguments.- Parameters:
args- the values used during the processing of the parameters will be set to null- Returns:
- the converted value or
nullif not found - See Also:
parse(String, Class)
-
getArguments
public static List<String> getArguments(String[] args)
Gets all of the non-parameter arguments. If any arguments start with "--" and are not a valid parameter, throws IllegalArgumentException. "--" may be used to separate parameters from arguments. The "--" will be included in the arguments returned.
-
-