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