From 406378c7adf877ad4aaa9743fcf8b3e301d53748 Mon Sep 17 00:00:00 2001 From: FoXeNe Date: Sun, 1 Mar 2026 03:05:49 +0300 Subject: [PATCH] chore(command): rename command interface --- .../main/kotlin/command/{CommandHandler.kt => Command.kt} | 3 ++- app/src/main/kotlin/command/CommandManager.kt | 4 ++-- app/src/main/kotlin/command/ProductReader.kt | 2 +- app/src/main/kotlin/command/commands/Add.kt | 8 +++++--- app/src/main/kotlin/command/commands/Exit.kt | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) rename app/src/main/kotlin/command/{CommandHandler.kt => Command.kt} (79%) diff --git a/app/src/main/kotlin/command/CommandHandler.kt b/app/src/main/kotlin/command/Command.kt similarity index 79% rename from app/src/main/kotlin/command/CommandHandler.kt rename to app/src/main/kotlin/command/Command.kt index fa63903..60cbe2f 100644 --- a/app/src/main/kotlin/command/CommandHandler.kt +++ b/app/src/main/kotlin/command/Command.kt @@ -1,7 +1,8 @@ package command -interface CommandHandler { +interface Command { val name: String val description: String + fun execute(args: String? = null) } diff --git a/app/src/main/kotlin/command/CommandManager.kt b/app/src/main/kotlin/command/CommandManager.kt index d80c4ab..d9878c5 100644 --- a/app/src/main/kotlin/command/CommandManager.kt +++ b/app/src/main/kotlin/command/CommandManager.kt @@ -4,9 +4,9 @@ import command.commands.* import io.IOHandler class CommandManager { - private val commands = mutableMapOf() + private val commands = mutableMapOf() - fun register(command: CommandHandler) { + fun register(command: Command) { commands[command.name] = command } diff --git a/app/src/main/kotlin/command/ProductReader.kt b/app/src/main/kotlin/command/ProductReader.kt index 75666db..0febe3e 100644 --- a/app/src/main/kotlin/command/ProductReader.kt +++ b/app/src/main/kotlin/command/ProductReader.kt @@ -10,7 +10,7 @@ import kotlin.text.toLong import kotlin.text.toLongOrNull class InputHandler { - fun productInput(): Product { + fun read(): Product { println("введите имя") val name = readLine() ?: "default" diff --git a/app/src/main/kotlin/command/commands/Add.kt b/app/src/main/kotlin/command/commands/Add.kt index 1305d4d..ec49064 100644 --- a/app/src/main/kotlin/command/commands/Add.kt +++ b/app/src/main/kotlin/command/commands/Add.kt @@ -1,15 +1,17 @@ package command.commands -import command.CommandHandler +import command.Command +import command.ProductReader import io.IOHandler class Add( private val io: IOHandler, -) : CommandHandler { +) : Command { override val name = "add" override val description = "add product" override fun execute(args: String?) { - io.println("fdada") + io.println("добавляем продукт") + ProductReader().read() } } diff --git a/app/src/main/kotlin/command/commands/Exit.kt b/app/src/main/kotlin/command/commands/Exit.kt index e8a7a90..dd74120 100644 --- a/app/src/main/kotlin/command/commands/Exit.kt +++ b/app/src/main/kotlin/command/commands/Exit.kt @@ -1,12 +1,12 @@ package command.commands -import command.CommandHandler +import command.Command import io.IOHandler import kotlin.system.exitProcess class Exit( private val io: IOHandler, -) : CommandHandler { +) : Command { override val name = "exit" override val description = "exit"