From f8c6246a262b1d15e42ce812363f7d4e4eb16b8a Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 9 Dec 2021 02:56:50 +0100 Subject: suspend shell executor --- src/main/kotlin/moe/nea89/website/Command.kt | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/main/kotlin/moe/nea89/website/Command.kt') diff --git a/src/main/kotlin/moe/nea89/website/Command.kt b/src/main/kotlin/moe/nea89/website/Command.kt index cb59d0a..b8e4675 100644 --- a/src/main/kotlin/moe/nea89/website/Command.kt +++ b/src/main/kotlin/moe/nea89/website/Command.kt @@ -1,16 +1,11 @@ package moe.nea89.website -interface Command { - val name: String - val aliases: Set - fun run(console: KConsole, name: String, args: List) -} +data class Command( + val name: String, + val aliases: Set, + val runner: suspend ShellExecutionContext.() -> Unit, +) -data class CommandContext(val console: KConsole, val name: String, val args: List) -fun command(name: String, vararg aliases: String, block: CommandContext. () -> Unit) = object : Command { - override val name: String = name - override val aliases: Set = aliases.toSet() - - override fun run(console: KConsole, name: String, args: List) = block(CommandContext(console, name, args)) -} \ No newline at end of file +fun command(name: String, vararg aliases: String, block: suspend ShellExecutionContext. () -> Unit) = + Command(name, aliases.toSet(), block) \ No newline at end of file -- cgit