refactor(command): refactor CommandManager logic

This commit is contained in:
2026-03-01 02:39:56 +03:00
parent f1eb0dbe74
commit 0573d0a3dd

View File

@@ -4,10 +4,22 @@ import command.commands.*
import io.IOHandler
class CommandManager {
fun initCommand(command: String, io: IOHandler) {
when (command) {
"add" -> Add(io).execute()
"exit" -> Exit(io).execute()
private val commands = mutableMapOf<String, CommandHandler>()
fun register(command: CommandHandler) {
commands[command.name] = command
}
fun initCommand(
input: String,
io: IOHandler,
) {
val command = commands[input]
if (command != null) {
command?.execute()
} else {
io.println("команда не найдена")
}
}
}