Package aQute.lib.specinterface
Class SpecInterface<T>
java.lang.Object
aQute.lib.specinterface.SpecInterface<T>
- Type Parameters:
T
-
Uses an interface to provide a _specification_ of a command line. Methods
with no or 1 parameter (with the same parameter type as their return type)
are _parameter_ methods. If the return type is boolean, they are _option_
methods. If a method with the same name appears in the 0 and 1 parameter
form, the return type must be identical.
Each method name is available in the command line as --name, and -n, where n is the first character of the name. If the same letter is used twice, the names are sorted and the first appearing name gets the lower case, the second gets the upper case, and the third and later will not have a single character identifier.
Single character identifiers can be merged together. I.e. -xyz will be parsed as -x -y -z. Except for the last one, the others must be options.
The command line may also contains key=value
pairs. These are stored
in a map and are available as _properties() if declared on the interface.
There are a number of build-in values that, when needed, should be declared on the interface.
_arguments() List<String> the argument list with the parameters removed _properties() Map<String,String> any key=value pairs
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Pattern
private final IllegalArgumentException
private final T
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static void
failure()
static <T> SpecInterface<T>
getOptions
(Class<T> specification, List<String> args, File base) Parse the options in a command line and return an interface that provides the options from this command line.static Class<?>
getParameterizedInterfaceType
(Class<?> baseType, Class<?> interfce) A common pattern is to use theSpecInterface
with a parameterized interface.static Class<?>
getParameterizedSuperType
(Class<?> baseType) A common pattern is to use theSpecInterface
with a parameterized super class.instance()
boolean
(package private) static Map<String,
SpecInterface.O>
-
Field Details
-
ASSIGNMENT
-
instance
-
failure
-
-
Constructor Details
-
SpecInterface
-
SpecInterface
-
-
Method Details
-
instance
-
failure
-
isFailure
public boolean isFailure() -
getOptions
public static <T> SpecInterface<T> getOptions(Class<T> specification, List<String> args, File base) throws Exception Parse the options in a command line and return an interface that provides the options from this command line. This will parse up to (and including) -- or an argument that does not start with -- Throws:
Exception
-
getParameterizedSuperType
A common pattern is to use theSpecInterface
with a parameterized super class. This is a convenient method that extracts the first type parameter.- Parameters:
baseType
- a parameterized type- Returns:
- null or the first type parameter
-
getParameterizedInterfaceType
A common pattern is to use theSpecInterface
with a parameterized interface. This is a convenient method that extracts the first type parameter.- Parameters:
baseType
- a parameterized typeinterfce
- a interface type- Returns:
- null or the first type parameter
-
add
-
parse
-