feat(command): add args in execute

This commit is contained in:
2026-03-04 10:55:30 +03:00
parent 1496859cd1
commit 2e4dbda68f
8 changed files with 17 additions and 9 deletions

View File

@@ -4,5 +4,5 @@ interface Command {
val name: String
val description: String
fun execute()
fun execute(args: String)
}

View File

@@ -13,10 +13,18 @@ class CommandManager {
input: String,
io: IOHandler,
) {
val command = commands[input]
val resInput = input.trim().split(" ")
val name = resInput[0]
var args: String
if (resInput.size > 1) {
args = resInput[1]
} else {
args = " "
}
val command = commands[name]
if (command != null) {
command?.execute()
command.execute(args)
} else {
io.println("команда не найдена")
}

View File

@@ -12,7 +12,7 @@ class Add(
override val name = "add"
override val description = "add product"
override fun execute() {
override fun execute(args: String) {
collectionManager.addProduct(ProductReader(io).read())
}
}

View File

@@ -11,7 +11,7 @@ class Clear(
override val name = "clear"
override val description = "clear colletion"
override fun execute() {
override fun execute(args: String) {
collectionManager.getCollection().clear()
io.println(collectionManager.getCollection().toString())
}

View File

@@ -11,7 +11,7 @@ class Exit(
override val name = "exit"
override val description = "stop app execution"
override fun execute() {
override fun execute(args: String) {
io.println("завершение процесса")
stop()
}

View File

@@ -11,7 +11,7 @@ class Help(
override val name = "help"
override val description = "show avaliable commands"
override fun execute() {
override fun execute(args: String) {
for (command in commandManager.getCommands().values) {
io.println("${command.name}: ${command.description}")
}

View File

@@ -11,7 +11,7 @@ class Info(
override val name = "info"
override val description = "show collection info"
override fun execute() {
override fun execute(args: String) {
io.println(collectionManager.getInfoString())
}
}

View File

@@ -11,7 +11,7 @@ class Show(
override val name = "show"
override val description = "show collection elements"
override fun execute() {
override fun execute(args: String) {
if (collectionManager.getCollection().isNotEmpty()) {
for (product in collectionManager.getCollection()) {
io.println(product.toString())