Service that provides help information for commands.
More...
#include <HelpService.hxx>
|
| | HelpService (std::shared_ptr< ISubject > bus, std::function< std::vector< std::string >()> getCommands, std::function< std::string(const std::string &)> getDescription, std::function< void(const std::string &)> showHelp, std::function< std::string(const std::string &)> getUsage=nullptr) |
| | Constructs the HelpService by injecting necessary dependencies as callbacks.
|
| std::vector< std::string > | getAvailableCommands () const |
| | Executes the getCommandsCallback_ to retrieve the list of all available command names.
|
| std::string | getCommandDescription (const std::string &commandName) const |
| | Executes the getDescriptionCallback_ to retrieve the brief description of a specific command.
|
| void | showCommandHelp (const std::string &commandName) const |
| | Executes the showHelpCallback_ to trigger the display of detailed help for a specific command.
|
| bool | commandExists (const std::string &commandName) const |
| | Checks for the existence of a command by comparing against the list returned by getAvailableCommands.
|
| std::string | getCommandUsage (const std::string &commandName) const |
| | Executes the getUsageCallback_ to retrieve the usage syntax of a specific command.
|
Service that provides help information for commands.
This service implements the application logic for displaying help. It uses a set of callback functions (std::function) to retrieve command data (names, descriptions, usage) and display specific help. This design choice prevents a direct dependency on the CommandFactory, thereby breaking a potential circular dependency.
◆ HelpService()
| svcs::cli::HelpService::HelpService |
( |
std::shared_ptr< ISubject > | bus, |
|
|
std::function< std::vector< std::string >()> | getCommands, |
|
|
std::function< std::string(const std::string &)> | getDescription, |
|
|
std::function< void(const std::string &)> | showHelp, |
|
|
std::function< std::string(const std::string &)> | getUsage = nullptr ) |
Constructs the HelpService by injecting necessary dependencies as callbacks.
- Parameters
-
| bus | Shared pointer to the event bus for notifications. |
| getCommands | Function (callback) that returns a list of available command names. |
| getDescription | Function (callback) that returns the brief description of a command. |
| showHelp | Function (callback) that triggers the full help display for a command. |
| getUsage | Function (callback) that returns the usage syntax of a command (defaults to nullptr if not strictly needed). |
◆ commandExists()
| bool svcs::cli::HelpService::commandExists |
( |
const std::string & | commandName | ) |
const |
|
nodiscard |
Checks for the existence of a command by comparing against the list returned by getAvailableCommands.
- Parameters
-
| commandName | The name of the command to check. |
- Returns
true if the command is registered, false otherwise.
◆ getAvailableCommands()
| std::vector< std::string > svcs::cli::HelpService::getAvailableCommands |
( |
| ) |
const |
|
nodiscard |
Executes the getCommandsCallback_ to retrieve the list of all available command names.
- Returns
- Vector of strings containing the names of all registered commands.
◆ getCommandDescription()
| std::string svcs::cli::HelpService::getCommandDescription |
( |
const std::string & | commandName | ) |
const |
|
nodiscard |
Executes the getDescriptionCallback_ to retrieve the brief description of a specific command.
- Parameters
-
| commandName | The name of the command. |
- Returns
- The command description, or "Unknown command" if the command name is not valid or the callback fails.
◆ getCommandUsage()
| std::string svcs::cli::HelpService::getCommandUsage |
( |
const std::string & | commandName | ) |
const |
|
nodiscard |
Executes the getUsageCallback_ to retrieve the usage syntax of a specific command.
- Parameters
-
| commandName | The name of the command. |
- Returns
- The command usage string, or an empty string if the command is not found or the callback is not set.
◆ showCommandHelp()
| void svcs::cli::HelpService::showCommandHelp |
( |
const std::string & | commandName | ) |
const |
Executes the showHelpCallback_ to trigger the display of detailed help for a specific command.
- Parameters
-
| commandName | The name of the command to show help for. |
The documentation for this class was generated from the following files: