Made console command registry a better usage pattern

This commit is contained in:
2026-09-16 01:59:18 -07:00
parent 8824f64225
commit 169ff4a277
8 changed files with 131 additions and 33 deletions
@@ -0,0 +1,31 @@
#include <sophia/console/console_command_registry.hpp>
namespace sophia {
void ConsoleCommandRegistry::registerCommand(std::string name, std::string help,
Handler handler) {
commands[std::move(name)] = Command{std::move(help), std::move(handler)};
}
bool ConsoleCommandRegistry::dispatch(const std::string& name,
const std::vector<std::string>& args,
std::string& outResult) const {
auto it = commands.find(name);
if (it == commands.end()) {
return false;
}
outResult = it->second.handler(args);
return true;
}
std::vector<ConsoleCommandRegistry::CommandInfo> ConsoleCommandRegistry::list()
const {
std::vector<CommandInfo> result;
result.reserve(commands.size());
for (const auto& [name, command] : commands) {
result.push_back(CommandInfo{name, command.help});
}
return result;
}
} // namespace sophia