Flag: Toggle Group
Toggleable Group/Toggle Group
Togglable Group
Treat a group of flags as a radio button group in GUI, so the last flags will be reset while the flag in same group is been parsed ok and set.
Generally, both these flags should have a boolean default value. And only one flag have true
value. If the rule is not obeyed, cmdr keeps the last one (true
value of the flags).
Define
.ToggleGroup(toggleGroupName)
can do that.
toggleGroupName
makes the flags into a same toggle group. It is also used as the group name.
In phase invoking OnAction
, the final value of the toggale group can be read by cmd.Store().MustBool(toggleGroupName)
.
Since v2.1.16, Multiple Selections
for a Toggle Group
is avaliable: the final selected items can be read by cmd.Store().MustStringSlice(toggleGroupName+".selected")
.
A sample here,
Run
In the help screen, the flags in a toggle group will be shown with a leading checkbox, just like the following output:
And the final value banana
will be retrieved properly.
额外的话题
How is this guide?
Last updated on