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

me.jakejmattson.kutils.api.arguments.SplitterArg.kt Maven / Gradle / Ivy

There is a newer version: 0.18.1
Show newest version
package me.jakejmattson.kutils.api.arguments

import me.jakejmattson.kutils.api.dsl.arguments.*
import me.jakejmattson.kutils.api.dsl.command.CommandEvent

open class SplitterArg(override val name: String = "TextWithSplitter", private val splitter: String = "|") : ArgumentType>() {
    companion object : SplitterArg()

    override fun convert(arg: String, args: List, event: CommandEvent<*>): ArgumentResult> {
        val joined = args.joinToString(" ")

        if (!joined.contains(splitter))
            return ArgumentResult.Error("$name requires the character `$splitter` to split input.")

        return ArgumentResult.Success(joined.split(splitter).toList(), args.size)
    }

    override fun generateExamples(event: CommandEvent<*>) = listOf("A${splitter}B${splitter}C")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy