Annotation Interface Parser
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.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionAlias[]
Defines command aliaseschar
Sets a character used in alias definitions to indicate that the built-in should be called regardless of the setting ofaliasesOverrideBuiltIns()
boolean
Controls whether command alises may be chained i.e.boolean
Controls whether aliases are allowed to override built-in commands i.e.boolean
Controls whether command names may be abbreviated provided such abbreviations are unambiguous (default false)boolean
Controls whether options names may be abbreviated provided such abbreviations are unambiguous (default false)Controls the separator that is used to distinguish options from arguments were arguments may be confused as optionsClass
<? extends CommandFactory> Sets the command factory class to useString[]
Sets the composition annotation classes to use.boolean
Sets whether to use the default alias locators first before any additional alias locators that may be defined (default false)boolean
Sets whether to use the default option parsers first before any additional option parsers that may be defined (default true)Class
<? extends ParserErrorHandler> Sets the error handler to use, defaults toFailFast
which throws errors as soon as they are encounteredSets the flag negation prefixClass
<? extends NumericTypeConverter> Sets the numeric type converter to use, this is used in conjunction with the value of thetypeConverter()
, if that class does not respectNumericTypeConverter
instances then this field has no effectClass<? extends OptionParser>[]
Sets the option parser classes to be usedClass
<? extends TypeConverter> Sets the type converter class to useboolean
Sets whether to use the default user alias locators (default true)boolean
Sets whether to use the default set of option parsers (default true)Defines the name of a file from which user defined command aliases should be readSets the prefix used for properties that define aliasesString[]
Defines the search locations (i.e.Class<? extends ResourceLocator>[]
Sets the user alias locator classes to be used
-
Element Details
-
allowCommandAbbreviation
boolean allowCommandAbbreviationControls 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 allowOptionAbbreviationControls whether options names may be abbreviated provided such abbreviations are unambiguous (default false)- Returns:
- True if option abbreviation allowed, false otherwise
- Default:
false
-
argumentsSeparator
String argumentsSeparatorControls the separator that is used to distinguish options from arguments were arguments may be confused as optionsThe default is
--
which is the widely used convention- Returns:
- Arguments separator
- Default:
"--"
-
aliasesMayChain
boolean aliasesMayChainControls 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 aliasesOverrideBuiltInsControls 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[] aliasesDefines command aliases- Returns:
- Command aliases
- Default:
{}
-
userAliasesFile
String userAliasesFileDefines the name of a file from which user defined command aliases should be read- Returns:
- User aliases filename
- Default:
""
-
userAliasesSearchLocation
String[] userAliasesSearchLocationDefines the search locations (i.e. directories) where the properties file containing the user defined aliases may existThese 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
String userAliasesPrefixSets the prefix used for properties that define aliasesThis 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 propertyfoo.bar
then you would be defining an aliasbar
- Returns:
- User defined aliases prefix
- Default:
""
-
aliasesForceBuiltInPrefix
char aliasesForceBuiltInPrefixSets a character used in alias definitions to indicate that the built-in should be called regardless of the setting ofaliasesOverrideBuiltIns()
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 useDefaultAliasLocatorsSets whether to use the default user alias locators (default true)- Returns:
- True if defaults are used, false otherwise
- Default:
true
-
defaultAliasLocatorsFirst
boolean defaultAliasLocatorsFirstSets 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
Class<? extends ResourceLocator>[] userAliasLocatorsSets the user alias locator classes to be used- Returns:
- User alias locator classes
- Default:
{}
-
useDefaultOptionParsers
boolean useDefaultOptionParsersSets 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 defaultParsersFirstSets 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
Class<? extends OptionParser>[] optionParsersSets the option parser classes to be used- Returns:
- Option parser classes
- Default:
{}
-
commandFactory
Class<? extends CommandFactory> commandFactorySets the command factory class to use- Returns:
- Command factory class
- Default:
com.github.rvesse.airline.DefaultCommandFactory.class
-
compositionAnnotationClasses
String[] compositionAnnotationClassesSets 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
Class<? extends TypeConverter> typeConverterSets the type converter class to use- Returns:
- Type converter class
- Default:
com.github.rvesse.airline.types.DefaultTypeConverter.class
-
numericTypeConverter
Class<? extends NumericTypeConverter> numericTypeConverterSets the numeric type converter to use, this is used in conjunction with the value of thetypeConverter()
, if that class does not respectNumericTypeConverter
instances then this field has no effect- Returns:
- Numeric type converter class
- Default:
com.github.rvesse.airline.types.numerics.DefaultNumericConverter.class
-
errorHandler
Class<? extends ParserErrorHandler> errorHandlerSets the error handler to use, defaults toFailFast
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
String flagNegationPrefixSets the flag negation prefixIf 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 tofalse
. Note that an appropriate name must be present in theOption.name()
for the flag option which you wish to allow to be negated.- Returns:
- Flag negation prefix
- Default:
""
-