@AllowedEnumValues
The @AllowedEnumValues
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.
public enum VerbosityLevels {
TRACE,
DEBUG,
INFO,
WARNING,
ERROR,
FATAL
}
@Option(name = { "-v", "--verbosity" }, arity = 1, title = "Level", description = "Sets the desired verbosity")
@AllowedEnumValues(VerbosityLevels.class)
public VerbosityLevels verbosity = VerbosityLevels.INFO;
This specifies that the --verbosity
option only allows the values from the VerbosityLevels
enum to be specified by the user. Any other value will be rejected.
Note that the restriction applies to the raw string provided to the parser prior to converting it to the target type. So in the above example the values would be checked prior to parsing them as enum values.
If there may be more than one way that the same value may be specified then it may be useful to use the @AllowedValues
annotation instead. If you have a list of acceptable raw string values then use the @AllowedRawValues
annotation instead.
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.