Argument groups
Commands can contain argument groups. Groups allow you to organize the arguments in the command in a more structured way so that the user can understand the purpose of each argument better.
Groups are mostly useful for the help message generation, where they can be seen visually affecting the representation of how arguments are displayed.
Creating a group and adding Arguments
Wrap the arguments you want to group in an Group
:
In this case the arguments are added before the group is added to the command (Group instantiation > Arguments added to group > Group added to command). However, this doesn't mean that the arguments have to be added before the group is added to the command. This is also allowed:
Creating a group
Use the group()
attribute in the @Argument.Define
annotation to specify the group that an argument belongs to.
Group hierarchy
Just like commands, groups can be nested inside other groups. This allows you to create a hierarchy of groups:
Restrictive groups
Groups can be set to be restrictive. This means that only a single argument inside that group (or any of its sub-groups) can be used at a time. This is useful for commands that have mutually exclusive arguments.
To make a group restrictive, set the restricted
property of the group to true
:
Example
Given the following group tree (lime colored groups are restrictive):
If
Argument 1
is used, then none of the arguments in the child groups can be used, becauseGroup 1
is restricted.If
Argument 3.1
is used, then none of the arguments in the rest of the tree can be used, because bothGroup 3
and its parentGroup 1
are restricted.If
Argument 2.1
is used,Argument 2.2
can still be used, becauseGroup 2
is not restricted. No other arguments in the tree can be used though.