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

Factory for creating server administration ICommand objects. More...

#include <ServerCommandFactory.hxx>

Public Member Functions

 ServerCommandFactory (std::shared_ptr< ISubject > bus, std::shared_ptr< RepositoryManager > repoManager)
 Constructs the ServerCommandFactory.
 ServerCommandFactory (const ServerCommandFactory &)=delete
 Deletes the copy constructor. The Server Factory should not be copied.
ServerCommandFactoryoperator= (const ServerCommandFactory &)=delete
 Deletes the assignment operator. The Server 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 server command.
std::string getCommandDescription (const std::string &name) const
 Retrieves the brief description for a registered server command.
void showCommandHelp (const std::string &name) const
 Displays the detailed help and usage for a registered server command.
std::unique_ptr< ICommandcreateCommand (const std::string &name) const
 Creates and returns a server command object by its name.
std::vector< std::string > getRegisteredCommands () const
 Retrieves a list of names for all currently registered server commands.
bool commandExists (const std::string &name) const
 Checks if a server command with the given name exists.

Detailed Description

Factory for creating server administration ICommand objects.

The ServerCommandFactory manages the lifecycle of server-specific 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). This factory is specifically designed for server administration commands that require repository management.

Constructor & Destructor Documentation

◆ ServerCommandFactory()

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

Constructs the ServerCommandFactory.

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

Member Function Documentation

◆ commandExists()

bool svcs::server::cli::ServerCommandFactory::commandExists ( const std::string & name) const

Checks if a server command with the given name exists.

Parameters
nameThe name of the server command to check.
Returns
True if the command exists and can be created, false otherwise.

◆ createCommand()

std::unique_ptr< ICommand > svcs::server::cli::ServerCommandFactory::createCommand ( const std::string & name) const

Creates and returns a server command object by its name.

Transfers ownership (via unique_ptr) of the created object to the caller.

Parameters
nameThe name of the server 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::server::cli::ServerCommandFactory::getCommandDescription ( const std::string & name) const

Retrieves the brief description for a registered server command.

Creates a temporary instance of the command to retrieve its description.

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

◆ getRegisteredCommands()

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

Retrieves a list of names for all currently registered server commands.

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

◆ registerCommand()

void svcs::server::cli::ServerCommandFactory::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 server command.

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

◆ showCommandHelp()

void svcs::server::cli::ServerCommandFactory::showCommandHelp ( const std::string & name) const

Displays the detailed help and usage for a registered server command.

Creates a temporary command instance and calls its showHelp method.

Parameters
nameThe name of the server command.

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