feat(command): add args in execute
This commit is contained in:
@@ -4,5 +4,5 @@ interface Command {
|
||||
val name: String
|
||||
val description: String
|
||||
|
||||
fun execute()
|
||||
fun execute(args: String)
|
||||
}
|
||||
|
||||
@@ -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("команда не найдена")
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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}")
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user