Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 13683:4c1f26b4883b 13.0
mod_admin_shell: Support for hiding certain commands from default help listing
Useful for e.g. deprecated commands.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 13 Feb 2025 16:16:19 +0000 |
| parent | 13681:8f43b954bdac |
| child | 13684:026a75a443de |
comparison
equal
deleted
inserted
replaced
| 13682:0055c177a54c | 13683:4c1f26b4883b |
|---|---|
| 347 event.origin.send(st.stanza("repl-result", { type = "error" }):text(err)); | 347 event.origin.send(st.stanza("repl-result", { type = "error" }):text(err)); |
| 348 end | 348 end |
| 349 return true; | 349 return true; |
| 350 end); | 350 end); |
| 351 | 351 |
| 352 local function describe_command(s) | 352 local function describe_command(s, hidden) |
| 353 local section, name, args, desc = s:match("^([%w_]+):([%w_]+)%(([^)]*)%) %- (.+)$"); | 353 local section, name, args, desc = s:match("^([%w_]+):([%w_]+)%(([^)]*)%) %- (.+)$"); |
| 354 if not section then | 354 if not section then |
| 355 error("Failed to parse command description: "..s); | 355 error("Failed to parse command description: "..s); |
| 356 end | 356 end |
| 357 local command_help = getmetatable(def_env[section]).help.commands; | 357 local command_help = getmetatable(def_env[section]).help.commands; |
| 358 command_help[name] = { | 358 command_help[name] = { |
| 359 desc = desc; | 359 desc = desc; |
| 360 args = array.collect(args:gmatch("[%w_]+")):map(function (arg_name) | 360 args = array.collect(args:gmatch("[%w_]+")):map(function (arg_name) |
| 361 return { name = arg_name }; | 361 return { name = arg_name }; |
| 362 end); | 362 end); |
| 363 hidden = hidden; | |
| 363 }; | 364 }; |
| 364 end | 365 end |
| 365 | 366 |
| 366 -- Console commands -- | 367 -- Console commands -- |
| 367 -- These are simple commands, not valid standalone in Lua | 368 -- These are simple commands, not valid standalone in Lua |
| 453 print(section_help.content); | 454 print(section_help.content); |
| 454 print(""); | 455 print(""); |
| 455 end | 456 end |
| 456 | 457 |
| 457 for command, command_help in it.sorted_pairs(section_help.commands or {}) do | 458 for command, command_help in it.sorted_pairs(section_help.commands or {}) do |
| 458 c = c + 1; | 459 if not command_help.hidden then |
| 459 local args = array.pluck(command_help.args, "name"):concat(", "); | 460 c = c + 1; |
| 460 local desc = command_help.desc or command_help.module and ("Provided by mod_"..command_help.module) or ""; | 461 local args = array.pluck(command_help.args, "name"):concat(", "); |
| 461 print(("%s:%s(%s) - %s"):format(section_name, command, args, desc)); | 462 local desc = command_help.desc or command_help.module and ("Provided by mod_"..command_help.module) or ""; |
| 463 print(("%s:%s(%s) - %s"):format(section_name, command, args, desc)); | |
| 464 end | |
| 462 end | 465 end |
| 463 elseif help_topics[section_name] then | 466 elseif help_topics[section_name] then |
| 464 local topic = help_topics[section_name]; | 467 local topic = help_topics[section_name]; |
| 465 if type(topic.content) == "function" then | 468 if type(topic.content) == "function" then |
| 466 topic.content(self, print); | 469 topic.content(self, print); |