SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::cli::HelpService Class Reference

Service that provides help information for commands. More...

#include <HelpService.hxx>

Inheritance diagram for svcs::cli::HelpService:
svcs::test::cli::mocks::MockHelpServiceAdapter

Public Member Functions

 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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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
busShared pointer to the event bus for notifications.
getCommandsFunction (callback) that returns a list of available command names.
getDescriptionFunction (callback) that returns the brief description of a command.
showHelpFunction (callback) that triggers the full help display for a command.
getUsageFunction (callback) that returns the usage syntax of a command (defaults to nullptr if not strictly needed).

Member Function Documentation

◆ 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
commandNameThe 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
commandNameThe 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
commandNameThe 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
commandNameThe name of the command to show help for.

The documentation for this class was generated from the following files: