feat(command): add help command

This commit is contained in:
2026-03-04 12:35:55 +03:00
parent 956e3c15a9
commit d2ab854e90
3 changed files with 26 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import command.commands.Add
import command.commands.Clear import command.commands.Clear
import command.commands.Exit import command.commands.Exit
import command.commands.Help import command.commands.Help
import command.commands.History
import command.commands.Info import command.commands.Info
import command.commands.RemoveById import command.commands.RemoveById
import command.commands.RemoveFirst import command.commands.RemoveFirst
@@ -30,5 +31,6 @@ class AppInitializer {
commandManager.register(Update(io, collectionManager)) commandManager.register(Update(io, collectionManager))
commandManager.register(RemoveById(io, collectionManager)) commandManager.register(RemoveById(io, collectionManager))
commandManager.register(RemoveFirst(io, collectionManager)) commandManager.register(RemoveFirst(io, collectionManager))
commandManager.register(History(io, commandManager))
} }
} }

View File

@@ -1,9 +1,11 @@
package command package command
import io.IOHandler import io.IOHandler
import java.util.LinkedList
class CommandManager { class CommandManager {
private val commands = mutableMapOf<String, Command>() private val commands = mutableMapOf<String, Command>()
private val history = LinkedList<Command>()
fun register(command: Command) { fun register(command: Command) {
commands[command.name] = command commands[command.name] = command
@@ -25,10 +27,13 @@ class CommandManager {
if (command != null) { if (command != null) {
command.execute(args) command.execute(args)
history.add(command)
} else { } else {
io.println("команда не найдена") io.println("команда не найдена")
} }
} }
fun getCommands() = commands fun getCommands() = commands
fun getHistory() = history
} }

View File

@@ -0,0 +1,19 @@
package command.commands
import command.Command
import command.CommandManager
import io.IOHandler
class History(
private val io: IOHandler,
private val commandManager: CommandManager,
) : Command {
override val name = "history"
override val description = "last 10 command was written"
override fun execute(args: String) {
for (command in commandManager.getHistory()) {
io.println(command.name)
}
}
}