Airline uses a variety of different annotations to allow you to declaratively define various aspects of your CLIs. This section of the user guide covers each annotation in-depth with examples of their practical usage.
The following annotations are used to define the high level aspects of your CLIs:
@Command
annotation defines classes as being commands@Option
annotation defines fields of a class as denoting options@Arguments
annotation defines a field of a class as denoting arguments@Cli
annotation defines a class as being a CLI which consists of potentially many commands
@Parser
annotation defines the parser behaviour
@Alias
annotation defines command aliases for a parser configuration@DefaultOption
annotation defines an @Option
annotated field as being able to also be populated as if it were @Arguments
annotatedThe following annotations are used to define various restrictions on options and arguments that cause Airline to automatically enforce restrictions on their usage e.g. requiring an option take a value from a restricted set of values.
All these annotations are applied to fields that are annotated with @Option
or @Arguments
and are automatically discovered during meta-data extraction. If you are overriding the definition of an option then restrictions are automatically inherited unless you specify new restrictions further as part of your override. In the case where you wish to remove inherited restrictions you can use the special @Unrestricted
annotation to indicate that.
The following annotations are used to specify that options/arguments (or combinations thereof) are required:
@Required
annotation indicates that an option/argument must be specified@RequireSome
annotation indicates that one/more from some set of options must be specified@RequireOnlyOne
annotation indicates that precisely one of some set of options must be specified@MutuallyExclusiveWith
annotation indicates that precisely one of some set of options may be specifiedThe following annotations are used to specify the number of times that options/arguments can be specified:
@Once
annotation indicates that at option/argument may be specified only once@MinOccurrences
annotation indicates that an option/argument must be specified a minimum number of times@MaxOccurrences
annotation indicates that an option/argument may be specified a maximum number of timesThe following annotations are used to specify restrictions on the values for options/arguments:
@AllowedRawValues
annotation specifies a set of strings that may be specified as the value@AllowedValues
annotation specifies a set of values that may be specified as the value@MaxLength
annotation specifies the maximum length of the value that may be given@MinLength
annotation specifies the minimum length of the value that may be given@NotBlank
annotation specifies that a value may not consist entirely of white space@NotEmpty
annotation specifies that the value may not be an empty string@Path
annotation specifies restrictions on values that refer to files and/or directories@Pattern
annotation specifies that a value must match a regular expression@Port
annotation specifies restrictions on values that represent port numbersA further subset of annotations specify restrictions on the values for options/arguments in terms of ranges of acceptable values:
@ByteRange
annotation specifies a range of byte
values that are acceptable@DoubleRange
annotation specifies a range of double
values that are acceptable@FloatRange
annotation specifies a range of float
values that are acceptable@IntegerRange
annotation specifies a range of int
values that are acceptable@LexicalRange
annotation specifies a range of string
values that are acceptable@LongRange
annotation specifies a range of long
values that are acceptable@ShortRange
annotation specifies a range of short
values that are acceptableThe following are special purpose restrictions:
@Unrestricted
annotation indicates that no restrictions apply to the option. Used in conjunction with option overriding to clear restrictions.@Partials/@Partial
annotation is used to apply restrictions to only some parts of options/arguments where multiple values are accepted by those fieldsThe following are Global restrictions which apply over the final parser state:
@CommandRequired
annotation indicates that a command must be specified.@NoMissingOptionValues
annotation indicates that specifying an option without its corresponding value(s) is not permitted.@NoUnexpectedArguments
annotation indicates that any unrecognised inputs are not permitted.The following annotations are used to add additional help information to commands that may be consumed by the various help generators provided by Airline by producing additional help sections.
All these annotations are added to an @Command
annotated class or a parent class in the commands
hierarchy. They are automatically discovered from a command classes inheritance hierarchy, where an annotation occurs
more than once the annotation specified furthest down the hierarchy is used. This can be used to specify a default for
some help annotation with the option of overriding it if necessary, the special @HideSection
annotation may be used to suppress an inherited help annotation.
@Copyright
annotation adds a copyright statement@Discussion
/@ExternalDiscussion
annotations add extended discussion@ExitCodes
/@ExternalExitCodes
annotations adds documentation on exit codes@Examples
/@ExternalExamples
/@ExternalTabularExamples
annotations add usage examples@HideSection
annotation is used to hide an inherited help section@License
annotation adds a license statement@ProseSection
/@ExternalProse
annotations adds custom titled text sections@Version
annotation adds a version statementThis documentation is itself open source and lives in GitHub under the docs/ directory.
I am not a professional technical writer and as the developer of this software I can often make assumptions of
knowledge that you as a user reading this may not have. Improvements to the documentation are always welcome, if you
have suggestions for the documentation please submit pull requests to the main
branch.