All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.molumn.catrix.kommand.KommandContext.kt Maven / Gradle / Ivy

There is a newer version: 0.3.2
Show newest version
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