diff options
-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 | ||