io.github.molumn.catrix.kommand.KommandContext.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of catrix-api Show documentation
Show all versions of catrix-api Show documentation
Kotlin/JVM library for terminal command development
package io.github.molumn.catrix.kommand
import io.github.molumn.catrix.common.Interactive
import kotlin.reflect.KProperty
class KommandContext(
private val kommand: RegisteredKommand,
private val contents: HashMap>
) {
fun getCommandInputs() : String {
return contents.values.fold("") { acc, kommandContent ->
"$acc " + kommandContent.string
}
}
operator fun invoke(args: Array, interactive: Interactive) {
kommand.execute(args, interactive)
}
@Suppress("UNCHECKED_CAST")
operator fun get(name: String) : T {
val content = contents[name]?.content ?: error("Not found content : $name")
return content as T
}
}
operator fun KommandContext.getValue(
thisRef: Any?,
property: KProperty<*>
) : T {
return this[property.name]
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy