|
SVCS - English Documentation
|
Factory for creating ICommand objects by their string name. More...
#include <CommandFactory.hxx>
Public Member Functions | |
| CommandFactory (std::shared_ptr< ISubject > bus, std::shared_ptr< RepositoryManager > repoManager) | |
| Constructs the CommandFactory. | |
| CommandFactory (const CommandFactory &)=delete | |
| Deletes the copy constructor. The Factory should not be copied. | |
| CommandFactory & | operator= (const CommandFactory &)=delete |
| Deletes the assignment operator. The Factory should not be assigned. | |
| void | registerCommand (const std::string &name, std::function< std::unique_ptr< ICommand >(std::shared_ptr< ISubject >, std::shared_ptr< RepositoryManager >)> creator) |
| Registers a creator function for a new command. | |
| std::string | getCommandDescription (const std::string &name) const |
| Retrieves the brief description for a registered command. | |
| void | showCommandHelp (const std::string &name) const |
| Displays the detailed help and usage for a registered command. | |
| std::unique_ptr< ICommand > | createCommand (const std::string &name) const |
| Creates and returns a command object by its name. | |
| std::vector< std::string > | getRegisteredCommands () const |
| Retrieves a list of names for all currently registered commands. | |
Factory for creating ICommand objects by their string name.
The CommandFactory manages the lifecycle of commands, creating them dynamically using creator functions registered under unique names. Commands are constructed with shared ownership of an event bus (ISubject) and a repository manager (RepositoryManager).
|
explicit |
Constructs the CommandFactory.
| bus | A shared pointer to the event bus. |
| repoManager | A shared pointer to the repository manager. |
| std::unique_ptr< ICommand > svcs::cli::CommandFactory::createCommand | ( | const std::string & | name | ) | const |
Creates and returns a command object by its name.
Transfers ownership (via unique_ptr) of the created object to the caller.
| name | The name of the command (the key in the creators map). |
| std::string svcs::cli::CommandFactory::getCommandDescription | ( | const std::string & | name | ) | const |
Retrieves the brief description for a registered command.
To do this, it must create a temporary instance of the command.
| name | The name of the command. |
| std::vector< std::string > svcs::cli::CommandFactory::getRegisteredCommands | ( | ) | const |
Retrieves a list of names for all currently registered commands.
| void svcs::cli::CommandFactory::registerCommand | ( | const std::string & | name, |
| std::function< std::unique_ptr< ICommand >(std::shared_ptr< ISubject >, std::shared_ptr< RepositoryManager >)> | creator ) |
Registers a creator function for a new command.
| name | The string name under which the command will be callable. |
| creator | The function that creates and returns a new ICommand object. |
| void svcs::cli::CommandFactory::showCommandHelp | ( | const std::string & | name | ) | const |
Displays the detailed help and usage for a registered command.
This is accomplished by creating a temporary command instance and calling its showHelp method.
| name | The name of the command. |