diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-06-03 11:16:55 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-06-03 11:58:47 +0300 |
commit | d55041dbc477000d0aa8a1585824958b0ade66a1 (patch) | |
tree | 99e2d28a30da52973fbc9caf2817f5fdf5c5fe19 | |
parent | d524b515c67ceded00a15c2617283f81a2f21f7c (diff) | |
download | luarocks-d55041dbc477000d0aa8a1585824958b0ade66a1.tar.gz luarocks-d55041dbc477000d0aa8a1585824958b0ade66a1.tar.bz2 luarocks-d55041dbc477000d0aa8a1585824958b0ade66a1.zip |
Refactor CLI to avoid double args parsing
New command module interface: instead of 'run' function
they must have 'command' function that accepts flags table
and other arguments. For compatibility a new util function
is called on all command modules: it adds 'run' function
that parses command-line args before passing them to 'command'.
-rw-r--r-- | src/luarocks/add.lua | 6 | ||||
-rw-r--r-- | src/luarocks/admin_remove.lua | 6 | ||||
-rw-r--r-- | src/luarocks/build.lua | 4 | ||||
-rw-r--r-- | src/luarocks/command_line.lua | 37 | ||||
-rw-r--r-- | src/luarocks/config_cmd.lua | 5 | ||||
-rw-r--r-- | src/luarocks/doc.lua | 4 | ||||
-rw-r--r-- | src/luarocks/download.lua | 5 | ||||
-rw-r--r-- | src/luarocks/help.lua | 5 | ||||
-rw-r--r-- | src/luarocks/install.lua | 4 | ||||
-rw-r--r-- | src/luarocks/lint.lua | 5 | ||||
-rw-r--r-- | src/luarocks/list.lua | 4 | ||||
-rw-r--r-- | src/luarocks/make.lua | 4 | ||||
-rw-r--r-- | src/luarocks/make_manifest.lua | 5 | ||||
-rw-r--r-- | src/luarocks/new_version.lua | 4 | ||||
-rw-r--r-- | src/luarocks/pack.lua | 4 | ||||
-rw-r--r-- | src/luarocks/path_cmd.lua | 4 | ||||
-rw-r--r-- | src/luarocks/purge.lua | 5 | ||||
-rw-r--r-- | src/luarocks/refresh_cache.lua | 4 | ||||
-rw-r--r-- | src/luarocks/remove.lua | 5 | ||||
-rw-r--r-- | src/luarocks/search.lua | 5 | ||||
-rw-r--r-- | src/luarocks/show.lua | 5 | ||||
-rw-r--r-- | src/luarocks/unpack.lua | 5 | ||||
-rw-r--r-- | src/luarocks/upload.lua | 4 | ||||
-rw-r--r-- | src/luarocks/util.lua | 7 | ||||
-rw-r--r-- | src/luarocks/validate.lua | 4 | ||||
-rw-r--r-- | src/luarocks/write_rockspec.lua | 5 |
26 files changed, 64 insertions, 91 deletions
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index bea2d861..f37d334d 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua | |||
@@ -12,6 +12,7 @@ local index = require("luarocks.index") | |||
12 | local fs = require("luarocks.fs") | 12 | local fs = require("luarocks.fs") |
13 | local cache = require("luarocks.cache") | 13 | local cache = require("luarocks.cache") |
14 | 14 | ||
15 | util.add_run_function(add) | ||
15 | add.help_summary = "Add a rock or rockspec to a rocks server." | 16 | add.help_summary = "Add a rock or rockspec to a rocks server." |
16 | add.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" | 17 | add.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" |
17 | add.help = [[ | 18 | add.help = [[ |
@@ -107,9 +108,8 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) | |||
107 | return true | 108 | return true |
108 | end | 109 | end |
109 | 110 | ||
110 | function add.run(...) | 111 | function add.command(flags, ...) |
111 | local files = { util.parse_flags(...) } | 112 | local files = {...} |
112 | local flags = table.remove(files, 1) | ||
113 | if #files < 1 then | 113 | if #files < 1 then |
114 | return nil, "Argument missing. "..util.see_help("add", "luarocks-admin") | 114 | return nil, "Argument missing. "..util.see_help("add", "luarocks-admin") |
115 | end | 115 | end |
diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua index 59ca4975..621f1317 100644 --- a/src/luarocks/admin_remove.lua +++ b/src/luarocks/admin_remove.lua | |||
@@ -12,6 +12,7 @@ local index = require("luarocks.index") | |||
12 | local fs = require("luarocks.fs") | 12 | local fs = require("luarocks.fs") |
13 | local cache = require("luarocks.cache") | 13 | local cache = require("luarocks.cache") |
14 | 14 | ||
15 | util.add_run_function(admin_remove) | ||
15 | admin_remove.help_summary = "Remove a rock or rockspec from a rocks server." | 16 | admin_remove.help_summary = "Remove a rock or rockspec from a rocks server." |
16 | admin_remove.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" | 17 | admin_remove.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" |
17 | admin_remove.help = [[ | 18 | admin_remove.help = [[ |
@@ -77,9 +78,8 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve | |||
77 | return true | 78 | return true |
78 | end | 79 | end |
79 | 80 | ||
80 | function admin_remove.run(...) | 81 | function admin_remove.command(flags, ...) |
81 | local files = { util.parse_flags(...) } | 82 | local files = {...} |
82 | local flags = table.remove(files, 1) | ||
83 | if #files < 1 then | 83 | if #files < 1 then |
84 | return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin") | 84 | return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin") |
85 | end | 85 | end |
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index edf4efb4..0e72ca85 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -16,6 +16,7 @@ local manif = require("luarocks.manif") | |||
16 | local remove = require("luarocks.remove") | 16 | local remove = require("luarocks.remove") |
17 | local cfg = require("luarocks.cfg") | 17 | local cfg = require("luarocks.cfg") |
18 | 18 | ||
19 | util.add_run_function(build) | ||
19 | build.help_summary = "Build/compile a rock." | 20 | build.help_summary = "Build/compile a rock." |
20 | build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}" | 21 | build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}" |
21 | build.help = [[ | 22 | build.help = [[ |
@@ -390,8 +391,7 @@ end | |||
390 | -- also be given. | 391 | -- also be given. |
391 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an | 392 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an |
392 | -- error message otherwise. exitcode is optionally returned. | 393 | -- error message otherwise. exitcode is optionally returned. |
393 | function build.run(...) | 394 | function build.command(flags, name, version) |
394 | local flags, name, version = util.parse_flags(...) | ||
395 | if type(name) ~= "string" then | 395 | if type(name) ~= "string" then |
396 | return nil, "Argument missing. "..util.see_help("build") | 396 | return nil, "Argument missing. "..util.see_help("build") |
397 | end | 397 | end |
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index b3284534..1a8c0fe7 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
@@ -27,20 +27,9 @@ local function die(message, exitcode) | |||
27 | os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) | 27 | os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) |
28 | end | 28 | end |
29 | 29 | ||
30 | local function replace_tree(flags, args, tree) | 30 | local function replace_tree(flags, tree) |
31 | tree = dir.normalize(tree) | 31 | tree = dir.normalize(tree) |
32 | flags["tree"] = tree | 32 | flags["tree"] = tree |
33 | local added = false | ||
34 | for i = 1, #args do | ||
35 | if args[i]:match("%-%-tree=") then | ||
36 | args[i] = "--tree="..tree | ||
37 | added = true | ||
38 | break | ||
39 | end | ||
40 | end | ||
41 | if not added then | ||
42 | args[#args + 1] = "--tree="..tree | ||
43 | end | ||
44 | path.use_tree(tree) | 33 | path.use_tree(tree) |
45 | end | 34 | end |
46 | 35 | ||
@@ -78,7 +67,6 @@ function command_line.run_command(...) | |||
78 | if flags["to"] then flags["tree"] = flags["to"] end | 67 | if flags["to"] then flags["tree"] = flags["to"] end |
79 | if flags["nodeps"] then | 68 | if flags["nodeps"] then |
80 | flags["deps-mode"] = "none" | 69 | flags["deps-mode"] = "none" |
81 | table.insert(args, "--deps-mode=none") | ||
82 | end | 70 | end |
83 | 71 | ||
84 | cfg.flags = flags | 72 | cfg.flags = flags |
@@ -106,15 +94,8 @@ function command_line.run_command(...) | |||
106 | os.exit(cfg.errorcodes.OK) | 94 | os.exit(cfg.errorcodes.OK) |
107 | elseif flags["help"] or #nonflags == 0 then | 95 | elseif flags["help"] or #nonflags == 0 then |
108 | command = "help" | 96 | command = "help" |
109 | args = nonflags | ||
110 | else | 97 | else |
111 | command = nonflags[1] | 98 | command = table.remove(nonflags, 1) |
112 | for i, arg in ipairs(args) do | ||
113 | if arg == command then | ||
114 | table.remove(args, i) | ||
115 | break | ||
116 | end | ||
117 | end | ||
118 | end | 99 | end |
119 | command = command:gsub("-", "_") | 100 | command = command:gsub("-", "_") |
120 | 101 | ||
@@ -137,14 +118,14 @@ function command_line.run_command(...) | |||
137 | if not tree.root then | 118 | if not tree.root then |
138 | die("Configuration error: tree '"..tree.name.."' has no 'root' field.") | 119 | die("Configuration error: tree '"..tree.name.."' has no 'root' field.") |
139 | end | 120 | end |
140 | replace_tree(flags, args, tree.root) | 121 | replace_tree(flags, tree.root) |
141 | named = true | 122 | named = true |
142 | break | 123 | break |
143 | end | 124 | end |
144 | end | 125 | end |
145 | if not named then | 126 | if not named then |
146 | local root_dir = fs.absolute_name(flags["tree"]) | 127 | local root_dir = fs.absolute_name(flags["tree"]) |
147 | replace_tree(flags, args, root_dir) | 128 | replace_tree(flags, root_dir) |
148 | end | 129 | end |
149 | elseif flags["local"] then | 130 | elseif flags["local"] then |
150 | if not cfg.home_tree then | 131 | if not cfg.home_tree then |
@@ -152,7 +133,7 @@ function command_line.run_command(...) | |||
152 | "You are running as a superuser, which is intended for system-wide operation.\n".. | 133 | "You are running as a superuser, which is intended for system-wide operation.\n".. |
153 | "To force using the superuser's home, use --tree explicitly.") | 134 | "To force using the superuser's home, use --tree explicitly.") |
154 | end | 135 | end |
155 | replace_tree(flags, args, cfg.home_tree) | 136 | replace_tree(flags, cfg.home_tree) |
156 | else | 137 | else |
157 | local trees = cfg.rocks_trees | 138 | local trees = cfg.rocks_trees |
158 | path.use_tree(trees[#trees]) | 139 | path.use_tree(trees[#trees]) |
@@ -195,14 +176,8 @@ function command_line.run_command(...) | |||
195 | end | 176 | end |
196 | 177 | ||
197 | if commands[command] then | 178 | if commands[command] then |
198 | -- TODO the interface of run should be modified, to receive the | ||
199 | -- flags table and the (possibly unpacked) nonflags arguments. | ||
200 | -- This would remove redundant parsing of arguments. | ||
201 | -- I'm not changing this now to avoid messing with the run() | ||
202 | -- interface, which I know some people use (even though | ||
203 | -- I never published it as a public API...) | ||
204 | local cmd = require(commands[command]) | 179 | local cmd = require(commands[command]) |
205 | local xp, ok, err, exitcode = xpcall(function() return cmd.run(unpack(args)) end, function(err) | 180 | local xp, ok, err, exitcode = xpcall(function() return cmd.command(flags, unpack(nonflags)) end, function(err) |
206 | die(debug.traceback("LuaRocks "..cfg.program_version | 181 | die(debug.traceback("LuaRocks "..cfg.program_version |
207 | .." bug (please report at https://github.com/keplerproject/luarocks/issues).\n" | 182 | .." bug (please report at https://github.com/keplerproject/luarocks/issues).\n" |
208 | ..err, 2), cfg.errorcodes.CRASH) | 183 | ..err, 2), cfg.errorcodes.CRASH) |
diff --git a/src/luarocks/config_cmd.lua b/src/luarocks/config_cmd.lua index bf282a7a..fe3cc637 100644 --- a/src/luarocks/config_cmd.lua +++ b/src/luarocks/config_cmd.lua | |||
@@ -6,6 +6,7 @@ local cfg = require("luarocks.cfg") | |||
6 | local util = require("luarocks.util") | 6 | local util = require("luarocks.util") |
7 | local dir = require("luarocks.dir") | 7 | local dir = require("luarocks.dir") |
8 | 8 | ||
9 | util.add_run_function(config_cmd) | ||
9 | config_cmd.help_summary = "Query information about the LuaRocks configuration." | 10 | config_cmd.help_summary = "Query information about the LuaRocks configuration." |
10 | config_cmd.help_arguments = "<flag>" | 11 | config_cmd.help_arguments = "<flag>" |
11 | config_cmd.help = [[ | 12 | config_cmd.help = [[ |
@@ -33,9 +34,7 @@ end | |||
33 | 34 | ||
34 | --- Driver function for "config" command. | 35 | --- Driver function for "config" command. |
35 | -- @return boolean: True if succeeded, nil on errors. | 36 | -- @return boolean: True if succeeded, nil on errors. |
36 | function config_cmd.run(...) | 37 | function config_cmd.command(flags) |
37 | local flags = util.parse_flags(...) | ||
38 | |||
39 | if flags["lua-incdir"] then | 38 | if flags["lua-incdir"] then |
40 | print(cfg.variables.LUA_INCDIR) | 39 | print(cfg.variables.LUA_INCDIR) |
41 | return true | 40 | return true |
diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index 62e80232..ec2b1110 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua | |||
@@ -12,6 +12,7 @@ local fetch = require("luarocks.fetch") | |||
12 | local fs = require("luarocks.fs") | 12 | local fs = require("luarocks.fs") |
13 | local download = require("luarocks.download") | 13 | local download = require("luarocks.download") |
14 | 14 | ||
15 | util.add_run_function(doc) | ||
15 | doc.help_summary = "Show documentation for an installed rock." | 16 | doc.help_summary = "Show documentation for an installed rock." |
16 | 17 | ||
17 | doc.help = [[ | 18 | doc.help = [[ |
@@ -57,8 +58,7 @@ end | |||
57 | -- @param name or nil: an existing package name. | 58 | -- @param name or nil: an existing package name. |
58 | -- @param version string or nil: a version may also be passed. | 59 | -- @param version string or nil: a version may also be passed. |
59 | -- @return boolean: True if succeeded, nil on errors. | 60 | -- @return boolean: True if succeeded, nil on errors. |
60 | function doc.run(...) | 61 | function doc.command(flags, name, version) |
61 | local flags, name, version = util.parse_flags(...) | ||
62 | if not name then | 62 | if not name then |
63 | return nil, "Argument missing. "..util.see_help("doc") | 63 | return nil, "Argument missing. "..util.see_help("doc") |
64 | end | 64 | end |
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 181aca75..2e434b03 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua | |||
@@ -12,6 +12,7 @@ local fs = require("luarocks.fs") | |||
12 | local dir = require("luarocks.dir") | 12 | local dir = require("luarocks.dir") |
13 | local cfg = require("luarocks.cfg") | 13 | local cfg = require("luarocks.cfg") |
14 | 14 | ||
15 | util.add_run_function(download) | ||
15 | download.help_summary = "Download a specific rock file from a rocks server." | 16 | download.help_summary = "Download a specific rock file from a rocks server." |
16 | download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" | 17 | download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" |
17 | 18 | ||
@@ -84,9 +85,7 @@ end | |||
84 | -- version may also be passed. | 85 | -- version may also be passed. |
85 | -- @return boolean or (nil, string): true if successful or nil followed | 86 | -- @return boolean or (nil, string): true if successful or nil followed |
86 | -- by an error message. | 87 | -- by an error message. |
87 | function download.run(...) | 88 | function download.command(flags, name, version) |
88 | local flags, name, version = util.parse_flags(...) | ||
89 | |||
90 | assert(type(version) == "string" or not version) | 89 | assert(type(version) == "string" or not version) |
91 | if type(name) ~= "string" and not flags["all"] then | 90 | if type(name) ~= "string" and not flags["all"] then |
92 | return nil, "Argument missing, see help." | 91 | return nil, "Argument missing, see help." |
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 0f66f64b..28f97702 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
@@ -12,6 +12,7 @@ local dir = require("luarocks.dir") | |||
12 | 12 | ||
13 | local program = util.this_program("luarocks") | 13 | local program = util.this_program("luarocks") |
14 | 14 | ||
15 | util.add_run_function(help) | ||
15 | help.help_summary = "Help on commands. Type '"..program.." help <command>' for more." | 16 | help.help_summary = "Help on commands. Type '"..program.." help <command>' for more." |
16 | 17 | ||
17 | help.help_arguments = "[<command>]" | 18 | help.help_arguments = "[<command>]" |
@@ -40,9 +41,7 @@ end | |||
40 | -- given, help summaries for all commands are shown. | 41 | -- given, help summaries for all commands are shown. |
41 | -- @return boolean or (nil, string): true if there were no errors | 42 | -- @return boolean or (nil, string): true if there were no errors |
42 | -- or nil and an error message if an invalid command was requested. | 43 | -- or nil and an error message if an invalid command was requested. |
43 | function help.run(...) | 44 | function help.command(flags, command) |
44 | local flags, command = util.parse_flags(...) | ||
45 | |||
46 | if not command then | 45 | if not command then |
47 | local conf = cfg.which_config() | 46 | local conf = cfg.which_config() |
48 | print_banner() | 47 | print_banner() |
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index f78c6a0d..d961f525 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua | |||
@@ -13,6 +13,7 @@ local manif = require("luarocks.manif") | |||
13 | local remove = require("luarocks.remove") | 13 | local remove = require("luarocks.remove") |
14 | local cfg = require("luarocks.cfg") | 14 | local cfg = require("luarocks.cfg") |
15 | 15 | ||
16 | util.add_run_function(install) | ||
16 | install.help_summary = "Install a rock." | 17 | install.help_summary = "Install a rock." |
17 | 18 | ||
18 | install.help_arguments = "{<rock>|<name> [<version>]}" | 19 | install.help_arguments = "{<rock>|<name> [<version>]}" |
@@ -149,8 +150,7 @@ end | |||
149 | -- may also be given. | 150 | -- may also be given. |
150 | -- @return boolean or (nil, string, exitcode): True if installation was | 151 | -- @return boolean or (nil, string, exitcode): True if installation was |
151 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | 152 | -- successful, nil and an error message otherwise. exitcode is optionally returned. |
152 | function install.run(...) | 153 | function install.command(flags, name, version) |
153 | local flags, name, version = util.parse_flags(...) | ||
154 | if type(name) ~= "string" then | 154 | if type(name) ~= "string" then |
155 | return nil, "Argument missing. "..util.see_help("install") | 155 | return nil, "Argument missing. "..util.see_help("install") |
156 | end | 156 | end |
diff --git a/src/luarocks/lint.lua b/src/luarocks/lint.lua index 81d8bab2..d5cc48d0 100644 --- a/src/luarocks/lint.lua +++ b/src/luarocks/lint.lua | |||
@@ -8,6 +8,7 @@ local util = require("luarocks.util") | |||
8 | local download = require("luarocks.download") | 8 | local download = require("luarocks.download") |
9 | local fetch = require("luarocks.fetch") | 9 | local fetch = require("luarocks.fetch") |
10 | 10 | ||
11 | util.add_run_function(lint) | ||
11 | lint.help_summary = "Check syntax of a rockspec." | 12 | lint.help_summary = "Check syntax of a rockspec." |
12 | lint.help_arguments = "<rockspec>" | 13 | lint.help_arguments = "<rockspec>" |
13 | lint.help = [[ | 14 | lint.help = [[ |
@@ -17,9 +18,7 @@ It returns success or failure if the text of a rockspec is | |||
17 | syntactically correct. | 18 | syntactically correct. |
18 | ]] | 19 | ]] |
19 | 20 | ||
20 | function lint.run(...) | 21 | function lint.command(flags, input) |
21 | local flags, input = util.parse_flags(...) | ||
22 | |||
23 | if not input then | 22 | if not input then |
24 | return nil, "Argument missing. "..util.see_help("lint") | 23 | return nil, "Argument missing. "..util.see_help("lint") |
25 | end | 24 | end |
diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua index 09fa9ad7..c65e058f 100644 --- a/src/luarocks/list.lua +++ b/src/luarocks/list.lua | |||
@@ -10,6 +10,7 @@ local cfg = require("luarocks.cfg") | |||
10 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
11 | local path = require("luarocks.path") | 11 | local path = require("luarocks.path") |
12 | 12 | ||
13 | util.add_run_function(list) | ||
13 | list.help_summary = "List currently installed rocks." | 14 | list.help_summary = "List currently installed rocks." |
14 | list.help_arguments = "[--porcelain] <filter>" | 15 | list.help_arguments = "[--porcelain] <filter>" |
15 | list.help = [[ | 16 | list.help = [[ |
@@ -69,8 +70,7 @@ end | |||
69 | -- @param filter string or nil: A substring of a rock name to filter by. | 70 | -- @param filter string or nil: A substring of a rock name to filter by. |
70 | -- @param version string or nil: a version may also be passed. | 71 | -- @param version string or nil: a version may also be passed. |
71 | -- @return boolean: True if succeeded, nil on errors. | 72 | -- @return boolean: True if succeeded, nil on errors. |
72 | function list.run(...) | 73 | function list.command(flags, filter, version) |
73 | local flags, filter, version = util.parse_flags(...) | ||
74 | local query = search.make_query(filter and filter:lower() or "", version) | 74 | local query = search.make_query(filter and filter:lower() or "", version) |
75 | query.exact_name = false | 75 | query.exact_name = false |
76 | local trees = cfg.rocks_trees | 76 | local trees = cfg.rocks_trees |
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 9d675884..1464def7 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
@@ -15,6 +15,7 @@ local pack = require("luarocks.pack") | |||
15 | local remove = require("luarocks.remove") | 15 | local remove = require("luarocks.remove") |
16 | local deps = require("luarocks.deps") | 16 | local deps = require("luarocks.deps") |
17 | 17 | ||
18 | util.add_run_function(make) | ||
18 | make.help_summary = "Compile package in current directory using a rockspec." | 19 | make.help_summary = "Compile package in current directory using a rockspec." |
19 | make.help_arguments = "[--pack-binary-rock] [<rockspec>]" | 20 | make.help_arguments = "[--pack-binary-rock] [<rockspec>]" |
20 | make.help = [[ | 21 | make.help = [[ |
@@ -50,8 +51,7 @@ To install rocks, you'll normally want to use the "install" and | |||
50 | -- @param name string: A local rockspec. | 51 | -- @param name string: A local rockspec. |
51 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an | 52 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an |
52 | -- error message otherwise. exitcode is optionally returned. | 53 | -- error message otherwise. exitcode is optionally returned. |
53 | function make.run(...) | 54 | function make.command(flags, rockspec) |
54 | local flags, rockspec = util.parse_flags(...) | ||
55 | assert(type(rockspec) == "string" or not rockspec) | 55 | assert(type(rockspec) == "string" or not rockspec) |
56 | 56 | ||
57 | if not rockspec then | 57 | if not rockspec then |
diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua index 3d9a6bac..c39c2939 100644 --- a/src/luarocks/make_manifest.lua +++ b/src/luarocks/make_manifest.lua | |||
@@ -12,6 +12,7 @@ local deps = require("luarocks.deps") | |||
12 | local fs = require("luarocks.fs") | 12 | local fs = require("luarocks.fs") |
13 | local dir = require("luarocks.dir") | 13 | local dir = require("luarocks.dir") |
14 | 14 | ||
15 | util.add_run_function(make_manifest) | ||
15 | make_manifest.help_summary = "Compile a manifest file for a repository." | 16 | make_manifest.help_summary = "Compile a manifest file for a repository." |
16 | 17 | ||
17 | make_manifest.help = [[ | 18 | make_manifest.help = [[ |
@@ -26,9 +27,7 @@ make_manifest.help = [[ | |||
26 | -- the default local repository configured as cfg.rocks_dir is used. | 27 | -- the default local repository configured as cfg.rocks_dir is used. |
27 | -- @return boolean or (nil, string): True if manifest was generated, | 28 | -- @return boolean or (nil, string): True if manifest was generated, |
28 | -- or nil and an error message. | 29 | -- or nil and an error message. |
29 | function make_manifest.run(...) | 30 | function make_manifest.command(flags, repo) |
30 | local flags, repo = util.parse_flags(...) | ||
31 | |||
32 | assert(type(repo) == "string" or not repo) | 31 | assert(type(repo) == "string" or not repo) |
33 | repo = repo or cfg.rocks_dir | 32 | repo = repo or cfg.rocks_dir |
34 | 33 | ||
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index 3382b85c..bd73e308 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua | |||
@@ -10,6 +10,7 @@ local persist = require("luarocks.persist") | |||
10 | local fs = require("luarocks.fs") | 10 | local fs = require("luarocks.fs") |
11 | local type_check = require("luarocks.type_check") | 11 | local type_check = require("luarocks.type_check") |
12 | 12 | ||
13 | util.add_run_function(new_version) | ||
13 | new_version.help_summary = "Auto-write a rockspec for a new version of a rock." | 14 | new_version.help_summary = "Auto-write a rockspec for a new version of a rock." |
14 | new_version.help_arguments = "[--tag=<tag>] [<package>|<rockspec>] [<new_version>] [<new_url>]" | 15 | new_version.help_arguments = "[--tag=<tag>] [<package>|<rockspec>] [<new_version>] [<new_url>]" |
15 | new_version.help = [[ | 16 | new_version.help = [[ |
@@ -123,8 +124,7 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver) | |||
123 | return true | 124 | return true |
124 | end | 125 | end |
125 | 126 | ||
126 | function new_version.run(...) | 127 | function new_version.command(flags, input, version, url) |
127 | local flags, input, version, url = util.parse_flags(...) | ||
128 | if not input then | 128 | if not input then |
129 | local err | 129 | local err |
130 | input, err = util.get_default_rockspec() | 130 | input, err = util.get_default_rockspec() |
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 685b84bd..277cf246 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua | |||
@@ -16,6 +16,7 @@ local dir = require("luarocks.dir") | |||
16 | local manif = require("luarocks.manif") | 16 | local manif = require("luarocks.manif") |
17 | local search = require("luarocks.search") | 17 | local search = require("luarocks.search") |
18 | 18 | ||
19 | util.add_run_function(pack) | ||
19 | pack.help_summary = "Create a rock, packing sources or binaries." | 20 | pack.help_summary = "Create a rock, packing sources or binaries." |
20 | pack.help_arguments = "{<rockspec>|<name> [<version>]}" | 21 | pack.help_arguments = "{<rockspec>|<name> [<version>]}" |
21 | pack.help = [[ | 22 | pack.help = [[ |
@@ -191,8 +192,7 @@ end | |||
191 | -- version may also be passed. | 192 | -- version may also be passed. |
192 | -- @return boolean or (nil, string): true if successful or nil followed | 193 | -- @return boolean or (nil, string): true if successful or nil followed |
193 | -- by an error message. | 194 | -- by an error message. |
194 | function pack.run(...) | 195 | function pack.command(flags, arg, version) |
195 | local flags, arg, version = util.parse_flags(...) | ||
196 | assert(type(version) == "string" or not version) | 196 | assert(type(version) == "string" or not version) |
197 | if type(arg) ~= "string" then | 197 | if type(arg) ~= "string" then |
198 | return nil, "Argument missing. "..util.see_help("pack") | 198 | return nil, "Argument missing. "..util.see_help("pack") |
diff --git a/src/luarocks/path_cmd.lua b/src/luarocks/path_cmd.lua index ecd6d4b1..15fb9ca2 100644 --- a/src/luarocks/path_cmd.lua +++ b/src/luarocks/path_cmd.lua | |||
@@ -7,6 +7,7 @@ local util = require("luarocks.util") | |||
7 | local deps = require("luarocks.deps") | 7 | local deps = require("luarocks.deps") |
8 | local cfg = require("luarocks.cfg") | 8 | local cfg = require("luarocks.cfg") |
9 | 9 | ||
10 | util.add_run_function(path_cmd) | ||
10 | path_cmd.help_summary = "Return the currently configured package path." | 11 | path_cmd.help_summary = "Return the currently configured package path." |
11 | path_cmd.help_arguments = "" | 12 | path_cmd.help_arguments = "" |
12 | path_cmd.help = [[ | 13 | path_cmd.help = [[ |
@@ -33,8 +34,7 @@ And on Windows: | |||
33 | 34 | ||
34 | --- Driver function for "path" command. | 35 | --- Driver function for "path" command. |
35 | -- @return boolean This function always succeeds. | 36 | -- @return boolean This function always succeeds. |
36 | function path_cmd.run(...) | 37 | function path_cmd.command(flags) |
37 | local flags = util.parse_flags(...) | ||
38 | local deps_mode = deps.get_deps_mode(flags) | 38 | local deps_mode = deps.get_deps_mode(flags) |
39 | 39 | ||
40 | local lr_path, lr_cpath, lr_bin = cfg.package_paths(flags["tree"]) | 40 | local lr_path, lr_cpath, lr_bin = cfg.package_paths(flags["tree"]) |
diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua index 0be6ef21..1ce46c0f 100644 --- a/src/luarocks/purge.lua +++ b/src/luarocks/purge.lua | |||
@@ -14,6 +14,7 @@ local manif = require("luarocks.manif") | |||
14 | local cfg = require("luarocks.cfg") | 14 | local cfg = require("luarocks.cfg") |
15 | local remove = require("luarocks.remove") | 15 | local remove = require("luarocks.remove") |
16 | 16 | ||
17 | util.add_run_function(purge) | ||
17 | purge.help_summary = "Remove all installed rocks from a tree." | 18 | purge.help_summary = "Remove all installed rocks from a tree." |
18 | purge.help_arguments = "--tree=<tree> [--old-versions]" | 19 | purge.help_arguments = "--tree=<tree> [--old-versions]" |
19 | purge.help = [[ | 20 | purge.help = [[ |
@@ -30,9 +31,7 @@ assume a default tree. | |||
30 | overridden with the flag --force. | 31 | overridden with the flag --force. |
31 | ]] | 32 | ]] |
32 | 33 | ||
33 | function purge.run(...) | 34 | function purge.command(flags) |
34 | local flags = util.parse_flags(...) | ||
35 | |||
36 | local tree = flags["tree"] | 35 | local tree = flags["tree"] |
37 | 36 | ||
38 | if type(tree) ~= "string" then | 37 | if type(tree) ~= "string" then |
diff --git a/src/luarocks/refresh_cache.lua b/src/luarocks/refresh_cache.lua index cc5b9c33..bbfd1f4d 100644 --- a/src/luarocks/refresh_cache.lua +++ b/src/luarocks/refresh_cache.lua | |||
@@ -7,6 +7,7 @@ local util = require("luarocks.util") | |||
7 | local cfg = require("luarocks.cfg") | 7 | local cfg = require("luarocks.cfg") |
8 | local cache = require("luarocks.cache") | 8 | local cache = require("luarocks.cache") |
9 | 9 | ||
10 | util.add_run_function(refresh_cache) | ||
10 | refresh_cache.help_summary = "Refresh local cache of a remote rocks server." | 11 | refresh_cache.help_summary = "Refresh local cache of a remote rocks server." |
11 | refresh_cache.help_arguments = "[--from=<server>]" | 12 | refresh_cache.help_arguments = "[--from=<server>]" |
12 | refresh_cache.help = [[ | 13 | refresh_cache.help = [[ |
@@ -15,8 +16,7 @@ If not given, the default server set in the upload_server variable | |||
15 | from the configuration file is used instead. | 16 | from the configuration file is used instead. |
16 | ]] | 17 | ]] |
17 | 18 | ||
18 | function refresh_cache.run(...) | 19 | function refresh_cache.command(flags) |
19 | local flags = util.parse_flags(...) | ||
20 | local server, upload_server = cache.get_upload_server(flags["server"]) | 20 | local server, upload_server = cache.get_upload_server(flags["server"]) |
21 | if not server then return nil, upload_server end | 21 | if not server then return nil, upload_server end |
22 | local download_url = cache.get_server_urls(server, upload_server) | 22 | local download_url = cache.get_server_urls(server, upload_server) |
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 7a559f8f..38851d36 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua | |||
@@ -14,6 +14,7 @@ local cfg = require("luarocks.cfg") | |||
14 | local manif = require("luarocks.manif") | 14 | local manif = require("luarocks.manif") |
15 | local fs = require("luarocks.fs") | 15 | local fs = require("luarocks.fs") |
16 | 16 | ||
17 | util.add_run_function(remove) | ||
17 | remove.help_summary = "Uninstall a rock." | 18 | remove.help_summary = "Uninstall a rock." |
18 | remove.help_arguments = "[--force|--force-fast] <name> [<version>]" | 19 | remove.help_arguments = "[--force|--force-fast] <name> [<version>]" |
19 | remove.help = [[ | 20 | remove.help = [[ |
@@ -136,9 +137,7 @@ end | |||
136 | -- may also be given. | 137 | -- may also be given. |
137 | -- @return boolean or (nil, string, exitcode): True if removal was | 138 | -- @return boolean or (nil, string, exitcode): True if removal was |
138 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | 139 | -- successful, nil and an error message otherwise. exitcode is optionally returned. |
139 | function remove.run(...) | 140 | function remove.command(flags, name, version) |
140 | local flags, name, version = util.parse_flags(...) | ||
141 | |||
142 | if type(name) ~= "string" then | 141 | if type(name) ~= "string" then |
143 | return nil, "Argument missing, see help." | 142 | return nil, "Argument missing, see help." |
144 | end | 143 | end |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 4ec0c65e..eaa321d5 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -11,6 +11,7 @@ local deps = require("luarocks.deps") | |||
11 | local cfg = require("luarocks.cfg") | 11 | local cfg = require("luarocks.cfg") |
12 | local util = require("luarocks.util") | 12 | local util = require("luarocks.util") |
13 | 13 | ||
14 | util.add_run_function(search) | ||
14 | search.help_summary = "Query the LuaRocks servers." | 15 | search.help_summary = "Query the LuaRocks servers." |
15 | search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" | 16 | search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" |
16 | search.help = [[ | 17 | search.help = [[ |
@@ -420,9 +421,7 @@ end | |||
420 | -- @param version string or nil: a version may also be passed. | 421 | -- @param version string or nil: a version may also be passed. |
421 | -- @return boolean or (nil, string): True if build was successful; nil and an | 422 | -- @return boolean or (nil, string): True if build was successful; nil and an |
422 | -- error message otherwise. | 423 | -- error message otherwise. |
423 | function search.run(...) | 424 | function search.command(flags, name, version) |
424 | local flags, name, version = util.parse_flags(...) | ||
425 | |||
426 | if flags["all"] then | 425 | if flags["all"] then |
427 | name, version = "", nil | 426 | name, version = "", nil |
428 | end | 427 | end |
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 1dc01cc0..01860e78 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua | |||
@@ -10,6 +10,8 @@ local path = require("luarocks.path") | |||
10 | local deps = require("luarocks.deps") | 10 | local deps = require("luarocks.deps") |
11 | local fetch = require("luarocks.fetch") | 11 | local fetch = require("luarocks.fetch") |
12 | local manif = require("luarocks.manif") | 12 | local manif = require("luarocks.manif") |
13 | |||
14 | util.add_run_function(show) | ||
13 | show.help_summary = "Show information about an installed rock." | 15 | show.help_summary = "Show information about an installed rock." |
14 | 16 | ||
15 | show.help = [[ | 17 | show.help = [[ |
@@ -103,8 +105,7 @@ end | |||
103 | -- @param name or nil: an existing package name. | 105 | -- @param name or nil: an existing package name. |
104 | -- @param version string or nil: a version may also be passed. | 106 | -- @param version string or nil: a version may also be passed. |
105 | -- @return boolean: True if succeeded, nil on errors. | 107 | -- @return boolean: True if succeeded, nil on errors. |
106 | function show.run(...) | 108 | function show.command(flags, name, version) |
107 | local flags, name, version = util.parse_flags(...) | ||
108 | if not name then | 109 | if not name then |
109 | return nil, "Argument missing. "..util.see_help("show") | 110 | return nil, "Argument missing. "..util.see_help("show") |
110 | end | 111 | end |
diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua index 4afe4547..2face005 100644 --- a/src/luarocks/unpack.lua +++ b/src/luarocks/unpack.lua | |||
@@ -11,6 +11,7 @@ local build = require("luarocks.build") | |||
11 | local dir = require("luarocks.dir") | 11 | local dir = require("luarocks.dir") |
12 | local cfg = require("luarocks.cfg") | 12 | local cfg = require("luarocks.cfg") |
13 | 13 | ||
14 | util.add_run_function(unpack) | ||
14 | unpack.help_summary = "Unpack the contents of a rock." | 15 | unpack.help_summary = "Unpack the contents of a rock." |
15 | unpack.help_arguments = "[--force] {<rock>|<name> [<version>]}" | 16 | unpack.help_arguments = "[--force] {<rock>|<name> [<version>]}" |
16 | unpack.help = [[ | 17 | unpack.help = [[ |
@@ -149,9 +150,7 @@ end | |||
149 | -- version may also be passed. | 150 | -- version may also be passed. |
150 | -- @return boolean or (nil, string): true if successful or nil followed | 151 | -- @return boolean or (nil, string): true if successful or nil followed |
151 | -- by an error message. | 152 | -- by an error message. |
152 | function unpack.run(...) | 153 | function unpack.command(flags, name, version) |
153 | local flags, name, version = util.parse_flags(...) | ||
154 | |||
155 | assert(type(version) == "string" or not version) | 154 | assert(type(version) == "string" or not version) |
156 | if type(name) ~= "string" then | 155 | if type(name) ~= "string" then |
157 | return nil, "Argument missing. "..util.see_help("unpack") | 156 | return nil, "Argument missing. "..util.see_help("unpack") |
diff --git a/src/luarocks/upload.lua b/src/luarocks/upload.lua index 19ddee8d..3adc1704 100644 --- a/src/luarocks/upload.lua +++ b/src/luarocks/upload.lua | |||
@@ -7,6 +7,7 @@ local pack = require("luarocks.pack") | |||
7 | local cfg = require("luarocks.cfg") | 7 | local cfg = require("luarocks.cfg") |
8 | local Api = require("luarocks.upload.api") | 8 | local Api = require("luarocks.upload.api") |
9 | 9 | ||
10 | util.add_run_function(upload) | ||
10 | upload.help_summary = "Upload a rockspec to the public rocks repository." | 11 | upload.help_summary = "Upload a rockspec to the public rocks repository." |
11 | upload.help_arguments = "[--skip-pack] [--api-key=<key>] [--force] <rockspec>" | 12 | upload.help_arguments = "[--skip-pack] [--api-key=<key>] [--force] <rockspec>" |
12 | upload.help = [[ | 13 | upload.help = [[ |
@@ -20,8 +21,7 @@ upload.help = [[ | |||
20 | increment the revision number instead. | 21 | increment the revision number instead. |
21 | ]] | 22 | ]] |
22 | 23 | ||
23 | function upload.run(...) | 24 | function upload.command(flags, fname) |
24 | local flags, fname = util.parse_flags(...) | ||
25 | if not fname then | 25 | if not fname then |
26 | return nil, "Missing rockspec. "..util.see_help("upload") | 26 | return nil, "Missing rockspec. "..util.see_help("upload") |
27 | end | 27 | end |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index f7e9b1ae..6aff5324 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
@@ -228,6 +228,13 @@ function util.forward_flags(flags, ...) | |||
228 | return unpack(out) | 228 | return unpack(out) |
229 | end | 229 | end |
230 | 230 | ||
231 | -- Adds legacy 'run' function to a command module. | ||
232 | -- @param command table: command module with 'command' function, | ||
233 | -- the added 'run' function calls it after parseing command-line arguments. | ||
234 | function util.add_run_function(command) | ||
235 | command.run = function(...) return command.command(util.parse_flags(...)) end | ||
236 | end | ||
237 | |||
231 | --- Merges contents of src on top of dst's contents. | 238 | --- Merges contents of src on top of dst's contents. |
232 | -- @param dst Destination table, which will receive src's contents. | 239 | -- @param dst Destination table, which will receive src's contents. |
233 | -- @param src Table which provides new contents to dst. | 240 | -- @param src Table which provides new contents to dst. |
diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua index 24c6f835..c4570aa4 100644 --- a/src/luarocks/validate.lua +++ b/src/luarocks/validate.lua | |||
@@ -11,6 +11,7 @@ local build = require("luarocks.build") | |||
11 | local install = require("luarocks.install") | 11 | local install = require("luarocks.install") |
12 | local util = require("luarocks.util") | 12 | local util = require("luarocks.util") |
13 | 13 | ||
14 | util.add_run_function(validate) | ||
14 | validate.help_summary = "Sandboxed test of build/install of all packages in a repository." | 15 | validate.help_summary = "Sandboxed test of build/install of all packages in a repository." |
15 | 16 | ||
16 | validate.help = [[ | 17 | validate.help = [[ |
@@ -74,8 +75,7 @@ local function validate_rock(file) | |||
74 | return ok, err, errcode | 75 | return ok, err, errcode |
75 | end | 76 | end |
76 | 77 | ||
77 | function validate.run(...) | 78 | function validate.command(flags, repo) |
78 | local flags, repo = util.parse_flags(...) | ||
79 | repo = repo or cfg.rocks_dir | 79 | repo = repo or cfg.rocks_dir |
80 | 80 | ||
81 | util.printout("Verifying contents of "..repo) | 81 | util.printout("Verifying contents of "..repo) |
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 79902bb4..33edeb1b 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua | |||
@@ -11,6 +11,7 @@ local persist = require("luarocks.persist") | |||
11 | local type_check = require("luarocks.type_check") | 11 | local type_check = require("luarocks.type_check") |
12 | local util = require("luarocks.util") | 12 | local util = require("luarocks.util") |
13 | 13 | ||
14 | util.add_run_function(write_rockspec) | ||
14 | write_rockspec.help_summary = "Write a template for a rockspec file." | 15 | write_rockspec.help_summary = "Write a template for a rockspec file." |
15 | write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] [<url>|<path>]" | 16 | write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] [<url>|<path>]" |
16 | write_rockspec.help = [[ | 17 | write_rockspec.help = [[ |
@@ -224,9 +225,7 @@ local function rockspec_cleanup(rockspec) | |||
224 | rockspec.name = nil | 225 | rockspec.name = nil |
225 | end | 226 | end |
226 | 227 | ||
227 | function write_rockspec.run(...) | 228 | function write_rockspec.command(flags, name, version, url_or_dir) |
228 | local flags, name, version, url_or_dir = util.parse_flags(...) | ||
229 | |||
230 | if not name then | 229 | if not name then |
231 | url_or_dir = "." | 230 | url_or_dir = "." |
232 | elseif not version then | 231 | elseif not version then |