From 55cf0d2a015706932c477ff9521645814d9b89d1 Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Sun, 25 Aug 2019 16:44:06 -0400 Subject: Refactor command line handling of namespaces --- src/luarocks/cmd.lua | 1 + src/luarocks/cmd/build.lua | 31 +++++++++++------------ src/luarocks/cmd/doc.lua | 23 +++++++++-------- src/luarocks/cmd/download.lua | 7 +++--- src/luarocks/cmd/install.lua | 5 ++-- src/luarocks/cmd/list.lua | 2 +- src/luarocks/cmd/make.lua | 7 +++--- src/luarocks/cmd/pack.lua | 4 +-- src/luarocks/cmd/remove.lua | 11 +++++---- src/luarocks/cmd/search.lua | 8 +++--- src/luarocks/cmd/show.lua | 8 +++--- src/luarocks/cmd/unpack.lua | 9 +++---- src/luarocks/cmd/write_rockspec.lua | 4 +-- src/luarocks/deps.lua | 19 +++++++------- src/luarocks/download.lua | 9 ++++--- src/luarocks/pack.lua | 6 ++--- src/luarocks/queries.lua | 12 ++++----- src/luarocks/remove.lua | 2 +- src/luarocks/search.lua | 4 +-- src/luarocks/util.lua | 49 +++++++++++++++++++------------------ 20 files changed, 108 insertions(+), 113 deletions(-) diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index b19535e2..b43faaba 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -393,6 +393,7 @@ Enabling completion for Fish: parser:option("--only-sources", "Restrict downloads to paths matching the given URL.") :argname("") parser:option("--namespace", "Specify the rocks server namespace to use.") + :convert(string.lower) parser:option("--lua-dir", "Which Lua installation to use.") :argname("") parser:option("--lua-version", "Which Lua version to use.") diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index 3bc1554e..8e9956cb 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua @@ -27,6 +27,7 @@ function cmd_build.add_to_parser(parser) cmd:argument("rock", "A rockspec file, a source rock file, or the name of ".. "a rock to be fetched from a repository.") :args("?") + :action(util.namespaced_name_action) cmd:argument("version", "Rock version.") :args("?") @@ -76,21 +77,20 @@ local function build_rock(rock_filename, opts) return ok, err, errcode end -local function do_build(ns_name, version, opts) - assert(type(ns_name) == "string") +local function do_build(name, namespace, version, opts) + assert(type(name) == "string") + assert(type(namespace) == "string" or not namespace) assert(version == nil or type(version) == "string") assert(opts:type() == "build.opts") local url, err - if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then - url = ns_name + if name:match("%.rockspec$") or name:match("%.rock$") then + url = name else - url, err = search.find_src_or_rockspec(ns_name, version, opts.check_lua_versions) + url, err = search.find_src_or_rockspec(name, namespace, version, opts.check_lua_versions) if not url then return nil, err end - local _, namespace = util.split_namespace(ns_name) - opts.namespace = namespace end if url:match("%.rockspec$") then @@ -119,13 +119,11 @@ function cmd_build.command(args) return make.command(args) end - local name = util.adjust_name_and_namespace(args.rock, args) - local opts = build.opts({ need_to_fetch = true, minimal_mode = false, deps_mode = deps.get_deps_mode(args), - build_only_deps = not not args.only_deps, + build_only_deps = not not (args.only_deps and not args.pack_binary_rock), namespace = args.namespace, branch = args.branch, verify = not not args.verify, @@ -138,9 +136,8 @@ function cmd_build.command(args) end if args.pack_binary_rock then - return pack.pack_binary_rock(name, args.version, args.sign, function() - opts.build_only_deps = false - local name, version, errcode = do_build(name, args.version, opts) + return pack.pack_binary_rock(args.rock, args.namespace, args.version, args.sign, function() + local name, version, errcode = do_build(args.rock, args.namespace, args.version, opts) if name and args.no_doc then util.remove_doc_dir(name, version) end @@ -153,10 +150,10 @@ function cmd_build.command(args) return nil, err, cmd.errorcodes.PERMISSIONDENIED end - ok, err = do_build(name, args.version, opts) - if not ok then return nil, err end - local version - name, version = ok, err + local name, version, errcode = do_build(args.rock, args.namespace, args.version, opts) + if not name then + return nil, version, errcode + end if args.no_doc then util.remove_doc_dir(name, version) diff --git a/src/luarocks/cmd/doc.lua b/src/luarocks/cmd/doc.lua index 4b3335d8..6345063d 100644 --- a/src/luarocks/cmd/doc.lua +++ b/src/luarocks/cmd/doc.lua @@ -21,6 +21,7 @@ function doc.add_to_parser(parser) :summary("Show documentation for an installed rock.") cmd:argument("rock", "Name of the rock.") + :action(util.namespaced_name_action) cmd:argument("version", "Version of the rock.") :args("?") @@ -29,16 +30,16 @@ function doc.add_to_parser(parser) cmd:flag("--porcelain", "Produce machine-friendly output.") end -local function show_homepage(homepage, name, version) +local function show_homepage(homepage, name, namespace, version) if not homepage then - return nil, "No 'homepage' field in rockspec for "..name.." "..version + return nil, "No 'homepage' field in rockspec for "..util.format_rock_name(name, namespace, version) end util.printout("Opening "..homepage.." ...") fs.browser(homepage) return true end -local function try_to_open_homepage(name, version) +local function try_to_open_homepage(name, namespace, version) local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or "")) if not temp_dir then return nil, "Failed creating temporary directory: "..err @@ -46,26 +47,24 @@ local function try_to_open_homepage(name, version) util.schedule_function(fs.delete, temp_dir) local ok, err = fs.change_dir(temp_dir) if not ok then return nil, err end - local filename, err = download.download("rockspec", name, version) + local filename, err = download.download("rockspec", name, namespace, version) if not filename then return nil, err end local rockspec, err = fetch.load_local_rockspec(filename) if not rockspec then return nil, err end fs.pop_dir() local descript = rockspec.description or {} - if not descript.homepage then return nil, "No homepage defined for "..name end - return show_homepage(descript.homepage, name, version) + return show_homepage(descript.homepage, name, namespace, version) end --- Driver function for "doc" command. -- @return boolean: True if succeeded, nil on errors. function doc.command(args) - local name = util.adjust_name_and_namespace(args.rock, args) - local version = args.version - local query = queries.new(name, version) + local query = queries.new(args.rock, args.namespace, args.version) local iname, iversion, repo = search.pick_installed_rock(query, args.tree) if not iname then - util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...") - return try_to_open_homepage(name, version) + local rock = util.format_rock_name(args.rock, args.namespace, args.version) + util.printout(rock.." is not installed. Looking for it in the rocks servers...") + return try_to_open_homepage(args.rock, args.namespace, args.version) end name, version = iname, iversion @@ -74,7 +73,7 @@ function doc.command(args) local descript = rockspec.description or {} if args.home then - return show_homepage(descript.homepage, name, version) + return show_homepage(descript.homepage, name, args.namespace, version) end local directory = path.install_dir(name, version, repo) diff --git a/src/luarocks/cmd/download.lua b/src/luarocks/cmd/download.lua index 4beecdc3..1f844595 100644 --- a/src/luarocks/cmd/download.lua +++ b/src/luarocks/cmd/download.lua @@ -11,6 +11,7 @@ function cmd_download.add_to_parser(parser) cmd:argument("name", "Name of the rock.") :args("?") + :action(util.namespaced_name_action) cmd:argument("version", "Version of the rock.") :args("?") @@ -31,9 +32,7 @@ function cmd_download.command(args) return nil, "Argument missing. "..util.see_help("download") end - local name = util.adjust_name_and_namespace(args.name, args) - - if not name then name, args.version = "", "" end + args.name = args.name or "" local arch @@ -45,7 +44,7 @@ function cmd_download.command(args) arch = args.arch end - local dl, err = download.download(arch, name:lower(), args.version, args.all, args.check_lua_versions) + local dl, err = download.download(arch, args.name, args.namespace, args.version, args.all, args.check_lua_versions) return dl and true, err end diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index 88556e25..55074366 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua @@ -21,6 +21,7 @@ function install.add_to_parser(parser) cmd:argument("rock", "The name of a rock to be fetched from a repository ".. "or a filename of a locally available rock.") + :action(util.namespaced_name_action) cmd:argument("version", "Version of the rock.") :args("?") @@ -212,8 +213,6 @@ end -- @return boolean or (nil, string, exitcode): True if installation was -- successful, nil and an error message otherwise. exitcode is optionally returned. function install.command(args) - args.rock = util.adjust_name_and_namespace(args.rock, args) - local ok, err = fs.check_command_permissions(args) if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end @@ -238,7 +237,7 @@ function install.command(args) end else local url, err = search.find_rock_checking_lua_versions( - queries.new(args.rock:lower(), args.version), + queries.new(args.rock, args.namespace, args.version), args.check_lua_versions) if not url then return nil, err diff --git a/src/luarocks/cmd/list.lua b/src/luarocks/cmd/list.lua index cac5cd8a..aa815ea3 100644 --- a/src/luarocks/cmd/list.lua +++ b/src/luarocks/cmd/list.lua @@ -69,7 +69,7 @@ end --- Driver function for "list" command. -- @return boolean: True if succeeded, nil on errors. function list.command(args) - local query = queries.new(args.filter and args.filter:lower() or "", args.version, true) + local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true) local trees = cfg.rocks_trees local title = "Rocks installed for Lua "..cfg.lua_version if args.tree then diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index 13e974c1..ad6a211d 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua @@ -94,14 +94,15 @@ function make.command(args) return nil, err end - local name = util.adjust_name_and_namespace(rockspec.name, args) + local name, namespace = util.split_namespace(rockspec.name) + namespace = namespace or args.namespace local opts = build.opts({ need_to_fetch = false, minimal_mode = true, deps_mode = deps.get_deps_mode(args), build_only_deps = false, - namespace = args.namespace, + namespace = namespace, branch = args.branch, verify = not not args.verify, check_lua_versions = not not args.check_lua_versions, @@ -113,7 +114,7 @@ function make.command(args) end if args.pack_binary_rock then - return pack.pack_binary_rock(name, rockspec.version, args.sign, function() + return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function() local name, version = build.build_rockspec(rockspec, opts) if name and args.no_doc then util.remove_doc_dir(name, version) diff --git a/src/luarocks/cmd/pack.lua b/src/luarocks/cmd/pack.lua index fde8f875..9ceb2fa8 100644 --- a/src/luarocks/cmd/pack.lua +++ b/src/luarocks/cmd/pack.lua @@ -13,6 +13,7 @@ function cmd_pack.add_to_parser(parser) cmd:argument("rock", "A rockspec file, for creating a source rock, or the ".. "name of an installed package, for creating a binary rock.") + :action(util.namespaced_name_action) cmd:argument("version", "A version may be given if the first argument is a rock name.") :args("?") @@ -27,8 +28,7 @@ function cmd_pack.command(args) if args.rock:match(".*%.rockspec") then file, err = pack.pack_source_rock(args.rock) else - local name = util.adjust_name_and_namespace(args.rock, args) - local query = queries.new(name, args.version) + local query = queries.new(args.rock, args.namespace, args.version) file, err = pack.pack_installed_rock(query, args.tree) end return pack.report_and_sign_local_file(file, err, args.sign) diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua index f29b0b7d..cede148d 100644 --- a/src/luarocks/cmd/remove.lua +++ b/src/luarocks/cmd/remove.lua @@ -25,6 +25,7 @@ To override this check and force the removal, use --force or --force-fast.]], :summary("Uninstall a rock.") cmd:argument("rock", "Name of the rock to be uninstalled.") + :action(util.namespaced_name_action) cmd:argument("version", "Version of the rock to uninstall.") :args("?") @@ -37,9 +38,8 @@ end -- @return boolean or (nil, string, exitcode): True if removal was -- successful, nil and an error message otherwise. exitcode is optionally returned. function cmd_remove.command(args) - local name = util.adjust_name_and_namespace(args.rock, args) - - local deps_mode = args.deps_mode or cfg.deps_mode + local name = args.rock + local deps_mode = deps.get_deps_mode(args) local ok, err = fs.check_command_permissions(args) if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end @@ -54,9 +54,10 @@ function cmd_remove.command(args) local results = {} name = name:lower() - search.local_manifest_search(results, cfg.rocks_dir, queries.new(name, version)) + search.local_manifest_search(results, cfg.rocks_dir, queries.new(name, args.namespace, version)) if not results[name] then - return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) + local rock = util.format_rock_name(name, args.namespace, version) + return nil, "Could not find rock '"..rock.."' in "..path.rocks_tree_to_string(cfg.root_dir) end local ok, err = remove.remove_search_results(results, name, deps_mode, args.force, args.force_fast) diff --git a/src/luarocks/cmd/search.lua b/src/luarocks/cmd/search.lua index f34cf7b9..181fdacc 100644 --- a/src/luarocks/cmd/search.lua +++ b/src/luarocks/cmd/search.lua @@ -14,6 +14,7 @@ function cmd_search.add_to_parser(parser) cmd:argument("name", "Name of the rock to search for.") :args("?") + :action(util.namespaced_name_action) cmd:argument("version", "Rock version to search for.") :args("?") @@ -53,8 +54,7 @@ end -- @return boolean or (nil, string): True if build was successful; nil and an -- error message otherwise. function cmd_search.command(args) - - local name = util.adjust_name_and_namespace(args.name, args) + local name = args.name if args.all then name, args.version = "", nil @@ -64,10 +64,10 @@ function cmd_search.command(args) return nil, "Enter name and version or use --all. "..util.see_help("search") end - local query = queries.new(name:lower(), args.version, true) + local query = queries.new(name, args.namespace, args.version, true) local result_tree, err = search.search_repos(query) local porcelain = args.porcelain - local full_name = name .. (args.version and " " .. args.version or "") + local full_name = util.format_rock_name(name, args.namespace, args.version) util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=") local sources, binaries = split_source_and_binary_results(result_tree) if next(sources) and not args.binary then diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index db7aed54..8bb61b94 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua @@ -22,6 +22,7 @@ With flags, return only the desired information.]], util.see_also()) :summary("Show information about an installed rock.") cmd:argument("rock", "Name of an installed rock.") + :action(util.namespaced_name_action) cmd:argument("version", "Rock version.") :args("?") @@ -260,12 +261,9 @@ end --- Driver function for "show" command. -- @return boolean: True if succeeded, nil on errors. function show.command(args) - local name = util.adjust_name_and_namespace(args.rock, args) - local version = args.version - local query = queries.new(name, version) + local query = queries.new(args.rock, args.namespace, args.version) - local repo, repo_url - name, version, repo, repo_url = search.pick_installed_rock(query, args.tree) + local name, version, repo, repo_url = search.pick_installed_rock(query, args.tree) if not name then return nil, version end diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua index c2b5b983..b9bec4a6 100644 --- a/src/luarocks/cmd/unpack.lua +++ b/src/luarocks/cmd/unpack.lua @@ -19,6 +19,7 @@ In the latter case, the rock version may be given as a second argument.]], :summary("Unpack the contents of a rock.") cmd:argument("rock", "A rock file or the name of a rock.") + :action(util.namespaced_name_action) cmd:argument("version", "Rock version.") :args("?") @@ -151,13 +152,11 @@ end -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. function unpack.command(args) - local ns_name = util.adjust_name_and_namespace(args.rock, args) - local url, err - if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then - url = ns_name + if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then + url = args.rock else - url, err = search.find_src_or_rockspec(ns_name, args.version, args.check_lua_versions) + url, err = search.find_src_or_rockspec(args.rock, args.namespace, args.version, args.check_lua_versions) if not url then return nil, err end diff --git a/src/luarocks/cmd/write_rockspec.lua b/src/luarocks/cmd/write_rockspec.lua index ee825ce4..521f8fbc 100644 --- a/src/luarocks/cmd/write_rockspec.lua +++ b/src/luarocks/cmd/write_rockspec.lua @@ -263,9 +263,7 @@ local function rockspec_cleanup(rockspec) end function write_rockspec.command(args) - - local name = util.adjust_name_and_namespace(args.name, args) - local version = args.version + local name, version = args.name, args.version local location = args.location if not name then diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index d54c30de..08f2debb 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -102,7 +102,7 @@ local function match_dep(dep, get_versions) latest_matching_msg = " (latest matching is " .. latest_vstring .. ")" end util.printout("Forcing " .. dep.name .. " to pinned version " .. lockversion .. latest_matching_msg) - return nil, nil, queries.new(dep.name, lockversion) + return nil, nil, queries.new(dep.name, dep.namespace, lockversion) end return latest_vstring, locations[latest_vstring], dep, provided @@ -155,11 +155,11 @@ function deps.match_deps(dependencies, rocks_provided, blacklist, deps_mode) return match_all_deps(dependencies, get_versions) end -local function rock_status(name, get_versions) - assert(type(name) == "string") +local function rock_status(dep, get_versions) + assert(dep:type() == "query") assert(type(get_versions) == "function") - local installed, _, _, provided = match_dep(queries.new(name), get_versions) + local installed, _, _, provided = match_dep(dep, get_versions) local installation_type = provided and "provided by VM" or "installed" return installed and installed.." "..installation_type or "not installed" end @@ -197,7 +197,7 @@ function deps.report_missing_dependencies(name, version, dependencies, deps_mode first_missing_dep = false end - util.printout((" %s (%s)"):format(tostring(dep), rock_status(dep.name, get_versions))) + util.printout((" %s (%s)"):format(tostring(dep), rock_status(dep, get_versions))) end end end @@ -301,11 +301,12 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock util.printout("Using dependencies pinned in lockfile: " .. filename) local get_versions = prepare_get_versions("none", rocks_provided, depskey) - for dname, dversion in deplocks.each(depskey) do - local dep = queries.new(dname, dversion) + for dnsname, dversion in deplocks.each(depskey) do + local dname, dnamespace = util.split_namespace(dnsname) + local dep = queries.new(dname, dnamespace, dversion) util.printout(("%s %s is pinned to %s (%s)"):format( - name, version, tostring(dep), rock_status(dep.name, get_versions))) + name, version, tostring(dep), rock_status(dep, get_versions))) local ok, err = deps.fulfill_dependency(dep, "none", rocks_provided, verify, depskey) if not ok then @@ -331,7 +332,7 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock for _, dep in ipairs(rockspec[depskey]) do util.printout(("%s %s depends on %s (%s)"):format( - name, version, tostring(dep), rock_status(dep.name, get_versions))) + name, version, tostring(dep), rock_status(dep, get_versions))) local ok, found_or_err, _, no_upgrade = deps.fulfill_dependency(dep, deps_mode, rocks_provided, verify, depskey) if ok then diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 145fefed..70570344 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua @@ -6,6 +6,7 @@ local search = require("luarocks.search") local queries = require("luarocks.queries") local fs = require("luarocks.fs") local dir = require("luarocks.dir") +local util = require("luarocks.util") local function get_file(filename) local protocol, pathname = dir.split_url(filename) @@ -21,9 +22,9 @@ local function get_file(filename) end end -function download.download(arch, name, version, all, check_lua_versions) +function download.download(arch, name, namespace, version, all, check_lua_versions) local substring = (all and name == "") - local query = queries.new(name, version, substring, arch) + local query = queries.new(name, namespace, version, substring, arch) local search_err if all then @@ -58,8 +59,8 @@ function download.download(arch, name, version, all, check_lua_versions) return get_file(url) end end - return nil, "Could not find a result named "..name..(version and " "..version or "").. - (search_err and ": "..search_err or ".") + local rock = util.format_rock_name(name, namespace, version) + return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") end return download diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 336b9167..983aef74 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -137,7 +137,7 @@ function pack.report_and_sign_local_file(file, err, sign) end util.printout("Packed: "..file) if sigfile then - util.printout("Sigature stored in: "..sigfile) + util.printout("Signature stored in: "..sigfile) end if err then return nil, err @@ -145,7 +145,7 @@ function pack.report_and_sign_local_file(file, err, sign) return true end -function pack.pack_binary_rock(name, version, sign, cmd) +function pack.pack_binary_rock(name, namespace, version, sign, cmd) -- The --pack-binary-rock option for "luarocks build" basically performs -- "luarocks build" on a temporary tree and then "luarocks pack". The @@ -169,7 +169,7 @@ function pack.pack_binary_rock(name, version, sign, cmd) if not rname then rname, rversion = name, version end - local query = queries.new(rname, rversion) + local query = queries.new(rname, namespace, rversion) local file, err = pack.pack_installed_rock(query, temp_dir) return pack.report_and_sign_local_file(file, err, sign) end diff --git a/src/luarocks/queries.lua b/src/luarocks/queries.lua index 15dc5fac..de5c9652 100644 --- a/src/luarocks/queries.lua +++ b/src/luarocks/queries.lua @@ -40,15 +40,17 @@ local function arch_to_table(input) end --- Prepare a query in dependency table format. --- @param ns_name string: the package name, may contain a namespace. +-- @param name string: the package name. +-- @param namespace string?: the package namespace. -- @param version string?: the package version. -- @param substring boolean?: match substrings of the name -- (default is false, match full name) -- @param arch string?: a string with pipe-separated accepted arch values -- @param operator string?: operator for version matching (default is "==") -- @return table: A query in table format -function queries.new(ns_name, version, substring, arch, operator) - assert(type(ns_name) == "string") +function queries.new(name, namespace, version, substring, arch, operator) + assert(type(name) == "string") + assert(type(namespace) == "string" or not namespace) assert(type(version) == "string" or not version) assert(type(substring) == "boolean" or not substring) assert(type(arch) == "string" or not arch) @@ -56,8 +58,6 @@ function queries.new(ns_name, version, substring, arch, operator) operator = operator or "==" - local name, namespace = util.split_namespace(ns_name) - local self = { name = name, namespace = namespace, @@ -78,7 +78,7 @@ end function queries.all(arch) assert(type(arch) == "string" or not arch) - return queries.new("", nil, true, arch) + return queries.new("", nil, nil, true, arch) end do diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 9ae89da4..aabd716f 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -105,7 +105,7 @@ end function remove.remove_other_versions(name, version, force, fast) local results = {} - local query = queries.new(name, version, false, nil, "~=") + local query = queries.new(name, nil, version, false, nil, "~=") search.local_manifest_search(results, cfg.rocks_dir, query) if results[name] then return remove.remove_search_results(results, name, cfg.deps_mode, force, fast) diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index efe3b9c9..80e4caaa 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -250,8 +250,8 @@ function search.find_suitable_rock(query) end end -function search.find_src_or_rockspec(ns_name, version, check_lua_versions) - local query = queries.new(ns_name, version, false, "src|rockspec") +function search.find_src_or_rockspec(name, namespace, version, check_lua_versions) + local query = queries.new(name, namespace, version, false, "src|rockspec") local url, err = search.find_rock_checking_lua_versions(query, check_lua_versions) if not url then return nil, "Could not find a result named "..tostring(query)..": "..err diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index a7c31422..ae198daf 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -215,6 +215,10 @@ function util.this_program(default) return prog end +function util.format_rock_name(name, namespace, version) + return (namespace and namespace.."/" or "")..name..(version and " "..version or "") +end + function util.deps_mode_option(parser, program) local cfg = require("luarocks.core.cfg") @@ -338,30 +342,6 @@ function util.LQ(s) return ("%q"):format(s) end ---- Normalize the --namespace option and the user/rock syntax for namespaces. --- If a namespace is given in user/rock syntax, update the --namespace option; --- If a namespace is given in --namespace option, update the user/rock syntax. --- In case of conflicts, the user/rock syntax takes precedence. -function util.adjust_name_and_namespace(ns_name, args) - assert(type(ns_name) == "string" or not ns_name) - assert(type(args) == "table") - - if not ns_name then - return - elseif ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then - return ns_name - end - - local name, namespace = util.split_namespace(ns_name) - if namespace then - args.namespace = namespace - end - if args.namespace then - name = args.namespace .. "/" .. name - end - return name:lower() -end - -- Split name and namespace of a package name. -- @param ns_name a name that may be in "namespace/name" format -- @return string, string? - name and optionally a namespace @@ -373,6 +353,27 @@ function util.split_namespace(ns_name) return ns_name end +--- Argparse action callback for namespaced rock arguments. +function util.namespaced_name_action(args, target, ns_name) + assert(type(args) == "table") + assert(type(target) == "string") + assert(type(ns_name) == "string" or not ns_name) + + if not ns_name then + return + end + + if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then + args[target] = ns_name + else + local name, namespace = util.split_namespace(ns_name) + args[target] = name:lower() + if namespace then + args.namespace = namespace:lower() + end + end +end + function util.deep_copy(tbl) local copy = {} for k, v in pairs(tbl) do -- cgit v1.2.3-55-g6feb