Software /
code /
prosody
Comparison
prosodyctl @ 1390:ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 23 Jun 2009 01:50:10 +0100 |
parent | 1205:23a079f50cab |
child | 1458:fce75b4efda9 |
comparison
equal
deleted
inserted
replaced
1389:846df07536eb | 1390:ef672c9fe7c9 |
---|---|
92 ["invalid-hostname"] = "The given hostname is invalid"; | 92 ["invalid-hostname"] = "The given hostname is invalid"; |
93 ["no-password"] = "No password was supplied"; | 93 ["no-password"] = "No password was supplied"; |
94 ["no-such-user"] = "The given user does not exist on the server"; | 94 ["no-such-user"] = "The given user does not exist on the server"; |
95 ["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?"; | 95 ["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?"; |
96 ["no-pidfile"] = "There is no pidfile option in the configuration file, see http://prosody.im/doc/prosodyctl#pidfile for help"; | 96 ["no-pidfile"] = "There is no pidfile option in the configuration file, see http://prosody.im/doc/prosodyctl#pidfile for help"; |
97 ["no-such-method"] = "This module has no commands"; | |
97 }, { __index = function (t,k) return "Error: "..(tostring(k):gsub("%-", " "):gsub("^.", string.upper)); end }); | 98 }, { __index = function (t,k) return "Error: "..(tostring(k):gsub("%-", " "):gsub("^.", string.upper)); end }); |
98 | 99 |
99 hosts = {}; | 100 hosts = {}; |
100 | 101 |
101 require "core.hostmanager" | 102 require "core.hostmanager" |
102 require "core.eventmanager".fire_event("server-starting"); | 103 require "core.eventmanager".fire_event("server-starting"); |
104 require "core.modulemanager" | |
103 | 105 |
104 require "util.prosodyctl" | 106 require "util.prosodyctl" |
105 ----------------------- | 107 ----------------------- |
106 | 108 |
107 function show_message(msg, ...) | 109 function show_message(msg, ...) |
402 end | 404 end |
403 | 405 |
404 | 406 |
405 --------------------- | 407 --------------------- |
406 | 408 |
409 if command:match("^mod_") then -- Is a command in a module | |
410 local module_name = command:match("^mod_(.+)"); | |
411 local ret, err = modulemanager.load("*", module_name); | |
412 if not ret then | |
413 show_message("Failed to load module '"..module_name.."': "..err); | |
414 os.exit(1); | |
415 end | |
416 | |
417 table.remove(arg, 1); | |
418 | |
419 local module = modulemanager.get_module("*", module_name); | |
420 if not module then | |
421 show_message("Failed to load module '"..module_name.."': Unknown error"); | |
422 os.exit(1); | |
423 end | |
424 | |
425 if not modulemanager.module_has_method(module, "command") then | |
426 show_message("Fail: mod_"..module_name.." does not support any commands"); | |
427 os.exit(1); | |
428 end | |
429 | |
430 local ok, ret = modulemanager.call_module_method(module, "command", arg); | |
431 if ok then | |
432 if type(ret) == "number" then | |
433 os.exit(ret); | |
434 elseif type(ret) == "string" then | |
435 show_message(ret); | |
436 end | |
437 os.exit(0); -- :) | |
438 else | |
439 show_message("Failed to execute command: "..error_messages[ret]); | |
440 os.exit(1); -- :( | |
441 end | |
442 end | |
443 | |
407 if not commands[command] then -- Show help for all commands | 444 if not commands[command] then -- Show help for all commands |
408 function show_usage(usage, desc) | 445 function show_usage(usage, desc) |
409 print(" "..usage); | 446 print(" "..usage); |
410 print(" "..desc); | 447 print(" "..desc); |
411 end | 448 end |