From e2f27d0cd2433a1526ee5426d3e77017e765baa5 Mon Sep 17 00:00:00 2001 From: FoXeNe Date: Sat, 28 Feb 2026 15:29:32 +0300 Subject: [PATCH] feat(command): add command manager and command --- app/src/main/kotlin/lab5/Main.kt | 10 ++-- .../kotlin/lab5/command/CommandInterface.kt | 8 +++ .../kotlin/lab5/command/CommandManager.kt | 11 ++++ .../main/kotlin/lab5/command/InputManager.kt | 50 ------------------- .../main/kotlin/lab5/command/commands/Add.kt | 12 +++++ 5 files changed, 38 insertions(+), 53 deletions(-) create mode 100644 app/src/main/kotlin/lab5/command/CommandInterface.kt create mode 100644 app/src/main/kotlin/lab5/command/CommandManager.kt delete mode 100644 app/src/main/kotlin/lab5/command/InputManager.kt create mode 100644 app/src/main/kotlin/lab5/command/commands/Add.kt diff --git a/app/src/main/kotlin/lab5/Main.kt b/app/src/main/kotlin/lab5/Main.kt index 5ea7db8..dc8757b 100644 --- a/app/src/main/kotlin/lab5/Main.kt +++ b/app/src/main/kotlin/lab5/Main.kt @@ -1,9 +1,13 @@ package lab5 -import lab5.command.InputManager +import lab5.command.CommandManager fun main() { - val input = InputManager() + val commandManager = CommandManager() - input.productInput() + while (true) { + val input = readlnOrNull().toString() + + commandManager.initCommand(input) + } } diff --git a/app/src/main/kotlin/lab5/command/CommandInterface.kt b/app/src/main/kotlin/lab5/command/CommandInterface.kt new file mode 100644 index 0000000..68db28c --- /dev/null +++ b/app/src/main/kotlin/lab5/command/CommandInterface.kt @@ -0,0 +1,8 @@ +package lab5.command + +interface CommandInterface { + val name: String + val description: String + + fun execute(args: String? = null) +} diff --git a/app/src/main/kotlin/lab5/command/CommandManager.kt b/app/src/main/kotlin/lab5/command/CommandManager.kt new file mode 100644 index 0000000..f899e02 --- /dev/null +++ b/app/src/main/kotlin/lab5/command/CommandManager.kt @@ -0,0 +1,11 @@ +package lab5.command + +import lab5.command.commands.Add + +class CommandManager { + fun initCommand(command: String) { + when (command) { + "add" -> Add().execute() + } + } +} diff --git a/app/src/main/kotlin/lab5/command/InputManager.kt b/app/src/main/kotlin/lab5/command/InputManager.kt deleted file mode 100644 index 9637b3c..0000000 --- a/app/src/main/kotlin/lab5/command/InputManager.kt +++ /dev/null @@ -1,50 +0,0 @@ -package lab5.command - -import lab5.manager.CollectionManager -import lab5.model.Coordinates -import lab5.model.Organization -import lab5.model.Product -import java.time.ZonedDateTime -import java.util.LinkedList -import kotlin.text.toLong -import kotlin.text.toLongOrNull - -class InputManager { - fun productInput() { - val manager = CollectionManager() - - println("введите имя") - val name = readLine() ?: "default" - - var price: Long? - - do { - println("введите цену:") - var input = readLine() - - price = input?.toLongOrNull() - - if (price == null) { - println("цена должна быть числом") - } else if (price <= 0) { - println("цена должна быть больше 0") - price = null - } - } - while (price == null) - - val newProduct = - Product( - id = 1, - name = name, - // TODO: do this coordinates section - coordinates = Coordinates(10L, 10F), - creationDate = ZonedDateTime.now(), - price = price, - unitOfMeasure = null, - // TODO: do this Organization section - manufacturer = Organization(1L, "test", "testtest", 10L), - ) - manager.addProduct(newProduct) - } -} diff --git a/app/src/main/kotlin/lab5/command/commands/Add.kt b/app/src/main/kotlin/lab5/command/commands/Add.kt new file mode 100644 index 0000000..0ef782f --- /dev/null +++ b/app/src/main/kotlin/lab5/command/commands/Add.kt @@ -0,0 +1,12 @@ +package lab5.command.commands + +import lab5.command.CommandInterface + +class Add : CommandInterface { + override val name = "add" + override val description = "add product" + + override fun execute(args: String?) { + println("fdada") + } +}