continue amb els ambits
This commit is contained in:
@@ -1032,6 +1032,11 @@ void CommandRegistry::registerHandlers() {
|
||||
dynamic_providers_["SET BGCOLOR"] = color_provider;
|
||||
dynamic_providers_["EDIT MAPBG"] = color_provider;
|
||||
dynamic_providers_["EDIT MAPCONN"] = color_provider;
|
||||
|
||||
// HELP: lista de comandos visibles en el scope activo
|
||||
dynamic_providers_["HELP"] = [this]() -> std::vector<std::string> {
|
||||
return getVisibleKeywords();
|
||||
};
|
||||
dynamic_providers_["SET BORDER"] = color_provider;
|
||||
dynamic_providers_["SET ITEMCOLOR1"] = color_provider;
|
||||
dynamic_providers_["SET ITEMCOLOR2"] = color_provider;
|
||||
@@ -1151,6 +1156,7 @@ void CommandRegistry::load(const std::string& yaml_path) {
|
||||
if (extras.contains("description")) { def.description = extras["description"].get_value<std::string>(); }
|
||||
if (extras.contains("usage")) { def.usage = extras["usage"].get_value<std::string>(); }
|
||||
if (extras.contains("hidden")) { def.hidden = extras["hidden"].get_value<bool>(); }
|
||||
if (extras.contains("help_hidden")) { def.help_hidden = extras["help_hidden"].get_value<bool>(); }
|
||||
if (extras.contains("completions")) {
|
||||
def.completions.clear();
|
||||
auto extras_completions = extras["completions"];
|
||||
@@ -1176,7 +1182,29 @@ void CommandRegistry::load(const std::string& yaml_path) {
|
||||
}
|
||||
|
||||
// Registrar el handler de HELP (captura this)
|
||||
handlers_["cmd_help"] = [this](const std::vector<std::string>&) -> std::string {
|
||||
handlers_["cmd_help"] = [this](const std::vector<std::string>& args) -> std::string {
|
||||
if (!args.empty()) {
|
||||
// HELP <command>: mostrar ayuda detallada de un comando
|
||||
const auto* cmd = findCommand(args[0]);
|
||||
if (cmd != nullptr) {
|
||||
std::string kw_lower = cmd->keyword;
|
||||
std::ranges::transform(kw_lower, kw_lower.begin(), ::tolower);
|
||||
std::string result = kw_lower + ": " + cmd->description + "\n" + cmd->usage;
|
||||
|
||||
// Listar subcomandos/opciones si hay completions
|
||||
auto opts = getCompletions(cmd->keyword);
|
||||
if (!opts.empty()) {
|
||||
result += "\noptions:";
|
||||
for (const auto& opt : opts) {
|
||||
std::string opt_lower = opt;
|
||||
std::ranges::transform(opt_lower, opt_lower.begin(), ::tolower);
|
||||
result += " " + opt_lower;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return "Unknown command: " + args[0];
|
||||
}
|
||||
std::cout << generateTerminalHelp();
|
||||
return generateConsoleHelp();
|
||||
};
|
||||
@@ -1288,6 +1316,15 @@ auto CommandRegistry::generateConsoleHelp() const -> std::string {
|
||||
}
|
||||
|
||||
auto CommandRegistry::getCompletions(const std::string& path) const -> std::vector<std::string> {
|
||||
// Verificar que el comando raíz es visible en el scope activo
|
||||
if (!active_scope_.empty()) {
|
||||
std::string root = path;
|
||||
auto space = root.find(' ');
|
||||
if (space != std::string::npos) { root = root.substr(0, space); }
|
||||
const auto* cmd = findCommand(root);
|
||||
if (cmd != nullptr && !isCommandVisible(*cmd)) { return {}; }
|
||||
}
|
||||
|
||||
// Primero: buscar proveedor dinámico (tiene prioridad si existe)
|
||||
const auto dyn_it = dynamic_providers_.find(path);
|
||||
if (dyn_it != dynamic_providers_.end()) {
|
||||
|
||||
Reference in New Issue
Block a user