clikt
clikt copied to clipboard
Is it possible to emit an error when parsing an option for groups other than the selected?
The groupChoice feature allow users to define multiple groups and use an option to select one from these. The doc said that:
Options for groups other than the selected one are ignored
I am wondering if it's possible to emit an error other than just ignoring the option from other group. And then it will be less error prone.
For example:
sealed class LoadConfig(name: String): OptionGroup(name)
class FromDisk : LoadConfig("Options for loading from disk") {
val path by option().file().required()
val followSymlinks by option().flag()
}
class FromNetwork: LoadConfig("Options for loading from network") {
val url by option().required()
val username by option().prompt()
val password by option().prompt(hideInput = true)
}
class Tool : CliktCommand(help = "An example of a custom help formatter that uses ansi colors") {
val load by option().groupChoice(
"disk" to FromDisk(),
"network" to FromNetwork()
)
override fun run() {
when(val it = load) {
is FromDisk -> echo("Loading from disk: ${it.path}")
is FromNetwork -> echo("Loading from network: ${it.url}")
null -> echo("Not loading")
}
}
}
Usage:
$ ./tool --load=disk --path=./config --follow-symlinks --username=admin
Error: No option "--username" when "--load=disk"