Annotation Type Arg


  • @Retention(RUNTIME)
    @Target(FIELD)
    public @interface Arg
    This annotation is used to mark a field as a named option(code/flag).
    Author:
    John Dunlap
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String category
      The category in which the option should appear in the help message.
      char code
      The single character code for the option.
      Class<?> collectionType
      This is only necessary if the field is a collection.
      Class<? extends TypeConverter<?>> converter
      This is only necessary if the field is a type that is not supported by default.
      String description
      The description of the option.
      int exitStatus
      If set to a non-zero value, this is the exit status which will be set if binding fails for this property.
      String flag
      The name of the option.
      int max
      This is ignored for fields which are not collections.
      int min
      This is ignored for fields which are not collections.
      int order
      The index into the array of ordered arguments(not specified with a code/flag).
      boolean required
      True if the option requires a value.
    • Element Detail

      • code

        char code
        The single character code for the option. This is expected to be a single character. For example, 'o'.
        Returns:
        The single character code for the option.
        Default:
        ' '
      • flag

        String flag
        The name of the option. This is expected to be two or more characters and hyphen cased. For example, "my-option".
        Returns:
        The name of the option.
        Default:
        ""
      • order

        int order
        The index into the array of ordered arguments(not specified with a code/flag). This index is used to determine which ordered values are applied to which fields. This has no affect if code or flag are specified.
        Returns:
        The index into the array of ordered arguments.
        Default:
        -1
      • min

        int min
        This is ignored for fields which are not collections. For collections, this is the minimum number of values that should be bound. If the number of values is less than this, an exception will be thrown. The default is 0.
        Returns:
        The minimum number of values that should be bound.
        Default:
        0
      • max

        int max
        This is ignored for fields which are not collections. For collections, this is the maximum number of values that should be bound. If the number of values is greater than this, an exception will be thrown. The default is 1.
        Returns:
        The maximum number of values that should be bound.
        Default:
        1
      • exitStatus

        int exitStatus
        If set to a non-zero value, this is the exit status which will be set if binding fails for this property. The default is 0. Setting this attribute to 0(the default) will have no effect as other properties may fail to bind even if this one succeeds.
        Returns:
        The exit status which will be set if binding fails for this property.
        Default:
        0
      • required

        boolean required
        True if the option requires a value. If true and if a value is not available, an exception will be thrown. If used on a collection, this is the same as specifying a min of 1.
        Returns:
        True if the option requires a value.
        Default:
        false
      • category

        String category
        The category in which the option should appear in the help message. This is used in the help message.
        Returns:
        The category of the option.
        Default:
        ""
      • description

        String description
        The description of the option. This is used in the help message.
        Returns:
        The description of the option.
        Default:
        ""
      • collectionType

        Class<?> collectionType
        This is only necessary if the field is a collection. In that case, this is the type of the objects which the collection will contain. This is necessary because of Java type erasure. Generics are not available at runtime.
        Returns:
        The type of the objects which the collection will contain.
        Default:
        java.lang.Object.class
      • converter

        Class<? extends TypeConverter<?>> converter
        This is only necessary if the field is a type that is not supported by default. In that case, this type is instantiated and used to parse the value.
        Returns:
        The class of the ValueParser to use.
        Default:
        pro.johndunlap.getopt.DefaultValueParser.class