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

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.
CommandFactoryoperator= (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< ICommandcreateCommand (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.

Detailed Description

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).

Constructor & Destructor Documentation

◆ CommandFactory()

svcs::cli::CommandFactory::CommandFactory ( std::shared_ptr< ISubject > bus,
std::shared_ptr< RepositoryManager > repoManager )
explicit

Constructs the CommandFactory.

Parameters
busA shared pointer to the event bus.
repoManagerA shared pointer to the repository manager.

Member Function Documentation

◆ createCommand()

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.

Parameters
nameThe name of the command (the key in the creators map).
Returns
std::unique_ptr<ICommand> holding a new command object, or nullptr if the command is not registered.

◆ getCommandDescription()

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.

Parameters
nameThe name of the command.
Returns
The command's description string, or an error message if the command is not registered.

◆ getRegisteredCommands()

std::vector< std::string > svcs::cli::CommandFactory::getRegisteredCommands ( ) const

Retrieves a list of names for all currently registered commands.

Returns
A vector of strings containing the names of all registered commands.

◆ registerCommand()

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.

Parameters
nameThe string name under which the command will be callable.
creatorThe function that creates and returns a new ICommand object.

◆ showCommandHelp()

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.

Parameters
nameThe name of the command.

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