Made console command registry a better usage pattern
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sophia {
|
||||
|
||||
class ConsoleCommandRegistry {
|
||||
public:
|
||||
using Handler = std::function<std::string(const std::vector<std::string>&)>;
|
||||
|
||||
struct CommandInfo {
|
||||
std::string name;
|
||||
std::string help;
|
||||
};
|
||||
|
||||
void registerCommand(std::string name, std::string help, Handler handler);
|
||||
|
||||
bool dispatch(const std::string& name, const std::vector<std::string>& args,
|
||||
std::string& outResult) const;
|
||||
|
||||
std::vector<CommandInfo> list() const;
|
||||
|
||||
private:
|
||||
struct Command {
|
||||
std::string help;
|
||||
Handler handler;
|
||||
};
|
||||
|
||||
std::map<std::string, Command> commands;
|
||||
};
|
||||
|
||||
} // namespace sophia
|
||||
Reference in New Issue
Block a user