diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-19 11:09:39 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 15:51:13 -0300 |
commit | e0af9ea7a7d7ba2aba76f975bf0d1c9965649ab8 (patch) | |
tree | 27279d0e330d2a4d11cd5163a639ec3921ef215b | |
parent | 10ee65ec23a9b107c712bd7b017083c9a5571b0c (diff) | |
download | luarocks-e0af9ea7a7d7ba2aba76f975bf0d1c9965649ab8.tar.gz luarocks-e0af9ea7a7d7ba2aba76f975bf0d1c9965649ab8.tar.bz2 luarocks-e0af9ea7a7d7ba2aba76f975bf0d1c9965649ab8.zip |
cmd: new command-line initialization sequence
-rwxr-xr-x | src/bin/luarocks | 6 | ||||
-rwxr-xr-x | src/bin/luarocks-admin | 9 | ||||
-rw-r--r-- | src/luarocks/cmd.lua | 4 | ||||
-rw-r--r-- | 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") | |||
6 | local loader = require("luarocks.loader") | 6 | local loader = require("luarocks.loader") |
7 | local cmd = require("luarocks.cmd") | 7 | local cmd = require("luarocks.cmd") |
8 | 8 | ||
9 | program_description = "LuaRocks main command-line interface" | 9 | local description = "LuaRocks main command-line interface" |
10 | 10 | ||
11 | commands = { | 11 | local commands = { |
12 | help = "luarocks.cmd.help", | 12 | help = "luarocks.cmd.help", |
13 | init = "luarocks.cmd.init", | 13 | init = "luarocks.cmd.init", |
14 | pack = "luarocks.cmd.pack", | 14 | pack = "luarocks.cmd.pack", |
@@ -33,4 +33,4 @@ commands = { | |||
33 | test = "luarocks.cmd.test", | 33 | test = "luarocks.cmd.test", |
34 | } | 34 | } |
35 | 35 | ||
36 | cmd.run_command(...) | 36 | 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 @@ | |||
1 | #!/usr/bin/env lua | 1 | #!/usr/bin/env lua |
2 | 2 | ||
3 | -- this should be loaded first. | ||
4 | local cfg = require("luarocks.core.cfg") | ||
5 | |||
6 | local loader = require("luarocks.loader") | 3 | local loader = require("luarocks.loader") |
7 | local cmd = require("luarocks.cmd") | 4 | local cmd = require("luarocks.cmd") |
8 | 5 | ||
9 | program_description = "LuaRocks repository administration interface" | 6 | local description = "LuaRocks repository administration interface" |
10 | 7 | ||
11 | commands = { | 8 | local commands = { |
12 | help = "luarocks.cmd.help", | 9 | help = "luarocks.cmd.help", |
13 | make_manifest = "luarocks.admin.cmd.make_manifest", | 10 | make_manifest = "luarocks.admin.cmd.make_manifest", |
14 | add = "luarocks.admin.cmd.add", | 11 | add = "luarocks.admin.cmd.add", |
@@ -16,4 +13,4 @@ commands = { | |||
16 | refresh_cache = "luarocks.admin.cmd.refresh_cache", | 13 | refresh_cache = "luarocks.admin.cmd.refresh_cache", |
17 | } | 14 | } |
18 | 15 | ||
19 | cmd.run_command(...) | 16 | 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 | |||
80 | -- Uses the global table "commands", which contains | 80 | -- Uses the global table "commands", which contains |
81 | -- the loaded modules representing commands. | 81 | -- the loaded modules representing commands. |
82 | -- @param ... string: Arguments given on the command-line. | 82 | -- @param ... string: Arguments given on the command-line. |
83 | function cmd.run_command(...) | 83 | function cmd.run_command(description, commands, ...) |
84 | local args = {...} | 84 | local args = {...} |
85 | local cmdline_vars = {} | 85 | local cmdline_vars = {} |
86 | for i = #args, 1, -1 do | 86 | for i = #args, 1, -1 do |
@@ -131,7 +131,7 @@ function cmd.run_command(...) | |||
131 | 131 | ||
132 | if flags["version"] then | 132 | if flags["version"] then |
133 | util.printout(program.." "..cfg.program_version) | 133 | util.printout(program.." "..cfg.program_version) |
134 | util.printout(program_description) | 134 | util.printout(description) |
135 | util.printout() | 135 | util.printout() |
136 | os.exit(cmd.errorcodes.OK) | 136 | os.exit(cmd.errorcodes.OK) |
137 | elseif flags["help"] or #nonflags == 0 then | 137 | 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 | |||
40 | -- given, help summaries for all commands are shown. | 40 | -- given, help summaries for all commands are shown. |
41 | -- @return boolean or (nil, string): true if there were no errors | 41 | -- @return boolean or (nil, string): true if there were no errors |
42 | -- or nil and an error message if an invalid command was requested. | 42 | -- or nil and an error message if an invalid command was requested. |
43 | function help.command(flags, command) | 43 | function help.command(description, commands, command) |
44 | assert(type(description) == "string") | ||
45 | assert(type(commands) == "table") | ||
46 | |||
44 | if not command then | 47 | if not command then |
45 | local conf = cfg.which_config() | 48 | local conf = cfg.which_config() |
46 | print_banner() | 49 | print_banner() |
47 | print_section("NAME") | 50 | print_section("NAME") |
48 | util.printout("\t"..program..[[ - ]]..program_description) | 51 | util.printout("\t"..program..[[ - ]]..description) |
49 | print_section("SYNOPSIS") | 52 | print_section("SYNOPSIS") |
50 | util.printout("\t"..program..[[ [<flags...>] [VAR=VALUE]... <command> [<argument>] ]]) | 53 | util.printout("\t"..program..[[ [<flags...>] [VAR=VALUE]... <command> [<argument>] ]]) |
51 | print_section("GENERAL OPTIONS") | 54 | print_section("GENERAL OPTIONS") |
@@ -72,8 +75,8 @@ function help.command(flags, command) | |||
72 | Variables from the "variables" table of the configuration file | 75 | Variables from the "variables" table of the configuration file |
73 | can be overriden with VAR=VALUE assignments.]]) | 76 | can be overriden with VAR=VALUE assignments.]]) |
74 | print_section("COMMANDS") | 77 | print_section("COMMANDS") |
75 | for name, command in util.sortedpairs(commands) do | 78 | for name, modname in util.sortedpairs(commands) do |
76 | local cmd = require(command) | 79 | local cmd = require(modname) |
77 | util.printout("", name) | 80 | util.printout("", name) |
78 | util.printout("\t", cmd.help_summary) | 81 | util.printout("\t", cmd.help_summary) |
79 | end | 82 | end |