Package picocli
Annotation Type CommandLine.ArgGroup
-
@Retention(RUNTIME) @Target({FIELD,METHOD,PARAMETER}) public static @interface CommandLine.ArgGroupACommandmay define one or moreArgGroups: a group of options, positional parameters or a mixture of the two. Groups can be used to:- define mutually exclusive arguments. By default, options and positional parameters
in a group are mutually exclusive. This can be controlled with the
exclusiveattribute. Picocli will throw aCommandLine.MutuallyExclusiveArgsExceptionif the command line contains multiple arguments that are mutually exclusive. - define a set of arguments that must co-occur. Set
exclusive = falseto define a group of options and positional parameters that must always be specified together. Picocli will throw aMissingParameterExceptionif not all the options and positional parameters in a co-occurring group are specified together. - create an option section in the usage help message.
To be shown in the usage help message, a group needs to have a
heading(which may come from a resource bundle). Groups without a heading are only used for validation. Setvalidate = falsefor groups whose purpose is only to customize the usage help message. - define composite repeating argument groups. Groups may contain other groups to create composite groups.
Groups may be optional (
multiplicity = "0..1"), required (multiplicity = "1"), or repeating groups (multiplicity = "0..*"ormultiplicity = "1..*"). For a group of mutually exclusive arguments, making the group required means that one of the arguments in the group must appear on the command line, or aMissingParameterExceptionis thrown. For a group of co-occurring arguments, all arguments in the group must appear on the command line.Groups can be composed for validation purposes:
- When the parent group is mutually exclusive, only one of the subgroups may be present.
- When the parent group is a co-occurring group, all subgroups must be present.
- When the parent group is required, at least one subgroup must be present.
Below is an example of an
ArgGroupdefining a set of dependent options that must occur together. All options are required within the group, while the group itself is optional:public class DependentOptions { @ArgGroup(exclusive = false, multiplicity = "0..1") Dependent group; static class Dependent { @Option(names = "-a", required = true) int a; @Option(names = "-b", required = true) int b; @Option(names = "-c", required = true) int c; } }- Since:
- 4.0
- See Also:
CommandLine.Model.ArgGroupSpec
- define mutually exclusive arguments. By default, options and positional parameters
in a group are mutually exclusive. This can be controlled with the
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description booleanexclusiveDetermines whether this is a mutually exclusive group;trueby default.java.lang.StringheadingThe heading of this group, used when generating the usage documentation.java.lang.StringheadingKeyResourceBundle key for this group's usage help message section heading.java.lang.StringmultiplicityDetermines how often this group can be specified on the command line;"0..1"(optional) by default.intorderDetermines the position in the options list in the usage help message at which this group should be shown.booleanvalidateDetermines whether picocli should validate the rules of this group (trueby default).
-
-
-
Element Detail
-
heading
java.lang.String heading
The heading of this group, used when generating the usage documentation. When neither aheadingnor aheadingKeyare specified, this group is used for validation only and does not change the usage help message.- Default:
- "__no_heading__"
-
-
-
headingKey
java.lang.String headingKey
ResourceBundle key for this group's usage help message section heading. When neither aheadingnor aheadingKeyare specified, this group is used for validation only and does not change the usage help message.- Default:
- "__no_heading_key__"
-
-
-
exclusive
boolean exclusive
Determines whether this is a mutually exclusive group;trueby default. Iffalse, this is a co-occurring group. Ignored ifvalidate()isfalse.- Default:
- true
-
-
-
multiplicity
java.lang.String multiplicity
Determines how often this group can be specified on the command line;"0..1"(optional) by default. For a group of mutually exclusive arguments, making the group requiredmultiplicity = "1"means that one of the arguments in the group must appear on the command line, or a MissingParameterException is thrown. For a group of co-occurring arguments, making the group required means that all arguments in the group must appear on the command line. Ignored ifvalidate()isfalse.- Default:
- "0..1"
-
-
-
validate
boolean validate
Determines whether picocli should validate the rules of this group (trueby default). For a mutually exclusive group validation means verifying that no more than one elements of the group is specified on the command line; for a co-occurring group validation means verifying that all elements of the group are specified on the command line. Setvalidate = falsefor groups whose purpose is only to customize the usage help message.- See Also:
multiplicity(),heading()
- Default:
- true
-
-
-
order
int order
Determines the position in the options list in the usage help message at which this group should be shown. Groups with a lower number are shown before groups with a higher number. This attribute is only honored for groups that have aheading(or aheadingKeywith a non-nullresource bundle value).- Default:
- -1
-
-