Comparison

plugins/mod_admin_shell.lua @ 13354:83f3076965f6

mod_admin_shell: Fix linter issues
author Matthew Wild <mwild1@gmail.com>
date Wed, 29 Nov 2023 17:49:20 +0000
parent 13352:b1f5a5531564
child 13473:9eb081616842
comparison
equal deleted inserted replaced
13353:27512ebcc8af 13354:83f3076965f6
301 error("Failed to parse command description: "..s); 301 error("Failed to parse command description: "..s);
302 end 302 end
303 local command_help = getmetatable(def_env[section]).help.commands; 303 local command_help = getmetatable(def_env[section]).help.commands;
304 command_help[name] = { 304 command_help[name] = {
305 desc = desc; 305 desc = desc;
306 args = array.collect(args:gmatch("[%w_]+")):map(function (name) 306 args = array.collect(args:gmatch("[%w_]+")):map(function (arg_name)
307 return { name = name }; 307 return { name = arg_name };
308 end); 308 end);
309 }; 309 };
310 end 310 end
311 311
312 -- Console commands -- 312 -- Console commands --
313 -- These are simple commands, not valid standalone in Lua 313 -- These are simple commands, not valid standalone in Lua
314 314
315 -- Help about individual topics is handled by def_env.help 315 -- Help about individual topics is handled by def_env.help
316 function commands.help(session, data) 316 function commands.help(session, data)
317 local print = session.print; 317 local print = session.print;
318 local section = data:match("^help (%w+)"); 318
319 if not section then 319 local topic = data:match("^help (%w+)");
320 print [[Commands are divided into multiple sections. For help on a particular section, ]] 320 if topic then
321 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]] 321 return def_env.help[topic]({ session = session });
322 print [[]] 322 end
323 local row = format_table({ { title = "Section", width = 7 }, { title = "Description", width = "100%" } }, session.width) 323
324 print(row()) 324 print [[Commands are divided into multiple sections. For help on a particular section, ]]
325 for section_name, section in it.sorted_pairs(def_env) do 325 print [[type: help SECTION (for example, 'help c2s'). Sections are: ]]
326 local section_mt = getmetatable(section); 326 print [[]]
327 local section_help = section_mt and section_mt.help; 327 local row = format_table({ { title = "Section", width = 7 }, { title = "Description", width = "100%" } }, session.width)
328 print(row { section_name; section_help and section_help.desc or "" }); 328 print(row())
329 end 329 for section_name, section in it.sorted_pairs(def_env) do
330 else 330 local section_mt = getmetatable(section);
331 return def_env.help[section]({ session = session }); 331 local section_help = section_mt and section_mt.help;
332 print(row { section_name; section_help and section_help.desc or "" });
332 end 333 end
333 334
334 print(""); 335 print("");
335 336
336 print [[In addition to info about commands, the following general topics are available:]] 337 print [[In addition to info about commands, the following general topics are available:]]
337 338
338 print(""); 339 print("");
339 for topic_name, topic in it.sorted_pairs(help_topics) do 340 for topic_name, topic_info in it.sorted_pairs(help_topics) do
340 print(topic_name .. " - "..topic.desc); 341 print(topic_name .. " - "..topic_info.desc);
341 end 342 end
342 end 343 end
343 344
344 -- Session environment -- 345 -- Session environment --
345 -- Anything in def_env will be accessible within the session as a global variable 346 -- Anything in def_env will be accessible within the session as a global variable
1801 total = total + 1; 1802 total = total + 1;
1802 end 1803 end
1803 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users"; 1804 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users";
1804 end 1805 end
1805 1806
1806 def_env.xmpp = new_section("Commands for sending XMPP stanzas");; 1807 def_env.xmpp = new_section("Commands for sending XMPP stanzas");
1807 1808
1808 describe_command [[xmpp:ping(localhost, remotehost) - Sends a ping to a remote XMPP server and reports the response]] 1809 describe_command [[xmpp:ping(localhost, remotehost) - Sends a ping to a remote XMPP server and reports the response]]
1809 local new_id = require "prosody.util.id".medium; 1810 local new_id = require "prosody.util.id".medium;
1810 function def_env.xmpp:ping(localhost, remotehost, timeout) 1811 function def_env.xmpp:ping(localhost, remotehost, timeout)
1811 localhost = select(2, jid_split(localhost)); 1812 localhost = select(2, jid_split(localhost));
2394 -- Otherwise we get strange stuff like average cpu usage decreasing until 2395 -- Otherwise we get strange stuff like average cpu usage decreasing until
2395 -- the next sample and so on. 2396 -- the next sample and so on.
2396 return setmetatable({ session = self.session, stats = true, now = time.now() }, stats_mt); 2397 return setmetatable({ session = self.session, stats = true, now = time.now() }, stats_mt);
2397 end 2398 end
2398 2399
2399 describe_command [[stats:show(pattern) - Show internal statistics, optionally filtering by name with a pattern. Append :cfgraph() or :histogram() for graphs]] 2400 describe_command [[stats:show(pattern) - Show internal statistics, optionally filtering by name with a pattern.]]
2401 -- Undocumented currently, you can append :histogram() or :cfgraph() to stats:show() for rendered graphs.
2400 function def_env.stats:show(name_filter) 2402 function def_env.stats:show(name_filter)
2401 local statsman = require "prosody.core.statsmanager" 2403 local statsman = require "prosody.core.statsmanager"
2402 local collect = statsman.collect 2404 local collect = statsman.collect
2403 if collect then 2405 if collect then
2404 -- force collection if in manual mode 2406 -- force collection if in manual mode
2482 handler = function (...) 2484 handler = function (...)
2483 local selected_host = select(2, jid_split((select(selector_index, ...)))); 2485 local selected_host = select(2, jid_split((select(selector_index, ...))));
2484 if type(selected_host) ~= "string" then 2486 if type(selected_host) ~= "string" then
2485 return nil, "Invalid or missing argument '"..command.host_selector.."'"; 2487 return nil, "Invalid or missing argument '"..command.host_selector.."'";
2486 end 2488 end
2487 if not hosts[selected_host] then 2489 if not prosody.hosts[selected_host] then
2488 return nil, "Unknown host: "..selected_host; 2490 return nil, "Unknown host: "..selected_host;
2489 end 2491 end
2490 local handler = host_commands[qualified_name][selected_host]; 2492 local host_handler = host_commands[qualified_name][selected_host];
2491 if not handler then 2493 if not host_handler then
2492 return nil, "This command is not available on "..selected_host; 2494 return nil, "This command is not available on "..selected_host;
2493 end 2495 end
2494 return handler(...); 2496 return host_handler(...);
2495 end; 2497 end;
2496 }; 2498 };
2497 }; 2499 };
2498 host_commands[qualified_name] = host_command_info; 2500 host_commands[qualified_name] = host_command_info;
2499 end 2501 end