Class SpecInterface<T>

java.lang.Object
aQute.lib.specinterface.SpecInterface<T>
Type Parameters:
T -

public class SpecInterface<T> extends 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
 
  • Field Details

  • Constructor Details

  • Method Details

    • instance

      public T instance()
    • failure

      public String 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

      public static Class<?> getParameterizedSuperType(Class<?> baseType)
      A common pattern is to use the SpecInterface 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 Class<?> getParameterizedInterfaceType(Class<?> baseType, Class<?> interfce)
      A common pattern is to use the SpecInterface with a parameterized interface. This is a convenient method that extracts the first type parameter.
      Parameters:
      baseType - a parameterized type
      interfce - a interface type
      Returns:
      null or the first type parameter
    • add

      static void add(Map<String,Object> map, SpecInterface.O o, String value)
    • parse

      static Map<String,SpecInterface.O> parse(Class<?> type)