From d55041dbc477000d0aa8a1585824958b0ade66a1 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 3 Jun 2016 11:16:55 +0300 Subject: 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'. --- src/luarocks/add.lua | 6 +++--- src/luarocks/admin_remove.lua | 6 +++--- src/luarocks/build.lua | 4 ++-- src/luarocks/command_line.lua | 37 ++++++------------------------------- src/luarocks/config_cmd.lua | 5 ++--- src/luarocks/doc.lua | 4 ++-- src/luarocks/download.lua | 5 ++--- src/luarocks/help.lua | 5 ++--- src/luarocks/install.lua | 4 ++-- src/luarocks/lint.lua | 5 ++--- src/luarocks/list.lua | 4 ++-- src/luarocks/make.lua | 4 ++-- src/luarocks/make_manifest.lua | 5 ++--- src/luarocks/new_version.lua | 4 ++-- src/luarocks/pack.lua | 4 ++-- src/luarocks/path_cmd.lua | 4 ++-- src/luarocks/purge.lua | 5 ++--- src/luarocks/refresh_cache.lua | 4 ++-- src/luarocks/remove.lua | 5 ++--- src/luarocks/search.lua | 5 ++--- src/luarocks/show.lua | 5 +++-- src/luarocks/unpack.lua | 5 ++--- src/luarocks/upload.lua | 4 ++-- src/luarocks/util.lua | 7 +++++++ src/luarocks/validate.lua | 4 ++-- 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") local fs = require("luarocks.fs") local cache = require("luarocks.cache") +util.add_run_function(add) add.help_summary = "Add a rock or rockspec to a rocks server." add.help_arguments = "[--server=] [--no-refresh] {|...}" add.help = [[ @@ -107,9 +108,8 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) return true end -function add.run(...) - local files = { util.parse_flags(...) } - local flags = table.remove(files, 1) +function add.command(flags, ...) + local files = {...} if #files < 1 then return nil, "Argument missing. "..util.see_help("add", "luarocks-admin") 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") local fs = require("luarocks.fs") local cache = require("luarocks.cache") +util.add_run_function(admin_remove) admin_remove.help_summary = "Remove a rock or rockspec from a rocks server." admin_remove.help_arguments = "[--server=] [--no-refresh] {|...}" admin_remove.help = [[ @@ -77,9 +78,8 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve return true end -function admin_remove.run(...) - local files = { util.parse_flags(...) } - local flags = table.remove(files, 1) +function admin_remove.command(flags, ...) + local files = {...} if #files < 1 then return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin") 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") local remove = require("luarocks.remove") local cfg = require("luarocks.cfg") +util.add_run_function(build) build.help_summary = "Build/compile a rock." build.help_arguments = "[--pack-binary-rock] [--keep] {|| []}" build.help = [[ @@ -390,8 +391,7 @@ end -- also be given. -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an -- error message otherwise. exitcode is optionally returned. -function build.run(...) - local flags, name, version = util.parse_flags(...) +function build.command(flags, name, version) if type(name) ~= "string" then return nil, "Argument missing. "..util.see_help("build") 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) os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) end -local function replace_tree(flags, args, tree) +local function replace_tree(flags, tree) tree = dir.normalize(tree) flags["tree"] = tree - local added = false - for i = 1, #args do - if args[i]:match("%-%-tree=") then - args[i] = "--tree="..tree - added = true - break - end - end - if not added then - args[#args + 1] = "--tree="..tree - end path.use_tree(tree) end @@ -78,7 +67,6 @@ function command_line.run_command(...) if flags["to"] then flags["tree"] = flags["to"] end if flags["nodeps"] then flags["deps-mode"] = "none" - table.insert(args, "--deps-mode=none") end cfg.flags = flags @@ -106,15 +94,8 @@ function command_line.run_command(...) os.exit(cfg.errorcodes.OK) elseif flags["help"] or #nonflags == 0 then command = "help" - args = nonflags else - command = nonflags[1] - for i, arg in ipairs(args) do - if arg == command then - table.remove(args, i) - break - end - end + command = table.remove(nonflags, 1) end command = command:gsub("-", "_") @@ -137,14 +118,14 @@ function command_line.run_command(...) if not tree.root then die("Configuration error: tree '"..tree.name.."' has no 'root' field.") end - replace_tree(flags, args, tree.root) + replace_tree(flags, tree.root) named = true break end end if not named then local root_dir = fs.absolute_name(flags["tree"]) - replace_tree(flags, args, root_dir) + replace_tree(flags, root_dir) end elseif flags["local"] then if not cfg.home_tree then @@ -152,7 +133,7 @@ function command_line.run_command(...) "You are running as a superuser, which is intended for system-wide operation.\n".. "To force using the superuser's home, use --tree explicitly.") end - replace_tree(flags, args, cfg.home_tree) + replace_tree(flags, cfg.home_tree) else local trees = cfg.rocks_trees path.use_tree(trees[#trees]) @@ -195,14 +176,8 @@ function command_line.run_command(...) end if commands[command] then - -- TODO the interface of run should be modified, to receive the - -- flags table and the (possibly unpacked) nonflags arguments. - -- This would remove redundant parsing of arguments. - -- I'm not changing this now to avoid messing with the run() - -- interface, which I know some people use (even though - -- I never published it as a public API...) local cmd = require(commands[command]) - local xp, ok, err, exitcode = xpcall(function() return cmd.run(unpack(args)) end, function(err) + local xp, ok, err, exitcode = xpcall(function() return cmd.command(flags, unpack(nonflags)) end, function(err) die(debug.traceback("LuaRocks "..cfg.program_version .." bug (please report at https://github.com/keplerproject/luarocks/issues).\n" ..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") local util = require("luarocks.util") local dir = require("luarocks.dir") +util.add_run_function(config_cmd) config_cmd.help_summary = "Query information about the LuaRocks configuration." config_cmd.help_arguments = "" config_cmd.help = [[ @@ -33,9 +34,7 @@ end --- Driver function for "config" command. -- @return boolean: True if succeeded, nil on errors. -function config_cmd.run(...) - local flags = util.parse_flags(...) - +function config_cmd.command(flags) if flags["lua-incdir"] then print(cfg.variables.LUA_INCDIR) 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") local fs = require("luarocks.fs") local download = require("luarocks.download") +util.add_run_function(doc) doc.help_summary = "Show documentation for an installed rock." doc.help = [[ @@ -57,8 +58,7 @@ end -- @param name or nil: an existing package name. -- @param version string or nil: a version may also be passed. -- @return boolean: True if succeeded, nil on errors. -function doc.run(...) - local flags, name, version = util.parse_flags(...) +function doc.command(flags, name, version) if not name then return nil, "Argument missing. "..util.see_help("doc") 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") local dir = require("luarocks.dir") local cfg = require("luarocks.cfg") +util.add_run_function(download) download.help_summary = "Download a specific rock file from a rocks server." download.help_arguments = "[--all] [--arch= | --source | --rockspec] [ []]" @@ -84,9 +85,7 @@ end -- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function download.run(...) - local flags, name, version = util.parse_flags(...) - +function download.command(flags, name, version) assert(type(version) == "string" or not version) if type(name) ~= "string" and not flags["all"] then 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") local program = util.this_program("luarocks") +util.add_run_function(help) help.help_summary = "Help on commands. Type '"..program.." help ' for more." help.help_arguments = "[]" @@ -40,9 +41,7 @@ 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.run(...) - local flags, command = util.parse_flags(...) - +function help.command(flags, command) if not command then local conf = cfg.which_config() 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") local remove = require("luarocks.remove") local cfg = require("luarocks.cfg") +util.add_run_function(install) install.help_summary = "Install a rock." install.help_arguments = "{| []}" @@ -149,8 +150,7 @@ end -- may also be given. -- @return boolean or (nil, string, exitcode): True if installation was -- successful, nil and an error message otherwise. exitcode is optionally returned. -function install.run(...) - local flags, name, version = util.parse_flags(...) +function install.command(flags, name, version) if type(name) ~= "string" then return nil, "Argument missing. "..util.see_help("install") 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") local download = require("luarocks.download") local fetch = require("luarocks.fetch") +util.add_run_function(lint) lint.help_summary = "Check syntax of a rockspec." lint.help_arguments = "" lint.help = [[ @@ -17,9 +18,7 @@ It returns success or failure if the text of a rockspec is syntactically correct. ]] -function lint.run(...) - local flags, input = util.parse_flags(...) - +function lint.command(flags, input) if not input then return nil, "Argument missing. "..util.see_help("lint") 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") local util = require("luarocks.util") local path = require("luarocks.path") +util.add_run_function(list) list.help_summary = "List currently installed rocks." list.help_arguments = "[--porcelain] " list.help = [[ @@ -69,8 +70,7 @@ end -- @param filter string or nil: A substring of a rock name to filter by. -- @param version string or nil: a version may also be passed. -- @return boolean: True if succeeded, nil on errors. -function list.run(...) - local flags, filter, version = util.parse_flags(...) +function list.command(flags, filter, version) local query = search.make_query(filter and filter:lower() or "", version) query.exact_name = false 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") local remove = require("luarocks.remove") local deps = require("luarocks.deps") +util.add_run_function(make) make.help_summary = "Compile package in current directory using a rockspec." make.help_arguments = "[--pack-binary-rock] []" make.help = [[ @@ -50,8 +51,7 @@ To install rocks, you'll normally want to use the "install" and -- @param name string: A local rockspec. -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an -- error message otherwise. exitcode is optionally returned. -function make.run(...) - local flags, rockspec = util.parse_flags(...) +function make.command(flags, rockspec) assert(type(rockspec) == "string" or not rockspec) 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") local fs = require("luarocks.fs") local dir = require("luarocks.dir") +util.add_run_function(make_manifest) make_manifest.help_summary = "Compile a manifest file for a repository." make_manifest.help = [[ @@ -26,9 +27,7 @@ make_manifest.help = [[ -- the default local repository configured as cfg.rocks_dir is used. -- @return boolean or (nil, string): True if manifest was generated, -- or nil and an error message. -function make_manifest.run(...) - local flags, repo = util.parse_flags(...) - +function make_manifest.command(flags, repo) assert(type(repo) == "string" or not repo) repo = repo or cfg.rocks_dir 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") local fs = require("luarocks.fs") local type_check = require("luarocks.type_check") +util.add_run_function(new_version) new_version.help_summary = "Auto-write a rockspec for a new version of a rock." new_version.help_arguments = "[--tag=] [|] [] []" new_version.help = [[ @@ -123,8 +124,7 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver) return true end -function new_version.run(...) - local flags, input, version, url = util.parse_flags(...) +function new_version.command(flags, input, version, url) if not input then local err 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") local manif = require("luarocks.manif") local search = require("luarocks.search") +util.add_run_function(pack) pack.help_summary = "Create a rock, packing sources or binaries." pack.help_arguments = "{| []}" pack.help = [[ @@ -191,8 +192,7 @@ end -- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function pack.run(...) - local flags, arg, version = util.parse_flags(...) +function pack.command(flags, arg, version) assert(type(version) == "string" or not version) if type(arg) ~= "string" then 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") local deps = require("luarocks.deps") local cfg = require("luarocks.cfg") +util.add_run_function(path_cmd) path_cmd.help_summary = "Return the currently configured package path." path_cmd.help_arguments = "" path_cmd.help = [[ @@ -33,8 +34,7 @@ And on Windows: --- Driver function for "path" command. -- @return boolean This function always succeeds. -function path_cmd.run(...) - local flags = util.parse_flags(...) +function path_cmd.command(flags) local deps_mode = deps.get_deps_mode(flags) 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") local cfg = require("luarocks.cfg") local remove = require("luarocks.remove") +util.add_run_function(purge) purge.help_summary = "Remove all installed rocks from a tree." purge.help_arguments = "--tree= [--old-versions]" purge.help = [[ @@ -30,9 +31,7 @@ assume a default tree. overridden with the flag --force. ]] -function purge.run(...) - local flags = util.parse_flags(...) - +function purge.command(flags) local tree = flags["tree"] 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") local cfg = require("luarocks.cfg") local cache = require("luarocks.cache") +util.add_run_function(refresh_cache) refresh_cache.help_summary = "Refresh local cache of a remote rocks server." refresh_cache.help_arguments = "[--from=]" refresh_cache.help = [[ @@ -15,8 +16,7 @@ If not given, the default server set in the upload_server variable from the configuration file is used instead. ]] -function refresh_cache.run(...) - local flags = util.parse_flags(...) +function refresh_cache.command(flags) local server, upload_server = cache.get_upload_server(flags["server"]) if not server then return nil, upload_server end 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") local manif = require("luarocks.manif") local fs = require("luarocks.fs") +util.add_run_function(remove) remove.help_summary = "Uninstall a rock." remove.help_arguments = "[--force|--force-fast] []" remove.help = [[ @@ -136,9 +137,7 @@ end -- may also be given. -- @return boolean or (nil, string, exitcode): True if removal was -- successful, nil and an error message otherwise. exitcode is optionally returned. -function remove.run(...) - local flags, name, version = util.parse_flags(...) - +function remove.command(flags, name, version) if type(name) ~= "string" then return nil, "Argument missing, see help." 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") local cfg = require("luarocks.cfg") local util = require("luarocks.util") +util.add_run_function(search) search.help_summary = "Query the LuaRocks servers." search.help_arguments = "[--source] [--binary] { [] | --all }" search.help = [[ @@ -420,9 +421,7 @@ end -- @param version string or nil: a version may also be passed. -- @return boolean or (nil, string): True if build was successful; nil and an -- error message otherwise. -function search.run(...) - local flags, name, version = util.parse_flags(...) - +function search.command(flags, name, version) if flags["all"] then name, version = "", nil 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") local deps = require("luarocks.deps") local fetch = require("luarocks.fetch") local manif = require("luarocks.manif") + +util.add_run_function(show) show.help_summary = "Show information about an installed rock." show.help = [[ @@ -103,8 +105,7 @@ end -- @param name or nil: an existing package name. -- @param version string or nil: a version may also be passed. -- @return boolean: True if succeeded, nil on errors. -function show.run(...) - local flags, name, version = util.parse_flags(...) +function show.command(flags, name, version) if not name then return nil, "Argument missing. "..util.see_help("show") 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") local dir = require("luarocks.dir") local cfg = require("luarocks.cfg") +util.add_run_function(unpack) unpack.help_summary = "Unpack the contents of a rock." unpack.help_arguments = "[--force] {| []}" unpack.help = [[ @@ -149,9 +150,7 @@ end -- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function unpack.run(...) - local flags, name, version = util.parse_flags(...) - +function unpack.command(flags, name, version) assert(type(version) == "string" or not version) if type(name) ~= "string" then 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") local cfg = require("luarocks.cfg") local Api = require("luarocks.upload.api") +util.add_run_function(upload) upload.help_summary = "Upload a rockspec to the public rocks repository." upload.help_arguments = "[--skip-pack] [--api-key=] [--force] " upload.help = [[ @@ -20,8 +21,7 @@ upload.help = [[ increment the revision number instead. ]] -function upload.run(...) - local flags, fname = util.parse_flags(...) +function upload.command(flags, fname) if not fname then return nil, "Missing rockspec. "..util.see_help("upload") 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, ...) return unpack(out) end +-- Adds legacy 'run' function to a command module. +-- @param command table: command module with 'command' function, +-- the added 'run' function calls it after parseing command-line arguments. +function util.add_run_function(command) + command.run = function(...) return command.command(util.parse_flags(...)) end +end + --- Merges contents of src on top of dst's contents. -- @param dst Destination table, which will receive src's contents. -- @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") local install = require("luarocks.install") local util = require("luarocks.util") +util.add_run_function(validate) validate.help_summary = "Sandboxed test of build/install of all packages in a repository." validate.help = [[ @@ -74,8 +75,7 @@ local function validate_rock(file) return ok, err, errcode end -function validate.run(...) - local flags, repo = util.parse_flags(...) +function validate.command(flags, repo) repo = repo or cfg.rocks_dir 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") local type_check = require("luarocks.type_check") local util = require("luarocks.util") +util.add_run_function(write_rockspec) write_rockspec.help_summary = "Write a template for a rockspec file." write_rockspec.help_arguments = "[--output= ...] [] [] [|]" write_rockspec.help = [[ @@ -224,9 +225,7 @@ local function rockspec_cleanup(rockspec) rockspec.name = nil end -function write_rockspec.run(...) - local flags, name, version, url_or_dir = util.parse_flags(...) - +function write_rockspec.command(flags, name, version, url_or_dir) if not name then url_or_dir = "." elseif not version then -- cgit v1.2.3-55-g6feb From a84d179f18b51190a27f6528aa016c6746c2c6c0 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 3 Jun 2016 12:07:54 +0300 Subject: Get rid of util.forward_flags Use 'commands' functions directly. --- src/luarocks/install.lua | 4 ++-- src/luarocks/util.lua | 32 -------------------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index d961f525..acbf584a 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -160,7 +160,7 @@ function install.command(flags, name, version) if name:match("%.rockspec$") or name:match("%.src%.rock$") then local build = require("luarocks.build") - return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode", "only-deps", "force", "force-fast")) + return build.command(flags, name) elseif name:match("%.rock$") then if flags["only-deps"] then ok, err = install.install_binary_rock_deps(name, deps.get_deps_mode(flags)) @@ -181,7 +181,7 @@ function install.command(flags, name, version) return nil, err end util.printout("Installing "..url) - return install.run(url, util.forward_flags(flags)) + return install.command(flags, url) end end diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 6aff5324..532bea8b 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -196,38 +196,6 @@ function util.parse_flags(...) return flags, unpack(out) end ---- Build a sequence of flags for forwarding from one command to --- another (for example, from "install" to "build"). --- @param flags table: A table of parsed flags --- @param ... string...: A variable number of flags to be checked --- in the flags table. If no flags are passed as varargs, the --- entire flags table is forwarded. --- @return string... A variable number of strings -function util.forward_flags(flags, ...) - assert(type(flags) == "table") - local out = {} - local filter = select('#', ...) - local function add_flag(flagname) - if flags[flagname] then - if flags[flagname] == true then - table.insert(out, "--"..flagname) - else - table.insert(out, "--"..flagname.."="..flags[flagname]) - end - end - end - if filter > 0 then - for i = 1, filter do - add_flag(select(i, ...)) - end - else - for flagname, _ in pairs(flags) do - add_flag(flagname) - end - end - return unpack(out) -end - -- Adds legacy 'run' function to a command module. -- @param command table: command module with 'command' function, -- the added 'run' function calls it after parseing command-line arguments. -- cgit v1.2.3-55-g6feb