Comparison

plugins/mod_invites.lua @ 13411:d815882d2692

mod_invites: Show help if --help passed instead of hostname Because I couldn't guess the right way to get the help message without reading the source twice.
author Kim Alvefur <zash@zash.se>
date Sat, 13 Jan 2024 10:59:04 +0100
parent 13410:7efdd143fdfc
child 13412:0e96d6a29a12
comparison
equal deleted inserted replaced
13410:7efdd143fdfc 13411:d815882d2692
247 end 247 end
248 return subcommands[cmd](arg); 248 return subcommands[cmd](arg);
249 end 249 end
250 250
251 function subcommands.generate(arg) 251 function subcommands.generate(arg)
252 252 local function help()
253 local sm = require "prosody.core.storagemanager";
254 local mm = require "prosody.core.modulemanager";
255
256 local host = table.remove(arg, 1); -- pop host
257 assert(prosody.hosts[host], "Host "..tostring(host).." does not exist");
258 sm.initialize_host(host);
259 module.host = host; --luacheck: ignore 122/module
260 token_storage = module:open_store("invite_token", "map");
261
262 local opts = argparse.parse(arg, {
263 short_params = { h = "help"; ["?"] = "help"; g = "group" };
264 value_params = { group = true; reset = true; role = true };
265 array_params = { group = true; role = true };
266 });
267
268
269 if opts.help then
270 print("usage: prosodyctl mod_" .. module.name .. " generate DOMAIN --reset USERNAME") 253 print("usage: prosodyctl mod_" .. module.name .. " generate DOMAIN --reset USERNAME")
271 print("usage: prosodyctl mod_" .. module.name .. " generate DOMAIN [--admin] [--role ROLE] [--group GROUPID]...") 254 print("usage: prosodyctl mod_" .. module.name .. " generate DOMAIN [--admin] [--role ROLE] [--group GROUPID]...")
272 print() 255 print()
273 print("This command has two modes: password reset and new account.") 256 print("This command has two modes: password reset and new account.")
274 print("If --reset is given, the command operates in password reset mode and in new account mode otherwise.") 257 print("If --reset is given, the command operates in password reset mode and in new account mode otherwise.")
290 print() 273 print()
291 print("--reset and the other options cannot be mixed.") 274 print("--reset and the other options cannot be mixed.")
292 return 2 275 return 2
293 end 276 end
294 277
278 local earlyopts = argparse.parse(arg, { short_params = { h = "help"; ["?"] = "help" } });
279 if earlyopts.help or next(earlyopts) ~= nil then
280 return help();
281 end
282
283 local sm = require "prosody.core.storagemanager";
284 local mm = require "prosody.core.modulemanager";
285
286 local host = table.remove(arg, 1); -- pop host
287 assert(prosody.hosts[host], "Host "..tostring(host).." does not exist");
288 sm.initialize_host(host);
289 module.host = host; --luacheck: ignore 122/module
290 token_storage = module:open_store("invite_token", "map");
291
292 local opts = argparse.parse(arg, {
293 short_params = { h = "help"; ["?"] = "help"; g = "group" };
294 value_params = { group = true; reset = true; role = true };
295 array_params = { group = true; role = true };
296 });
297
298 if opts.help then
299 return help();
300 end
301
295 -- Load mod_invites 302 -- Load mod_invites
296 local invites = module:depends("invites"); 303 local invites = module:depends("invites");
297 -- Optional community module that if used, needs to be loaded here 304 -- Optional community module that if used, needs to be loaded here
298 local invites_page_module = module:get_option_string("invites_page_module", "invites_page"); 305 local invites_page_module = module:get_option_string("invites_page_module", "invites_page");
299 if mm.get_modules_for_host(host):contains(invites_page_module) then 306 if mm.get_modules_for_host(host):contains(invites_page_module) then