Files
Lab6-Prog/server/src/main/kotlin/commands/AddCommand.kt
T
2026-04-13 01:01:04 +03:00

18 lines
679 B
Kotlin

package commands
import collection.CollectionManager
import models.HumanBeing
class AddCommand(private val manager: CollectionManager) : Command {
override val name = "add"
override val description = "добавить новый элемент в коллекцию"
override fun execute(args: List<String>, humanBeing: HumanBeing?): String {
humanBeing ?: return "[Ошибка] Объект HumanBeing не передан."
return if (manager.add(humanBeing))
"Элемент добавлен: ${humanBeing.name} [${humanBeing.id}]"
else
"Элемент уже существует в коллекции."
}
}