From e0af9ea7a7d7ba2aba76f975bf0d1c9965649ab8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 19 Jun 2018 11:09:39 -0300 Subject: cmd: new command-line initialization sequence --- src/bin/luarocks | 6 +++--- src/bin/luarocks-admin | 9 +++------ src/luarocks/cmd.lua | 4 ++-- src/luarocks/cmd/help.lua | 11 +++++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/bin/luarocks b/src/bin/luarocks index d776445c..d0df0532 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -6,9 +6,9 @@ local cfg = require("luarocks.core.cfg") local loader = require("luarocks.loader") local cmd = require("luarocks.cmd") -program_description = "LuaRocks main command-line interface" +local description = "LuaRocks main command-line interface" -commands = { +local commands = { help = "luarocks.cmd.help", init = "luarocks.cmd.init", pack = "luarocks.cmd.pack", @@ -33,4 +33,4 @@ commands = { test = "luarocks.cmd.test", } -cmd.run_command(...) +cmd.run_command(description, commands, ...) diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index 4521ac26..e27b8c01 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin @@ -1,14 +1,11 @@ #!/usr/bin/env lua --- this should be loaded first. -local cfg = require("luarocks.core.cfg") - local loader = require("luarocks.loader") local cmd = require("luarocks.cmd") -program_description = "LuaRocks repository administration interface" +local description = "LuaRocks repository administration interface" -commands = { +local commands = { help = "luarocks.cmd.help", make_manifest = "luarocks.admin.cmd.make_manifest", add = "luarocks.admin.cmd.add", @@ -16,4 +13,4 @@ commands = { refresh_cache = "luarocks.admin.cmd.refresh_cache", } -cmd.run_command(...) +cmd.run_command(description, commands, ...) diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index cedeed22..1b069d59 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -80,7 +80,7 @@ end -- Uses the global table "commands", which contains -- the loaded modules representing commands. -- @param ... string: Arguments given on the command-line. -function cmd.run_command(...) +function cmd.run_command(description, commands, ...) local args = {...} local cmdline_vars = {} for i = #args, 1, -1 do @@ -131,7 +131,7 @@ function cmd.run_command(...) if flags["version"] then util.printout(program.." "..cfg.program_version) - util.printout(program_description) + util.printout(description) util.printout() os.exit(cmd.errorcodes.OK) elseif flags["help"] or #nonflags == 0 then diff --git a/src/luarocks/cmd/help.lua b/src/luarocks/cmd/help.lua index 9e11ad87..1e1d8676 100644 --- a/src/luarocks/cmd/help.lua +++ b/src/luarocks/cmd/help.lua @@ -40,12 +40,15 @@ end -- given, help summaries for all commands are shown. -- @return boolean or (nil, string): true if there were no errors -- or nil and an error message if an invalid command was requested. -function help.command(flags, command) +function help.command(description, commands, command) + assert(type(description) == "string") + assert(type(commands) == "table") + if not command then local conf = cfg.which_config() print_banner() print_section("NAME") - util.printout("\t"..program..[[ - ]]..program_description) + util.printout("\t"..program..[[ - ]]..description) print_section("SYNOPSIS") util.printout("\t"..program..[[ [] [VAR=VALUE]... [] ]]) print_section("GENERAL OPTIONS") @@ -72,8 +75,8 @@ function help.command(flags, command) Variables from the "variables" table of the configuration file can be overriden with VAR=VALUE assignments.]]) print_section("COMMANDS") - for name, command in util.sortedpairs(commands) do - local cmd = require(command) + for name, modname in util.sortedpairs(commands) do + local cmd = require(modname) util.printout("", name) util.printout("\t", cmd.help_summary) end -- cgit v1.2.3-55-g6feb