You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a command has a group choice with a default group, then the options in this group do not work correctly if the user does not specify the group choice explicitly.
Expectation
Consider the following minimal working example.
classCommand : CliktCommand() {
classGroupA : OptionGroup() {
val subOptionA:Int by option()
.int()
.default(5)
}
classGroupB : OptionGroup()
val groupOption by option()
.groupChoice("a" to GroupA(), "b" to GroupB())
.defaultByName("a")
overridefunrun() {
when (val it = groupOption) {
isGroupA->println(it.subOptionA)
isGroupB->println("Nothing to see here")
else-> error("Oops")
}
}
}
funmain(args:Array<String>) =Command().main(args)
The default choice for groupOption is a. Therefore, I expect that if --group-option is not specified, the behaviour is equivalent to specifying --group-option a. This means that subOptionA takes on the value 5, and running the program should print 5.
Reality
The above code throws an exception if no arguments are provided to the program. Similarly, running with only the arguments --sub-option-a 3 also throws an exception. Only when --group-option a is also specified does the program work without exceptions.
Not giving any exceptions results in the following trace.
If a command has a group choice with a default group, then the options in this group do not work correctly if the user does not specify the group choice explicitly.
Expectation
Consider the following minimal working example.
The default choice for
groupOption
isa
. Therefore, I expect that if--group-option
is not specified, the behaviour is equivalent to specifying--group-option a
. This means thatsubOptionA
takes on the value5
, and running the program should print5
.Reality
The above code throws an exception if no arguments are provided to the program. Similarly, running with only the arguments
--sub-option-a 3
also throws an exception. Only when--group-option a
is also specified does the program work without exceptions.Not giving any exceptions results in the following trace.
Additional information
The text was updated successfully, but these errors were encountered: