SVCS - English Documentation
Loading...
Searching...
No Matches
CommandFactory.hxx
Go to the documentation of this file.
1
13#pragma once
14
18
19#include <memory>
20#include <unordered_map>
21#include <functional>
22#include <string>
23#include <vector>
24
38namespace svcs::cli {
39
40using namespace svcs::core;
57class CommandFactory {
58private:
66 std::shared_ptr<ISubject> event_bus;
67
75 std::shared_ptr<RepositoryManager> repo_manager;
76
90 std::unordered_map<std::string,
91 std::function<std::unique_ptr<ICommand>(std::shared_ptr<ISubject>,
92 std::shared_ptr<RepositoryManager>)>> creators;
103 void registerDefaultCommands();
104
105public:
117 explicit CommandFactory(std::shared_ptr<ISubject> bus,
118 std::shared_ptr<RepositoryManager> repoManager);
119
127 CommandFactory(const CommandFactory&) = delete;
128
136 CommandFactory& operator=(const CommandFactory&) = delete;
137
138
149 void registerCommand(const std::string& name,
150 std::function<std::unique_ptr<ICommand>(std::shared_ptr<ISubject>,
151 std::shared_ptr<RepositoryManager>)> creator);
152
166 std::string getCommandDescription(const std::string& name) const;
167
179 void showCommandHelp(const std::string& name) const;
180
194 std::unique_ptr<ICommand> createCommand(const std::string& name) const;
195
205 std::vector<std::string> getRegisteredCommands() const;
206};
207
208}
Declaration of the ICommand interface for all executable CLI commands.
Defines the interface for the Subject (Publisher) component of the Observer pattern.
Declaration of the RepositoryManager class, managing all repository-level file operations.
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.
Definition CommandFactory.cxx:164
std::string getCommandDescription(const std::string &name) const
Retrieves the brief description for a registered command.
Definition CommandFactory.cxx:147
CommandFactory & operator=(const CommandFactory &)=delete
Deletes the assignment operator. The Factory should not be assigned.
std::unique_ptr< ICommand > createCommand(const std::string &name) const
Creates and returns a command object by its name.
Definition CommandFactory.cxx:171
std::vector< std::string > getRegisteredCommands() const
Retrieves a list of names for all currently registered commands.
Definition CommandFactory.cxx:182
CommandFactory(std::shared_ptr< ISubject > bus, std::shared_ptr< RepositoryManager > repoManager)
Constructs the CommandFactory.
Definition CommandFactory.cxx:41
void showCommandHelp(const std::string &name) const
Displays the detailed help and usage for a registered command.
Definition CommandFactory.cxx:154
Command-line interface components and command implementations.