
commonMain.com.github.ajalt.clikt.parameters.groups.MutuallyExclusiveOption.kt Maven / Gradle / Ivy
package com.github.ajalt.clikt.parameters.groups
import com.github.ajalt.clikt.core.*
import com.github.ajalt.clikt.parameters.internal.NullableLateinit
import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parsers.OptionParser
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class MutuallyExclusiveOptions(
internal val options: List>,
override val groupName: String?,
override val groupHelp: String?,
internal val transformAll: (List) -> OutT
) : ParameterGroupDelegate {
init {
require(options.size > 1) { "must provide at least two options to a mutually exclusive group" }
}
private var value: OutT by NullableLateinit("Cannot read from group delegate before parsing command line")
override operator fun provideDelegate(thisRef: CliktCommand, prop: KProperty<*>): ReadOnlyProperty {
thisRef.registerOptionGroup(this)
for (option in options) {
require(option.names.isNotEmpty()) { "must specify names for all options in a group" }
option.parameterGroup = this
option.groupName = groupName
thisRef.registerOption(option)
}
return this
}
override fun getValue(thisRef: CliktCommand, property: KProperty<*>): OutT = value
override fun finalize(context: Context, invocationsByOption: Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy