feat(command): add help command
This commit is contained in:
@@ -5,6 +5,7 @@ import command.commands.Add
|
||||
import command.commands.Clear
|
||||
import command.commands.Exit
|
||||
import command.commands.Help
|
||||
import command.commands.History
|
||||
import command.commands.Info
|
||||
import command.commands.RemoveById
|
||||
import command.commands.RemoveFirst
|
||||
@@ -30,5 +31,6 @@ class AppInitializer {
|
||||
commandManager.register(Update(io, collectionManager))
|
||||
commandManager.register(RemoveById(io, collectionManager))
|
||||
commandManager.register(RemoveFirst(io, collectionManager))
|
||||
commandManager.register(History(io, commandManager))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package command
|
||||
|
||||
import io.IOHandler
|
||||
import java.util.LinkedList
|
||||
|
||||
class CommandManager {
|
||||
private val commands = mutableMapOf<String, Command>()
|
||||
private val history = LinkedList<Command>()
|
||||
|
||||
fun register(command: Command) {
|
||||
commands[command.name] = command
|
||||
@@ -25,10 +27,13 @@ class CommandManager {
|
||||
|
||||
if (command != null) {
|
||||
command.execute(args)
|
||||
history.add(command)
|
||||
} else {
|
||||
io.println("команда не найдена")
|
||||
}
|
||||
}
|
||||
|
||||
fun getCommands() = commands
|
||||
|
||||
fun getHistory() = history
|
||||
}
|
||||
|
||||
19
app/src/main/kotlin/command/commands/History.kt
Normal file
19
app/src/main/kotlin/command/commands/History.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user