RequireOnlyOne Annotation

@RequireOnlyOne

The @RequireOnlyOne annotation is applied to a field annotated with @Option to indicate that exactly one from some set of options must be specified e.g.

@Option(name = "--num", 
        arity = 1, 
        title = "Number")
@RequireOnlyOne(tag = "identifier")
private int number;

@Option(name = "--name",
        arity = 1,
        title = "Name")
@RequireOnlyOne(tag = "identifier")
private string name;

When fields are marked with @RequireOnlyOne if the user fails to supply exactly one of the options that have the same tag value then an error will be thrown during parsing.

In this example the user must specify exactly one of the --num or --name option, if they specify neither or specify both then it is treated as an error.

If you want to require that at least one of some set of options be specified then you should use @RequireSome instead.

If you optionally want to allow only one from some set of options then you should use @MutuallyExclusiveWith.


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.