Package aQute.lib.specinterface
Class SpecInterface<T>
- java.lang.Object
-
- aQute.lib.specinterface.SpecInterface<T>
-
- Type Parameters:
T
-
public class SpecInterface<T> extends java.lang.Object
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
-
-
Constructor Summary
Constructors Constructor Description SpecInterface(java.lang.IllegalArgumentException exception)
SpecInterface(T convert)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
failure()
static <T> SpecInterface<T>
getOptions(java.lang.Class<T> specification, java.util.List<java.lang.String> args, java.io.File base)
Parse the options in a command line and return an interface that provides the options from this command line.static java.lang.Class<?>
getParameterizedInterfaceType(java.lang.Class<?> baseType, java.lang.Class<?> interfce)
A common pattern is to use theSpecInterface
with a parameterized interface.static java.lang.Class<?>
getParameterizedSuperType(java.lang.Class<?> baseType)
A common pattern is to use theSpecInterface
with a parameterized super class.T
instance()
boolean
isFailure()
-
-
-
Constructor Detail
-
SpecInterface
public SpecInterface(T convert)
-
SpecInterface
public SpecInterface(java.lang.IllegalArgumentException exception)
-
-
Method Detail
-
instance
public T instance()
-
failure
public java.lang.String failure()
-
isFailure
public boolean isFailure()
-
getOptions
public static <T> SpecInterface<T> getOptions(java.lang.Class<T> specification, java.util.List<java.lang.String> args, java.io.File base) throws java.lang.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:
java.lang.Exception
-
getParameterizedSuperType
public static java.lang.Class<?> getParameterizedSuperType(java.lang.Class<?> baseType)
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
public static java.lang.Class<?> getParameterizedInterfaceType(java.lang.Class<?> baseType, java.lang.Class<?> interfce)
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
-
-