Annotation Type Parser


  • @Target(TYPE)
    @Retention(RUNTIME)
    @Documented
    public @interface Parser
    Class annotation used to declaratively specify a parser configuration

    When applied to a class that is also annotated with the Command annotation then if that class is used with SingleCommand.singleCommand(Class) the parser configuration will automatically be detected from this annotation.

    When specifying a CLI via the Cli annotation then this annotation may be included as an argument to the Cli.parserConfiguration() field to provide a parser configuration for the CLI.

    • Element Detail

      • allowCommandAbbreviation

        boolean allowCommandAbbreviation
        Controls whether command names may be abbreviated provided such abbreviations are unambiguous (default false)
        Returns:
        True if command abbreviation allowed, false otherwise
        Default:
        false
      • allowOptionAbbreviation

        boolean allowOptionAbbreviation
        Controls whether options names may be abbreviated provided such abbreviations are unambiguous (default false)
        Returns:
        True if option abbreviation allowed, false otherwise
        Default:
        false
      • argumentsSeparator

        java.lang.String argumentsSeparator
        Controls the separator that is used to distinguish options from arguments were arguments may be confused as options

        The default is -- which is the widely used convention

        Returns:
        Arguments separator
        Default:
        "--"
      • aliasesMayChain

        boolean aliasesMayChain
        Controls whether command alises may be chained i.e. can aliases be defined in terms of other aliases (default false)

        Note that even when enabled circular references are not permitted

        Returns:
        True if aliases may be chained, false otherwise
        Default:
        false
      • aliasesOverrideBuiltIns

        boolean aliasesOverrideBuiltIns
        Controls whether aliases are allowed to override built-in commands i.e. if a command and an alias are defined with the same name does the alias take precedence (default false)

        This is particularly important if you allow users to define aliases since allowing overriding would allow them to change the behaviour from the default expected

        Returns:
        True if aliases may override built-ins, false otherwise
        Default:
        false
      • aliases

        Alias[] aliases
        Defines command aliases
        Returns:
        Command aliases
        Default:
        {}
      • userAliasesFile

        java.lang.String userAliasesFile
        Defines the name of a file from which user defined command aliases should be read
        Returns:
        User aliases filename
        Default:
        ""
      • userAliasesSearchLocation

        java.lang.String[] userAliasesSearchLocation
        Defines the search locations (i.e. directories) where the properties file containing the user defined aliases may exist

        These should be given in order of preference, properties from all locations will be merged together such that properties from the locations earlier in this list take precedence

        Search locations may start with ~/ or ~\ (depending on the target platform) to refer to the home directory

        Returns:
        Search locations for alises
        Default:
        {""}
      • userAliasesPrefix

        java.lang.String userAliasesPrefix
        Sets the prefix used for properties that define aliases

        This is useful if you use the same properties file to store general properties for your application in the same properties file. If set only properties whose names begin with these prefix are treated as alias definition with the prefix being stripped. So for example if you have a prefix of foo. and defined a property foo.bar then you would be defining an alias bar

        Returns:
        User defined aliases prefix
        Default:
        ""
      • aliasesForceBuiltInPrefix

        char aliasesForceBuiltInPrefix
        Sets a character used in alias definitions to indicate that the built-in should be called regardless of the setting of aliasesOverrideBuiltIns()

        This is useful since it allows users to redefine built-ins with their desired default arguments while still allowing the alias to call the original built-in. This defaults to !

        Returns:
        Aliases force built-in prefix character
        Default:
        '!'
      • useDefaultAliasLocators

        boolean useDefaultAliasLocators
        Sets whether to use the default user alias locators (default true)
        Returns:
        True if defaults are used, false otherwise
        Default:
        true
      • defaultAliasLocatorsFirst

        boolean defaultAliasLocatorsFirst
        Sets whether to use the default alias locators first before any additional alias locators that may be defined (default false)
        Returns:
        True if defaults are used first, false otherwise
        Default:
        false
      • userAliasLocators

        java.lang.Class<? extends ResourceLocator>[] userAliasLocators
        Sets the user alias locator classes to be used
        Returns:
        User alias locator classes
        Default:
        {}
      • useDefaultOptionParsers

        boolean useDefaultOptionParsers
        Sets whether to use the default set of option parsers (default true)
        Returns:
        True if default option parsers are used, false otherwise
        Default:
        true
      • defaultParsersFirst

        boolean defaultParsersFirst
        Sets whether to use the default option parsers first before any additional option parsers that may be defined (default true)
        Returns:
        True if default parsers are used first, false otherwise
        Default:
        true
      • optionParsers

        java.lang.Class<? extends OptionParser>[] optionParsers
        Sets the option parser classes to be used
        Returns:
        Option parser classes
        Default:
        {}
      • commandFactory

        java.lang.Class<? extends CommandFactory> commandFactory
        Sets the command factory class to use
        Returns:
        Command factory class
        Default:
        com.github.rvesse.airline.DefaultCommandFactory.class
      • compositionAnnotationClasses

        java.lang.String[] compositionAnnotationClasses
        Sets the composition annotation classes to use.

        This is set by providing the fully qualified names of the classes, rather than class references themselves, this allows Airline to dynamically load the annotation at the point where it collects metadata for classes. Thus allowing the actual annotation types used to themselves be injected at runtime rather than compile time.

        See MetadataLoader.loadInjectionMetadata(Class, ParserMetadata) for more detailed description of how this configuration is used.

        This configuration point was introduced in 2.9.0 as part of the introduction of the AirlineModule annotation to provide for backwards compatibility and for users to better integrate with their chosen dependency injection framework.

        Returns:
        Composition annotation classes
        Since:
        2.9.0
        Default:
        {}
      • typeConverter

        java.lang.Class<? extends TypeConverter> typeConverter
        Sets the type converter class to use
        Returns:
        Type converter class
        Default:
        com.github.rvesse.airline.types.DefaultTypeConverter.class
      • numericTypeConverter

        java.lang.Class<? extends NumericTypeConverter> numericTypeConverter
        Sets the numeric type converter to use, this is used in conjunction with the value of the typeConverter(), if that class does not respect NumericTypeConverter instances then this field has no effect
        Returns:
        Numeric type converter class
        Default:
        com.github.rvesse.airline.types.numerics.DefaultNumericConverter.class
      • errorHandler

        java.lang.Class<? extends ParserErrorHandler> errorHandler
        Sets the error handler to use, defaults to FailFast which throws errors as soon as they are encountered
        Returns:
        Error handler to use
        Default:
        com.github.rvesse.airline.parser.errors.handlers.FailFast.class
      • flagNegationPrefix

        java.lang.String flagNegationPrefix
        Sets the flag negation prefix

        If set flag options (those with arity zero) will have their value set to false if the name used starts with this prefix. For example if the prefix is set to --no- and the user specifies a flag that begins with this the option will be set to false. Note that an appropriate name must be present in the Option.name() for the flag option which you wish to allow to be negated.

        Returns:
        Flag negation prefix
        Default:
        ""