4
0
Fork 0
mirror of https://github.com/Anvilcraft/modpacktools synced 2024-06-10 22:49:26 +02:00
modpacktools/src/main/kotlin/ley/anvil/modpacktools/command/AbstractCommand.kt
2020-08-15 16:59:52 +02:00

34 lines
1 KiB
Kotlin

package ley.anvil.modpacktools.command
import net.sourceforge.argparse4j.ArgumentParsers
import net.sourceforge.argparse4j.inf.ArgumentParser
/**
* Implement this for commands. it is meant to reduce boilerplate.
*
* @param displayName the name of this command to be displayed in the help message
* @param name the internal name of the command. will be the display name in lower case and with _ instead of spaces by default
*/
abstract class AbstractCommand
@JvmOverloads
constructor(
val displayName: String,
override val name: String = displayName.toLowerCase().replace(' ', '_')
) : ICommand {
override val parser: ArgumentParser by lazy {
ArgumentParsers.newFor(displayName)
.build()
.description(helpMessage)
.apply {addArgs()}
}
/**
* This will be called to add arguments to the arg parser of this command.
* override this to add arguments.
*
* @receiver the parser to add the args to
*/
protected open fun ArgumentParser.addArgs() {}
}