@AllowedValues
The @AllowedValues
annotation may be applied to fields annotated with @Option
and @Arguments
to limit the set of values that an option may be used with e.g.
@Option(name = { "-v", "--verbosity" }, arity = 1, title = "Level", description = "Sets the desired verbosity")
@AllowedValues(allowedValues = { "1", "2", "3" })
public int verbosity = 1;
This specifies that the --verbosity
option only allows the values 1
, 2
and 3
to be specified by the user. Any other value will be rejected.
Note that the restriction applies to the option value after the parser converts it to the target type. So in the above example the values given in the annotation would be converted to integers and checked against integers converted from the input to the parser.
If there is only one way that a given value may be specified then it may be simpler and more efficient to use the @AllowedRawValues
annotation instead.
If the acceptable values come from an enum
you can simplify your code by using the @AllowedEnumValues
annotation.
For more complex value restrictions a regular expression based restriction using @Pattern
might be appropriate.
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.