Comparison

plugins/mod_invites.lua @ 13412:0e96d6a29a12

mod_invites: Show short help instead of traceback on missing hostname
author Kim Alvefur <zash@zash.se>
date Sat, 13 Jan 2024 11:00:20 +0100
parent 13411:d815882d2692
child 13413:992389af2372
comparison
equal deleted inserted replaced
13411:d815882d2692 13412:0e96d6a29a12
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 local function help() 252 local function help(short)
253 print("usage: prosodyctl mod_" .. module.name .. " generate DOMAIN --reset USERNAME") 253 print("usage: prosodyctl mod_" .. module.name .. " generate DOMAIN --reset USERNAME")
254 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]...")
255 if short then return 2 end
255 print() 256 print()
256 print("This command has two modes: password reset and new account.") 257 print("This command has two modes: password reset and new account.")
257 print("If --reset is given, the command operates in password reset mode and in new account mode otherwise.") 258 print("If --reset is given, the command operates in password reset mode and in new account mode otherwise.")
258 print() 259 print()
259 print("required arguments in password reset mode:") 260 print("required arguments in password reset mode:")
282 283
283 local sm = require "prosody.core.storagemanager"; 284 local sm = require "prosody.core.storagemanager";
284 local mm = require "prosody.core.modulemanager"; 285 local mm = require "prosody.core.modulemanager";
285 286
286 local host = table.remove(arg, 1); -- pop host 287 local host = table.remove(arg, 1); -- pop host
287 assert(prosody.hosts[host], "Host "..tostring(host).." does not exist"); 288 if not host then return help(true) end
288 sm.initialize_host(host); 289 sm.initialize_host(host);
289 module.host = host; --luacheck: ignore 122/module 290 module.host = host; --luacheck: ignore 122/module
290 token_storage = module:open_store("invite_token", "map"); 291 token_storage = module:open_store("invite_token", "map");
291 292
292 local opts = argparse.parse(arg, { 293 local opts = argparse.parse(arg, {