feat(command): add help command
This commit is contained in:
@@ -4,19 +4,21 @@ import command.CommandManager
|
||||
import command.commands.Add
|
||||
import command.commands.Clear
|
||||
import command.commands.Exit
|
||||
import command.commands.Help
|
||||
import io.IOHandler
|
||||
import manager.CollectionManager
|
||||
|
||||
class AppInitializer {
|
||||
fun setup(
|
||||
manager: CommandManager,
|
||||
commandManager: CommandManager,
|
||||
io: IOHandler,
|
||||
app: AppExecutor,
|
||||
) {
|
||||
val collectionManager = CollectionManager(io)
|
||||
|
||||
manager.register(Add(io, collectionManager))
|
||||
manager.register(Exit(io) { app.stop() })
|
||||
manager.register(Clear(io, collectionManager))
|
||||
commandManager.register(Add(io, collectionManager))
|
||||
commandManager.register(Exit(io) { app.stop() })
|
||||
commandManager.register(Clear(io, collectionManager))
|
||||
commandManager.register(Help(io, commandManager))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,6 @@ class CommandManager {
|
||||
io.println("команда не найдена")
|
||||
}
|
||||
}
|
||||
|
||||
fun getCommands() = commands
|
||||
}
|
||||
|
||||
19
app/src/main/kotlin/command/commands/Help.kt
Normal file
19
app/src/main/kotlin/command/commands/Help.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package command.commands
|
||||
|
||||
import command.Command
|
||||
import command.CommandManager
|
||||
import io.IOHandler
|
||||
|
||||
class Help(
|
||||
private val io: IOHandler,
|
||||
private val commandManager: CommandManager,
|
||||
) : Command {
|
||||
override val name = "help"
|
||||
override val description = "show avaliable commands"
|
||||
|
||||
override fun execute() {
|
||||
for (command in commandManager.getCommands().values) {
|
||||
io.println("${command.name}: ${command.description}")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user