SVCS - English Documentation
Loading...
Searching...
No Matches
HelpService.hxx
Go to the documentation of this file.
1
13#pragma once
14
16
17#include <memory>
18#include <vector>
19#include <string>
20#include <functional>
21
35namespace svcs::cli {
36
37using namespace svcs::services;
54class HelpService {
55private:
63 std::shared_ptr<ISubject> eventBus_;
64
65 // Callback functions instead of direct CommandFactory dependency
66
74 std::function<std::vector<std::string>()> getCommandsCallback_;
75
83 std::function<std::string(const std::string&)> getDescriptionCallback_;
84
92 std::function<void(const std::string&)> showHelpCallback_;
93
101 std::function<std::string(const std::string&)> getUsageCallback_;
102
103public:
121 HelpService(std::shared_ptr<ISubject> bus,
122 std::function<std::vector<std::string>()> getCommands,
123 std::function<std::string(const std::string&)> getDescription,
124 std::function<void(const std::string&)> showHelp,
125 std::function<std::string(const std::string&)> getUsage = nullptr);
126
136 [[nodiscard]] std::vector<std::string> getAvailableCommands() const;
137
149 [[nodiscard]] std::string getCommandDescription(const std::string& commandName) const;
150
160 void showCommandHelp(const std::string& commandName) const;
161
173 [[nodiscard]] bool commandExists(const std::string& commandName) const;
174
186 [[nodiscard]] std::string getCommandUsage(const std::string& commandName) const;
187};
188
189}
Defines the interface for the Subject (Publisher) component of the Observer pattern.
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.
Definition HelpService.cxx:22
std::vector< std::string > getAvailableCommands() const
Executes the getCommandsCallback_ to retrieve the list of all available command names.
Definition HelpService.cxx:34
void showCommandHelp(const std::string &commandName) const
Executes the showHelpCallback_ to trigger the display of detailed help for a specific command.
Definition HelpService.cxx:48
bool commandExists(const std::string &commandName) const
Checks for the existence of a command by comparing against the list returned by getAvailableCommands.
Definition HelpService.cxx:57
std::string getCommandUsage(const std::string &commandName) const
Executes the getUsageCallback_ to retrieve the usage syntax of a specific command.
Definition HelpService.cxx:62
std::string getCommandDescription(const std::string &commandName) const
Executes the getDescriptionCallback_ to retrieve the brief description of a specific command.
Definition HelpService.cxx:41
Command-line interface components and command implementations.