Arguments Annotation

@Arguments

The @Arguments annotation is applied to fields of a class to indicate that the field should be populated from any string arguments that are not otherwise parsed as options.

Arguments are typically used to take in free-form inputs such as lists of files to operate on.

By default if no field is annotated with @Arguments then it is illegal to pass in string arguments that are not options.

Simple Definition

At its simplest the annotation requires no arguments and may be applied like so:

@Arguments
private List<String> files;

Here we define a field files which is a List<String> so each argument received will be treated as a String and the list populated appropriately. Just like @Option the type of the arguments is inferred from the field to which the annotation applies, please see Supported Types for more detail on the types Airline supports.

If you do not explicitly instantiate collection arguments then they will be null if a user does not provide any appropriate arguments

Titles

In more complex cases you may wish to have arguments where each argument denotes a different thing in which case you can use the titles field so set the titles of the arguments that will appear in Help e.g.

@Arguments(title = { "host", "username" })
private List<String> args;

Here we define a field args which again is a List<String> and with the titles host and username. This will cause these titles to be displayed in help as opposed to the default title which is simply the name of the annotated field.

Description

The description field may be used to describe how arguments are intended to be used e.g.

@Arguments(description = "Provides the names of one/more files to process")
private List<String> files;

Type Converter Provider

To override how user inputs are converted into values for these arguments specify a custom TypeConverterProvider to use e.g.

@Arguments(description = "Provides hexadecimal values", typeConverterProvider = Hexadecimal.class)
private List<Integer> hexCodes;

The above example uses the Hexadecimal type converter which parses users inputs as hexadecimal numbers when converting to Integer.


Improving this Documentation

This 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.