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

io.github.molumn.catrix.kommand.LiteralNode.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.annotations.KommandDSL
import io.github.molumn.catrix.common.Interactive
import io.github.molumn.catrix.utils.FakeSystem

@KommandDSL
class LiteralNode(name: String) : AbstractKommandNode(name) {

    override fun build(): AbstractRegisteredKommandNode<*> {
        return RegisteredLiteralNode(name, condition, executor, children.map { it.build() })
    }

}

class RegisteredLiteralNode(
    name: String,
    condition: FakeSystem.() -> Boolean,
    executor: ((Interactive, KommandContext, FakeSystem) -> Boolean)?,
    children: List>
) : AbstractRegisteredKommandNode(name, condition, executor, children) {

    override fun check(string: String): Boolean = string == name

    override fun extract(string: String): String {
        require(string == name) { "not matched content: $string to $name" }
        return string
    }

    override fun listSuggestion(string: String): List = listOf(name)

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy