@Unrestricted
The @Unrestricted
annotation is applied to fields annotated with @Option
or @Arguments
to indicate that no restrictions should apply.
This is useful because by default restrictions are inherited so if you wish to remove restrictions when overriding an option definition then you need to use this annotation.
For example consider we have the following command defined:
package com.github.rvesse.airline.examples.userguide.restrictions;
import com.github.rvesse.airline.SingleCommand;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;
import com.github.rvesse.airline.annotations.restrictions.Required;
@Command(name = "required")
public class RequiredOption {
@Option(name = "--name",
arity = 1,
title = "Name")
@Required
private String name;
public static void main(String[] args) {
SingleCommand.singleCommand(RequiredOption.class).parse(args);
}
}
This command requires that the --name
option be specified otherwise an error will be thrown.
However if we wanted to make that option optional in a derived class we can do so like so:
package com.github.rvesse.airline.examples.userguide.restrictions;
import com.github.rvesse.airline.SingleCommand;
import com.github.rvesse.airline.annotations.Command;
import com.github.rvesse.airline.annotations.Option;
import com.github.rvesse.airline.annotations.restrictions.Unrestricted;
@Command(name = "optional")
public class OptionalOption extends RequiredOption {
@Option(name = "--name",
arity = 1,
title = "Name")
@Unrestricted
private String name;
public static void main(String[] args) {
SingleCommand.singleCommand(OptionalOption.class).parse(args);
}
}
Here we use @Unrestricted
to indicate that the --name
option has no restrictions upon it.
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.