diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2019-08-30 16:42:28 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-09-03 15:00:01 -0300 |
commit | b9c4095511d8048910fbcb67865ec6eb86283bc6 (patch) | |
tree | 3e0e42fecaea919cd7f4289f11c9537a1d7f58d5 | |
parent | ccf92207e1092ae339b74454168acca79af72d0e (diff) | |
download | luarocks-b9c4095511d8048910fbcb67865ec6eb86283bc6.tar.gz luarocks-b9c4095511d8048910fbcb67865ec6eb86283bc6.tar.bz2 luarocks-b9c4095511d8048910fbcb67865ec6eb86283bc6.zip |
cmd: catch errors loading command modules
This should be useful for external modules.
-rw-r--r-- | src/luarocks/cmd.lua | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 328afe3f..eba5e9a8 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
@@ -460,19 +460,30 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
460 | 460 | ||
461 | local cmd_modules = {} | 461 | local cmd_modules = {} |
462 | for name, module in pairs(commands) do | 462 | for name, module in pairs(commands) do |
463 | cmd_modules[name] = require(module) | 463 | local pok, mod = pcall(require, module) |
464 | if not cmd_modules[name].add_to_parser then | 464 | if pok and type(mod) == "table" then |
465 | cmd_modules[name].add_to_parser = function(parser) | 465 | if not mod.add_to_parser then |
466 | parser:command(name, cmd_modules[name].help, util.see_also()) | 466 | mod.add_to_parser = function(parser) |
467 | :summary(cmd_modules[name].help_summary) | 467 | parser:command(name, mod.help, util.see_also()) |
468 | :handle_options(false) | 468 | :summary(mod.help_summary) |
469 | :argument("input") | 469 | :handle_options(false) |
470 | :args("*") | 470 | :argument("input") |
471 | :args("*") | ||
472 | end | ||
473 | local original_command = mod.command | ||
474 | if original_command then | ||
475 | mod.command = function(args) | ||
476 | return original_command(args, unpack(args.input)) | ||
477 | end | ||
478 | end | ||
471 | end | 479 | end |
472 | local original_command = cmd_modules[name].command | 480 | if mod.command then |
473 | cmd_modules[name].command = function(args) | 481 | cmd_modules[name] = mod |
474 | return original_command(args, unpack(args.input)) | 482 | else |
483 | util.warning("command module " .. module .. " does not implement command(), skipping") | ||
475 | end | 484 | end |
485 | else | ||
486 | util.warning("failed to load command module " .. module) | ||
476 | end | 487 | end |
477 | end | 488 | end |
478 | 489 | ||