diff options
| author | Paul Ouellette <oue.paul18@gmail.com> | 2019-08-25 16:44:06 -0400 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-12-02 14:45:07 -0300 |
| commit | 55cf0d2a015706932c477ff9521645814d9b89d1 (patch) | |
| tree | 688e7414b64837d5f26709751626b544f845fb59 | |
| parent | ea5788380b408894e8a7b0d165bf535d1a3fbe51 (diff) | |
| download | luarocks-55cf0d2a015706932c477ff9521645814d9b89d1.tar.gz luarocks-55cf0d2a015706932c477ff9521645814d9b89d1.tar.bz2 luarocks-55cf0d2a015706932c477ff9521645814d9b89d1.zip | |
Refactor command line handling of namespaces
| -rw-r--r-- | src/luarocks/cmd.lua | 1 | ||||
| -rw-r--r-- | src/luarocks/cmd/build.lua | 31 | ||||
| -rw-r--r-- | src/luarocks/cmd/doc.lua | 23 | ||||
| -rw-r--r-- | src/luarocks/cmd/download.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/cmd/install.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/cmd/list.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/cmd/make.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/cmd/pack.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/cmd/remove.lua | 11 | ||||
| -rw-r--r-- | src/luarocks/cmd/search.lua | 8 | ||||
| -rw-r--r-- | src/luarocks/cmd/show.lua | 8 | ||||
| -rw-r--r-- | src/luarocks/cmd/unpack.lua | 9 | ||||
| -rw-r--r-- | src/luarocks/cmd/write_rockspec.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/deps.lua | 19 | ||||
| -rw-r--r-- | src/luarocks/download.lua | 9 | ||||
| -rw-r--r-- | src/luarocks/pack.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/queries.lua | 12 | ||||
| -rw-r--r-- | src/luarocks/remove.lua | 2 | ||||
| -rw-r--r-- | src/luarocks/search.lua | 4 | ||||
| -rw-r--r-- | 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: | |||
| 393 | parser:option("--only-sources", "Restrict downloads to paths matching the given URL.") | 393 | parser:option("--only-sources", "Restrict downloads to paths matching the given URL.") |
| 394 | :argname("<url>") | 394 | :argname("<url>") |
| 395 | parser:option("--namespace", "Specify the rocks server namespace to use.") | 395 | parser:option("--namespace", "Specify the rocks server namespace to use.") |
| 396 | :convert(string.lower) | ||
| 396 | parser:option("--lua-dir", "Which Lua installation to use.") | 397 | parser:option("--lua-dir", "Which Lua installation to use.") |
| 397 | :argname("<prefix>") | 398 | :argname("<prefix>") |
| 398 | parser:option("--lua-version", "Which Lua version to use.") | 399 | 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) | |||
| 27 | cmd:argument("rock", "A rockspec file, a source rock file, or the name of ".. | 27 | cmd:argument("rock", "A rockspec file, a source rock file, or the name of ".. |
| 28 | "a rock to be fetched from a repository.") | 28 | "a rock to be fetched from a repository.") |
| 29 | :args("?") | 29 | :args("?") |
| 30 | :action(util.namespaced_name_action) | ||
| 30 | cmd:argument("version", "Rock version.") | 31 | cmd:argument("version", "Rock version.") |
| 31 | :args("?") | 32 | :args("?") |
| 32 | 33 | ||
| @@ -76,21 +77,20 @@ local function build_rock(rock_filename, opts) | |||
| 76 | return ok, err, errcode | 77 | return ok, err, errcode |
| 77 | end | 78 | end |
| 78 | 79 | ||
| 79 | local function do_build(ns_name, version, opts) | 80 | local function do_build(name, namespace, version, opts) |
| 80 | assert(type(ns_name) == "string") | 81 | assert(type(name) == "string") |
| 82 | assert(type(namespace) == "string" or not namespace) | ||
| 81 | assert(version == nil or type(version) == "string") | 83 | assert(version == nil or type(version) == "string") |
| 82 | assert(opts:type() == "build.opts") | 84 | assert(opts:type() == "build.opts") |
| 83 | 85 | ||
| 84 | local url, err | 86 | local url, err |
| 85 | if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then | 87 | if name:match("%.rockspec$") or name:match("%.rock$") then |
| 86 | url = ns_name | 88 | url = name |
| 87 | else | 89 | else |
| 88 | url, err = search.find_src_or_rockspec(ns_name, version, opts.check_lua_versions) | 90 | url, err = search.find_src_or_rockspec(name, namespace, version, opts.check_lua_versions) |
| 89 | if not url then | 91 | if not url then |
| 90 | return nil, err | 92 | return nil, err |
| 91 | end | 93 | end |
| 92 | local _, namespace = util.split_namespace(ns_name) | ||
| 93 | opts.namespace = namespace | ||
| 94 | end | 94 | end |
| 95 | 95 | ||
| 96 | if url:match("%.rockspec$") then | 96 | if url:match("%.rockspec$") then |
| @@ -119,13 +119,11 @@ function cmd_build.command(args) | |||
| 119 | return make.command(args) | 119 | return make.command(args) |
| 120 | end | 120 | end |
| 121 | 121 | ||
| 122 | local name = util.adjust_name_and_namespace(args.rock, args) | ||
| 123 | |||
| 124 | local opts = build.opts({ | 122 | local opts = build.opts({ |
| 125 | need_to_fetch = true, | 123 | need_to_fetch = true, |
| 126 | minimal_mode = false, | 124 | minimal_mode = false, |
| 127 | deps_mode = deps.get_deps_mode(args), | 125 | deps_mode = deps.get_deps_mode(args), |
| 128 | build_only_deps = not not args.only_deps, | 126 | build_only_deps = not not (args.only_deps and not args.pack_binary_rock), |
| 129 | namespace = args.namespace, | 127 | namespace = args.namespace, |
| 130 | branch = args.branch, | 128 | branch = args.branch, |
| 131 | verify = not not args.verify, | 129 | verify = not not args.verify, |
| @@ -138,9 +136,8 @@ function cmd_build.command(args) | |||
| 138 | end | 136 | end |
| 139 | 137 | ||
| 140 | if args.pack_binary_rock then | 138 | if args.pack_binary_rock then |
| 141 | return pack.pack_binary_rock(name, args.version, args.sign, function() | 139 | return pack.pack_binary_rock(args.rock, args.namespace, args.version, args.sign, function() |
| 142 | opts.build_only_deps = false | 140 | local name, version, errcode = do_build(args.rock, args.namespace, args.version, opts) |
| 143 | local name, version, errcode = do_build(name, args.version, opts) | ||
| 144 | if name and args.no_doc then | 141 | if name and args.no_doc then |
| 145 | util.remove_doc_dir(name, version) | 142 | util.remove_doc_dir(name, version) |
| 146 | end | 143 | end |
| @@ -153,10 +150,10 @@ function cmd_build.command(args) | |||
| 153 | return nil, err, cmd.errorcodes.PERMISSIONDENIED | 150 | return nil, err, cmd.errorcodes.PERMISSIONDENIED |
| 154 | end | 151 | end |
| 155 | 152 | ||
| 156 | ok, err = do_build(name, args.version, opts) | 153 | local name, version, errcode = do_build(args.rock, args.namespace, args.version, opts) |
| 157 | if not ok then return nil, err end | 154 | if not name then |
| 158 | local version | 155 | return nil, version, errcode |
| 159 | name, version = ok, err | 156 | end |
| 160 | 157 | ||
| 161 | if args.no_doc then | 158 | if args.no_doc then |
| 162 | util.remove_doc_dir(name, version) | 159 | 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) | |||
| 21 | :summary("Show documentation for an installed rock.") | 21 | :summary("Show documentation for an installed rock.") |
| 22 | 22 | ||
| 23 | cmd:argument("rock", "Name of the rock.") | 23 | cmd:argument("rock", "Name of the rock.") |
| 24 | :action(util.namespaced_name_action) | ||
| 24 | cmd:argument("version", "Version of the rock.") | 25 | cmd:argument("version", "Version of the rock.") |
| 25 | :args("?") | 26 | :args("?") |
| 26 | 27 | ||
| @@ -29,16 +30,16 @@ function doc.add_to_parser(parser) | |||
| 29 | cmd:flag("--porcelain", "Produce machine-friendly output.") | 30 | cmd:flag("--porcelain", "Produce machine-friendly output.") |
| 30 | end | 31 | end |
| 31 | 32 | ||
| 32 | local function show_homepage(homepage, name, version) | 33 | local function show_homepage(homepage, name, namespace, version) |
| 33 | if not homepage then | 34 | if not homepage then |
| 34 | return nil, "No 'homepage' field in rockspec for "..name.." "..version | 35 | return nil, "No 'homepage' field in rockspec for "..util.format_rock_name(name, namespace, version) |
| 35 | end | 36 | end |
| 36 | util.printout("Opening "..homepage.." ...") | 37 | util.printout("Opening "..homepage.." ...") |
| 37 | fs.browser(homepage) | 38 | fs.browser(homepage) |
| 38 | return true | 39 | return true |
| 39 | end | 40 | end |
| 40 | 41 | ||
| 41 | local function try_to_open_homepage(name, version) | 42 | local function try_to_open_homepage(name, namespace, version) |
| 42 | local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or "")) | 43 | local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or "")) |
| 43 | if not temp_dir then | 44 | if not temp_dir then |
| 44 | return nil, "Failed creating temporary directory: "..err | 45 | return nil, "Failed creating temporary directory: "..err |
| @@ -46,26 +47,24 @@ local function try_to_open_homepage(name, version) | |||
| 46 | util.schedule_function(fs.delete, temp_dir) | 47 | util.schedule_function(fs.delete, temp_dir) |
| 47 | local ok, err = fs.change_dir(temp_dir) | 48 | local ok, err = fs.change_dir(temp_dir) |
| 48 | if not ok then return nil, err end | 49 | if not ok then return nil, err end |
| 49 | local filename, err = download.download("rockspec", name, version) | 50 | local filename, err = download.download("rockspec", name, namespace, version) |
| 50 | if not filename then return nil, err end | 51 | if not filename then return nil, err end |
| 51 | local rockspec, err = fetch.load_local_rockspec(filename) | 52 | local rockspec, err = fetch.load_local_rockspec(filename) |
| 52 | if not rockspec then return nil, err end | 53 | if not rockspec then return nil, err end |
| 53 | fs.pop_dir() | 54 | fs.pop_dir() |
| 54 | local descript = rockspec.description or {} | 55 | local descript = rockspec.description or {} |
| 55 | if not descript.homepage then return nil, "No homepage defined for "..name end | 56 | return show_homepage(descript.homepage, name, namespace, version) |
| 56 | return show_homepage(descript.homepage, name, version) | ||
| 57 | end | 57 | end |
| 58 | 58 | ||
| 59 | --- Driver function for "doc" command. | 59 | --- Driver function for "doc" command. |
| 60 | -- @return boolean: True if succeeded, nil on errors. | 60 | -- @return boolean: True if succeeded, nil on errors. |
| 61 | function doc.command(args) | 61 | function doc.command(args) |
| 62 | local name = util.adjust_name_and_namespace(args.rock, args) | 62 | local query = queries.new(args.rock, args.namespace, args.version) |
| 63 | local version = args.version | ||
| 64 | local query = queries.new(name, version) | ||
| 65 | local iname, iversion, repo = search.pick_installed_rock(query, args.tree) | 63 | local iname, iversion, repo = search.pick_installed_rock(query, args.tree) |
| 66 | if not iname then | 64 | if not iname then |
| 67 | util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...") | 65 | local rock = util.format_rock_name(args.rock, args.namespace, args.version) |
| 68 | return try_to_open_homepage(name, version) | 66 | util.printout(rock.." is not installed. Looking for it in the rocks servers...") |
| 67 | return try_to_open_homepage(args.rock, args.namespace, args.version) | ||
| 69 | end | 68 | end |
| 70 | name, version = iname, iversion | 69 | name, version = iname, iversion |
| 71 | 70 | ||
| @@ -74,7 +73,7 @@ function doc.command(args) | |||
| 74 | local descript = rockspec.description or {} | 73 | local descript = rockspec.description or {} |
| 75 | 74 | ||
| 76 | if args.home then | 75 | if args.home then |
| 77 | return show_homepage(descript.homepage, name, version) | 76 | return show_homepage(descript.homepage, name, args.namespace, version) |
| 78 | end | 77 | end |
| 79 | 78 | ||
| 80 | local directory = path.install_dir(name, version, repo) | 79 | 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) | |||
| 11 | 11 | ||
| 12 | cmd:argument("name", "Name of the rock.") | 12 | cmd:argument("name", "Name of the rock.") |
| 13 | :args("?") | 13 | :args("?") |
| 14 | :action(util.namespaced_name_action) | ||
| 14 | cmd:argument("version", "Version of the rock.") | 15 | cmd:argument("version", "Version of the rock.") |
| 15 | :args("?") | 16 | :args("?") |
| 16 | 17 | ||
| @@ -31,9 +32,7 @@ function cmd_download.command(args) | |||
| 31 | return nil, "Argument missing. "..util.see_help("download") | 32 | return nil, "Argument missing. "..util.see_help("download") |
| 32 | end | 33 | end |
| 33 | 34 | ||
| 34 | local name = util.adjust_name_and_namespace(args.name, args) | 35 | args.name = args.name or "" |
| 35 | |||
| 36 | if not name then name, args.version = "", "" end | ||
| 37 | 36 | ||
| 38 | local arch | 37 | local arch |
| 39 | 38 | ||
| @@ -45,7 +44,7 @@ function cmd_download.command(args) | |||
| 45 | arch = args.arch | 44 | arch = args.arch |
| 46 | end | 45 | end |
| 47 | 46 | ||
| 48 | local dl, err = download.download(arch, name:lower(), args.version, args.all, args.check_lua_versions) | 47 | local dl, err = download.download(arch, args.name, args.namespace, args.version, args.all, args.check_lua_versions) |
| 49 | return dl and true, err | 48 | return dl and true, err |
| 50 | end | 49 | end |
| 51 | 50 | ||
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) | |||
| 21 | 21 | ||
| 22 | cmd:argument("rock", "The name of a rock to be fetched from a repository ".. | 22 | cmd:argument("rock", "The name of a rock to be fetched from a repository ".. |
| 23 | "or a filename of a locally available rock.") | 23 | "or a filename of a locally available rock.") |
| 24 | :action(util.namespaced_name_action) | ||
| 24 | cmd:argument("version", "Version of the rock.") | 25 | cmd:argument("version", "Version of the rock.") |
| 25 | :args("?") | 26 | :args("?") |
| 26 | 27 | ||
| @@ -212,8 +213,6 @@ end | |||
| 212 | -- @return boolean or (nil, string, exitcode): True if installation was | 213 | -- @return boolean or (nil, string, exitcode): True if installation was |
| 213 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | 214 | -- successful, nil and an error message otherwise. exitcode is optionally returned. |
| 214 | function install.command(args) | 215 | function install.command(args) |
| 215 | args.rock = util.adjust_name_and_namespace(args.rock, args) | ||
| 216 | |||
| 217 | local ok, err = fs.check_command_permissions(args) | 216 | local ok, err = fs.check_command_permissions(args) |
| 218 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end | 217 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end |
| 219 | 218 | ||
| @@ -238,7 +237,7 @@ function install.command(args) | |||
| 238 | end | 237 | end |
| 239 | else | 238 | else |
| 240 | local url, err = search.find_rock_checking_lua_versions( | 239 | local url, err = search.find_rock_checking_lua_versions( |
| 241 | queries.new(args.rock:lower(), args.version), | 240 | queries.new(args.rock, args.namespace, args.version), |
| 242 | args.check_lua_versions) | 241 | args.check_lua_versions) |
| 243 | if not url then | 242 | if not url then |
| 244 | return nil, err | 243 | 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 | |||
| 69 | --- Driver function for "list" command. | 69 | --- Driver function for "list" command. |
| 70 | -- @return boolean: True if succeeded, nil on errors. | 70 | -- @return boolean: True if succeeded, nil on errors. |
| 71 | function list.command(args) | 71 | function list.command(args) |
| 72 | local query = queries.new(args.filter and args.filter:lower() or "", args.version, true) | 72 | local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true) |
| 73 | local trees = cfg.rocks_trees | 73 | local trees = cfg.rocks_trees |
| 74 | local title = "Rocks installed for Lua "..cfg.lua_version | 74 | local title = "Rocks installed for Lua "..cfg.lua_version |
| 75 | if args.tree then | 75 | 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) | |||
| 94 | return nil, err | 94 | return nil, err |
| 95 | end | 95 | end |
| 96 | 96 | ||
| 97 | local name = util.adjust_name_and_namespace(rockspec.name, args) | 97 | local name, namespace = util.split_namespace(rockspec.name) |
| 98 | namespace = namespace or args.namespace | ||
| 98 | 99 | ||
| 99 | local opts = build.opts({ | 100 | local opts = build.opts({ |
| 100 | need_to_fetch = false, | 101 | need_to_fetch = false, |
| 101 | minimal_mode = true, | 102 | minimal_mode = true, |
| 102 | deps_mode = deps.get_deps_mode(args), | 103 | deps_mode = deps.get_deps_mode(args), |
| 103 | build_only_deps = false, | 104 | build_only_deps = false, |
| 104 | namespace = args.namespace, | 105 | namespace = namespace, |
| 105 | branch = args.branch, | 106 | branch = args.branch, |
| 106 | verify = not not args.verify, | 107 | verify = not not args.verify, |
| 107 | check_lua_versions = not not args.check_lua_versions, | 108 | check_lua_versions = not not args.check_lua_versions, |
| @@ -113,7 +114,7 @@ function make.command(args) | |||
| 113 | end | 114 | end |
| 114 | 115 | ||
| 115 | if args.pack_binary_rock then | 116 | if args.pack_binary_rock then |
| 116 | return pack.pack_binary_rock(name, rockspec.version, args.sign, function() | 117 | return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function() |
| 117 | local name, version = build.build_rockspec(rockspec, opts) | 118 | local name, version = build.build_rockspec(rockspec, opts) |
| 118 | if name and args.no_doc then | 119 | if name and args.no_doc then |
| 119 | util.remove_doc_dir(name, version) | 120 | 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) | |||
| 13 | 13 | ||
| 14 | cmd:argument("rock", "A rockspec file, for creating a source rock, or the ".. | 14 | cmd:argument("rock", "A rockspec file, for creating a source rock, or the ".. |
| 15 | "name of an installed package, for creating a binary rock.") | 15 | "name of an installed package, for creating a binary rock.") |
| 16 | :action(util.namespaced_name_action) | ||
| 16 | cmd:argument("version", "A version may be given if the first argument is a rock name.") | 17 | cmd:argument("version", "A version may be given if the first argument is a rock name.") |
| 17 | :args("?") | 18 | :args("?") |
| 18 | 19 | ||
| @@ -27,8 +28,7 @@ function cmd_pack.command(args) | |||
| 27 | if args.rock:match(".*%.rockspec") then | 28 | if args.rock:match(".*%.rockspec") then |
| 28 | file, err = pack.pack_source_rock(args.rock) | 29 | file, err = pack.pack_source_rock(args.rock) |
| 29 | else | 30 | else |
| 30 | local name = util.adjust_name_and_namespace(args.rock, args) | 31 | local query = queries.new(args.rock, args.namespace, args.version) |
| 31 | local query = queries.new(name, args.version) | ||
| 32 | file, err = pack.pack_installed_rock(query, args.tree) | 32 | file, err = pack.pack_installed_rock(query, args.tree) |
| 33 | end | 33 | end |
| 34 | return pack.report_and_sign_local_file(file, err, args.sign) | 34 | 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.]], | |||
| 25 | :summary("Uninstall a rock.") | 25 | :summary("Uninstall a rock.") |
| 26 | 26 | ||
| 27 | cmd:argument("rock", "Name of the rock to be uninstalled.") | 27 | cmd:argument("rock", "Name of the rock to be uninstalled.") |
| 28 | :action(util.namespaced_name_action) | ||
| 28 | cmd:argument("version", "Version of the rock to uninstall.") | 29 | cmd:argument("version", "Version of the rock to uninstall.") |
| 29 | :args("?") | 30 | :args("?") |
| 30 | 31 | ||
| @@ -37,9 +38,8 @@ end | |||
| 37 | -- @return boolean or (nil, string, exitcode): True if removal was | 38 | -- @return boolean or (nil, string, exitcode): True if removal was |
| 38 | -- successful, nil and an error message otherwise. exitcode is optionally returned. | 39 | -- successful, nil and an error message otherwise. exitcode is optionally returned. |
| 39 | function cmd_remove.command(args) | 40 | function cmd_remove.command(args) |
| 40 | local name = util.adjust_name_and_namespace(args.rock, args) | 41 | local name = args.rock |
| 41 | 42 | local deps_mode = deps.get_deps_mode(args) | |
| 42 | local deps_mode = args.deps_mode or cfg.deps_mode | ||
| 43 | 43 | ||
| 44 | local ok, err = fs.check_command_permissions(args) | 44 | local ok, err = fs.check_command_permissions(args) |
| 45 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end | 45 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end |
| @@ -54,9 +54,10 @@ function cmd_remove.command(args) | |||
| 54 | 54 | ||
| 55 | local results = {} | 55 | local results = {} |
| 56 | name = name:lower() | 56 | name = name:lower() |
| 57 | search.local_manifest_search(results, cfg.rocks_dir, queries.new(name, version)) | 57 | search.local_manifest_search(results, cfg.rocks_dir, queries.new(name, args.namespace, version)) |
| 58 | if not results[name] then | 58 | if not results[name] then |
| 59 | return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) | 59 | local rock = util.format_rock_name(name, args.namespace, version) |
| 60 | return nil, "Could not find rock '"..rock.."' in "..path.rocks_tree_to_string(cfg.root_dir) | ||
| 60 | end | 61 | end |
| 61 | 62 | ||
| 62 | local ok, err = remove.remove_search_results(results, name, deps_mode, args.force, args.force_fast) | 63 | 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) | |||
| 14 | 14 | ||
| 15 | cmd:argument("name", "Name of the rock to search for.") | 15 | cmd:argument("name", "Name of the rock to search for.") |
| 16 | :args("?") | 16 | :args("?") |
| 17 | :action(util.namespaced_name_action) | ||
| 17 | cmd:argument("version", "Rock version to search for.") | 18 | cmd:argument("version", "Rock version to search for.") |
| 18 | :args("?") | 19 | :args("?") |
| 19 | 20 | ||
| @@ -53,8 +54,7 @@ end | |||
| 53 | -- @return boolean or (nil, string): True if build was successful; nil and an | 54 | -- @return boolean or (nil, string): True if build was successful; nil and an |
| 54 | -- error message otherwise. | 55 | -- error message otherwise. |
| 55 | function cmd_search.command(args) | 56 | function cmd_search.command(args) |
| 56 | 57 | local name = args.name | |
| 57 | local name = util.adjust_name_and_namespace(args.name, args) | ||
| 58 | 58 | ||
| 59 | if args.all then | 59 | if args.all then |
| 60 | name, args.version = "", nil | 60 | name, args.version = "", nil |
| @@ -64,10 +64,10 @@ function cmd_search.command(args) | |||
| 64 | return nil, "Enter name and version or use --all. "..util.see_help("search") | 64 | return nil, "Enter name and version or use --all. "..util.see_help("search") |
| 65 | end | 65 | end |
| 66 | 66 | ||
| 67 | local query = queries.new(name:lower(), args.version, true) | 67 | local query = queries.new(name, args.namespace, args.version, true) |
| 68 | local result_tree, err = search.search_repos(query) | 68 | local result_tree, err = search.search_repos(query) |
| 69 | local porcelain = args.porcelain | 69 | local porcelain = args.porcelain |
| 70 | local full_name = name .. (args.version and " " .. args.version or "") | 70 | local full_name = util.format_rock_name(name, args.namespace, args.version) |
| 71 | util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=") | 71 | util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=") |
| 72 | local sources, binaries = split_source_and_binary_results(result_tree) | 72 | local sources, binaries = split_source_and_binary_results(result_tree) |
| 73 | if next(sources) and not args.binary then | 73 | 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()) | |||
| 22 | :summary("Show information about an installed rock.") | 22 | :summary("Show information about an installed rock.") |
| 23 | 23 | ||
| 24 | cmd:argument("rock", "Name of an installed rock.") | 24 | cmd:argument("rock", "Name of an installed rock.") |
| 25 | :action(util.namespaced_name_action) | ||
| 25 | cmd:argument("version", "Rock version.") | 26 | cmd:argument("version", "Rock version.") |
| 26 | :args("?") | 27 | :args("?") |
| 27 | 28 | ||
| @@ -260,12 +261,9 @@ end | |||
| 260 | --- Driver function for "show" command. | 261 | --- Driver function for "show" command. |
| 261 | -- @return boolean: True if succeeded, nil on errors. | 262 | -- @return boolean: True if succeeded, nil on errors. |
| 262 | function show.command(args) | 263 | function show.command(args) |
| 263 | local name = util.adjust_name_and_namespace(args.rock, args) | 264 | local query = queries.new(args.rock, args.namespace, args.version) |
| 264 | local version = args.version | ||
| 265 | local query = queries.new(name, version) | ||
| 266 | 265 | ||
| 267 | local repo, repo_url | 266 | local name, version, repo, repo_url = search.pick_installed_rock(query, args.tree) |
| 268 | name, version, repo, repo_url = search.pick_installed_rock(query, args.tree) | ||
| 269 | if not name then | 267 | if not name then |
| 270 | return nil, version | 268 | return nil, version |
| 271 | end | 269 | 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.]], | |||
| 19 | :summary("Unpack the contents of a rock.") | 19 | :summary("Unpack the contents of a rock.") |
| 20 | 20 | ||
| 21 | cmd:argument("rock", "A rock file or the name of a rock.") | 21 | cmd:argument("rock", "A rock file or the name of a rock.") |
| 22 | :action(util.namespaced_name_action) | ||
| 22 | cmd:argument("version", "Rock version.") | 23 | cmd:argument("version", "Rock version.") |
| 23 | :args("?") | 24 | :args("?") |
| 24 | 25 | ||
| @@ -151,13 +152,11 @@ end | |||
| 151 | -- @return boolean or (nil, string): true if successful or nil followed | 152 | -- @return boolean or (nil, string): true if successful or nil followed |
| 152 | -- by an error message. | 153 | -- by an error message. |
| 153 | function unpack.command(args) | 154 | function unpack.command(args) |
| 154 | local ns_name = util.adjust_name_and_namespace(args.rock, args) | ||
| 155 | |||
| 156 | local url, err | 155 | local url, err |
| 157 | if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then | 156 | if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then |
| 158 | url = ns_name | 157 | url = args.rock |
| 159 | else | 158 | else |
| 160 | url, err = search.find_src_or_rockspec(ns_name, args.version, args.check_lua_versions) | 159 | url, err = search.find_src_or_rockspec(args.rock, args.namespace, args.version, args.check_lua_versions) |
| 161 | if not url then | 160 | if not url then |
| 162 | return nil, err | 161 | return nil, err |
| 163 | end | 162 | 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) | |||
| 263 | end | 263 | end |
| 264 | 264 | ||
| 265 | function write_rockspec.command(args) | 265 | function write_rockspec.command(args) |
| 266 | 266 | local name, version = args.name, args.version | |
| 267 | local name = util.adjust_name_and_namespace(args.name, args) | ||
| 268 | local version = args.version | ||
| 269 | local location = args.location | 267 | local location = args.location |
| 270 | 268 | ||
| 271 | if not name then | 269 | 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) | |||
| 102 | latest_matching_msg = " (latest matching is " .. latest_vstring .. ")" | 102 | latest_matching_msg = " (latest matching is " .. latest_vstring .. ")" |
| 103 | end | 103 | end |
| 104 | util.printout("Forcing " .. dep.name .. " to pinned version " .. lockversion .. latest_matching_msg) | 104 | util.printout("Forcing " .. dep.name .. " to pinned version " .. lockversion .. latest_matching_msg) |
| 105 | return nil, nil, queries.new(dep.name, lockversion) | 105 | return nil, nil, queries.new(dep.name, dep.namespace, lockversion) |
| 106 | end | 106 | end |
| 107 | 107 | ||
| 108 | return latest_vstring, locations[latest_vstring], dep, provided | 108 | return latest_vstring, locations[latest_vstring], dep, provided |
| @@ -155,11 +155,11 @@ function deps.match_deps(dependencies, rocks_provided, blacklist, deps_mode) | |||
| 155 | return match_all_deps(dependencies, get_versions) | 155 | return match_all_deps(dependencies, get_versions) |
| 156 | end | 156 | end |
| 157 | 157 | ||
| 158 | local function rock_status(name, get_versions) | 158 | local function rock_status(dep, get_versions) |
| 159 | assert(type(name) == "string") | 159 | assert(dep:type() == "query") |
| 160 | assert(type(get_versions) == "function") | 160 | assert(type(get_versions) == "function") |
| 161 | 161 | ||
| 162 | local installed, _, _, provided = match_dep(queries.new(name), get_versions) | 162 | local installed, _, _, provided = match_dep(dep, get_versions) |
| 163 | local installation_type = provided and "provided by VM" or "installed" | 163 | local installation_type = provided and "provided by VM" or "installed" |
| 164 | return installed and installed.." "..installation_type or "not installed" | 164 | return installed and installed.." "..installation_type or "not installed" |
| 165 | end | 165 | end |
| @@ -197,7 +197,7 @@ function deps.report_missing_dependencies(name, version, dependencies, deps_mode | |||
| 197 | first_missing_dep = false | 197 | first_missing_dep = false |
| 198 | end | 198 | end |
| 199 | 199 | ||
| 200 | util.printout((" %s (%s)"):format(tostring(dep), rock_status(dep.name, get_versions))) | 200 | util.printout((" %s (%s)"):format(tostring(dep), rock_status(dep, get_versions))) |
| 201 | end | 201 | end |
| 202 | end | 202 | end |
| 203 | end | 203 | end |
| @@ -301,11 +301,12 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock | |||
| 301 | util.printout("Using dependencies pinned in lockfile: " .. filename) | 301 | util.printout("Using dependencies pinned in lockfile: " .. filename) |
| 302 | 302 | ||
| 303 | local get_versions = prepare_get_versions("none", rocks_provided, depskey) | 303 | local get_versions = prepare_get_versions("none", rocks_provided, depskey) |
| 304 | for dname, dversion in deplocks.each(depskey) do | 304 | for dnsname, dversion in deplocks.each(depskey) do |
| 305 | local dep = queries.new(dname, dversion) | 305 | local dname, dnamespace = util.split_namespace(dnsname) |
| 306 | local dep = queries.new(dname, dnamespace, dversion) | ||
| 306 | 307 | ||
| 307 | util.printout(("%s %s is pinned to %s (%s)"):format( | 308 | util.printout(("%s %s is pinned to %s (%s)"):format( |
| 308 | name, version, tostring(dep), rock_status(dep.name, get_versions))) | 309 | name, version, tostring(dep), rock_status(dep, get_versions))) |
| 309 | 310 | ||
| 310 | local ok, err = deps.fulfill_dependency(dep, "none", rocks_provided, verify, depskey) | 311 | local ok, err = deps.fulfill_dependency(dep, "none", rocks_provided, verify, depskey) |
| 311 | if not ok then | 312 | if not ok then |
| @@ -331,7 +332,7 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock | |||
| 331 | for _, dep in ipairs(rockspec[depskey]) do | 332 | for _, dep in ipairs(rockspec[depskey]) do |
| 332 | 333 | ||
| 333 | util.printout(("%s %s depends on %s (%s)"):format( | 334 | util.printout(("%s %s depends on %s (%s)"):format( |
| 334 | name, version, tostring(dep), rock_status(dep.name, get_versions))) | 335 | name, version, tostring(dep), rock_status(dep, get_versions))) |
| 335 | 336 | ||
| 336 | local ok, found_or_err, _, no_upgrade = deps.fulfill_dependency(dep, deps_mode, rocks_provided, verify, depskey) | 337 | local ok, found_or_err, _, no_upgrade = deps.fulfill_dependency(dep, deps_mode, rocks_provided, verify, depskey) |
| 337 | if ok then | 338 | 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") | |||
| 6 | local queries = require("luarocks.queries") | 6 | local queries = require("luarocks.queries") |
| 7 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
| 8 | local dir = require("luarocks.dir") | 8 | local dir = require("luarocks.dir") |
| 9 | local util = require("luarocks.util") | ||
| 9 | 10 | ||
| 10 | local function get_file(filename) | 11 | local function get_file(filename) |
| 11 | local protocol, pathname = dir.split_url(filename) | 12 | local protocol, pathname = dir.split_url(filename) |
| @@ -21,9 +22,9 @@ local function get_file(filename) | |||
| 21 | end | 22 | end |
| 22 | end | 23 | end |
| 23 | 24 | ||
| 24 | function download.download(arch, name, version, all, check_lua_versions) | 25 | function download.download(arch, name, namespace, version, all, check_lua_versions) |
| 25 | local substring = (all and name == "") | 26 | local substring = (all and name == "") |
| 26 | local query = queries.new(name, version, substring, arch) | 27 | local query = queries.new(name, namespace, version, substring, arch) |
| 27 | local search_err | 28 | local search_err |
| 28 | 29 | ||
| 29 | if all then | 30 | if all then |
| @@ -58,8 +59,8 @@ function download.download(arch, name, version, all, check_lua_versions) | |||
| 58 | return get_file(url) | 59 | return get_file(url) |
| 59 | end | 60 | end |
| 60 | end | 61 | end |
| 61 | return nil, "Could not find a result named "..name..(version and " "..version or "").. | 62 | local rock = util.format_rock_name(name, namespace, version) |
| 62 | (search_err and ": "..search_err or ".") | 63 | return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") |
| 63 | end | 64 | end |
| 64 | 65 | ||
| 65 | return download | 66 | 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) | |||
| 137 | end | 137 | end |
| 138 | util.printout("Packed: "..file) | 138 | util.printout("Packed: "..file) |
| 139 | if sigfile then | 139 | if sigfile then |
| 140 | util.printout("Sigature stored in: "..sigfile) | 140 | util.printout("Signature stored in: "..sigfile) |
| 141 | end | 141 | end |
| 142 | if err then | 142 | if err then |
| 143 | return nil, err | 143 | return nil, err |
| @@ -145,7 +145,7 @@ function pack.report_and_sign_local_file(file, err, sign) | |||
| 145 | return true | 145 | return true |
| 146 | end | 146 | end |
| 147 | 147 | ||
| 148 | function pack.pack_binary_rock(name, version, sign, cmd) | 148 | function pack.pack_binary_rock(name, namespace, version, sign, cmd) |
| 149 | 149 | ||
| 150 | -- The --pack-binary-rock option for "luarocks build" basically performs | 150 | -- The --pack-binary-rock option for "luarocks build" basically performs |
| 151 | -- "luarocks build" on a temporary tree and then "luarocks pack". The | 151 | -- "luarocks build" on a temporary tree and then "luarocks pack". The |
| @@ -169,7 +169,7 @@ function pack.pack_binary_rock(name, version, sign, cmd) | |||
| 169 | if not rname then | 169 | if not rname then |
| 170 | rname, rversion = name, version | 170 | rname, rversion = name, version |
| 171 | end | 171 | end |
| 172 | local query = queries.new(rname, rversion) | 172 | local query = queries.new(rname, namespace, rversion) |
| 173 | local file, err = pack.pack_installed_rock(query, temp_dir) | 173 | local file, err = pack.pack_installed_rock(query, temp_dir) |
| 174 | return pack.report_and_sign_local_file(file, err, sign) | 174 | return pack.report_and_sign_local_file(file, err, sign) |
| 175 | end | 175 | 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) | |||
| 40 | end | 40 | end |
| 41 | 41 | ||
| 42 | --- Prepare a query in dependency table format. | 42 | --- Prepare a query in dependency table format. |
| 43 | -- @param ns_name string: the package name, may contain a namespace. | 43 | -- @param name string: the package name. |
| 44 | -- @param namespace string?: the package namespace. | ||
| 44 | -- @param version string?: the package version. | 45 | -- @param version string?: the package version. |
| 45 | -- @param substring boolean?: match substrings of the name | 46 | -- @param substring boolean?: match substrings of the name |
| 46 | -- (default is false, match full name) | 47 | -- (default is false, match full name) |
| 47 | -- @param arch string?: a string with pipe-separated accepted arch values | 48 | -- @param arch string?: a string with pipe-separated accepted arch values |
| 48 | -- @param operator string?: operator for version matching (default is "==") | 49 | -- @param operator string?: operator for version matching (default is "==") |
| 49 | -- @return table: A query in table format | 50 | -- @return table: A query in table format |
| 50 | function queries.new(ns_name, version, substring, arch, operator) | 51 | function queries.new(name, namespace, version, substring, arch, operator) |
| 51 | assert(type(ns_name) == "string") | 52 | assert(type(name) == "string") |
| 53 | assert(type(namespace) == "string" or not namespace) | ||
| 52 | assert(type(version) == "string" or not version) | 54 | assert(type(version) == "string" or not version) |
| 53 | assert(type(substring) == "boolean" or not substring) | 55 | assert(type(substring) == "boolean" or not substring) |
| 54 | assert(type(arch) == "string" or not arch) | 56 | assert(type(arch) == "string" or not arch) |
| @@ -56,8 +58,6 @@ function queries.new(ns_name, version, substring, arch, operator) | |||
| 56 | 58 | ||
| 57 | operator = operator or "==" | 59 | operator = operator or "==" |
| 58 | 60 | ||
| 59 | local name, namespace = util.split_namespace(ns_name) | ||
| 60 | |||
| 61 | local self = { | 61 | local self = { |
| 62 | name = name, | 62 | name = name, |
| 63 | namespace = namespace, | 63 | namespace = namespace, |
| @@ -78,7 +78,7 @@ end | |||
| 78 | function queries.all(arch) | 78 | function queries.all(arch) |
| 79 | assert(type(arch) == "string" or not arch) | 79 | assert(type(arch) == "string" or not arch) |
| 80 | 80 | ||
| 81 | return queries.new("", nil, true, arch) | 81 | return queries.new("", nil, nil, true, arch) |
| 82 | end | 82 | end |
| 83 | 83 | ||
| 84 | do | 84 | 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 | |||
| 105 | 105 | ||
| 106 | function remove.remove_other_versions(name, version, force, fast) | 106 | function remove.remove_other_versions(name, version, force, fast) |
| 107 | local results = {} | 107 | local results = {} |
| 108 | local query = queries.new(name, version, false, nil, "~=") | 108 | local query = queries.new(name, nil, version, false, nil, "~=") |
| 109 | search.local_manifest_search(results, cfg.rocks_dir, query) | 109 | search.local_manifest_search(results, cfg.rocks_dir, query) |
| 110 | if results[name] then | 110 | if results[name] then |
| 111 | return remove.remove_search_results(results, name, cfg.deps_mode, force, fast) | 111 | 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) | |||
| 250 | end | 250 | end |
| 251 | end | 251 | end |
| 252 | 252 | ||
| 253 | function search.find_src_or_rockspec(ns_name, version, check_lua_versions) | 253 | function search.find_src_or_rockspec(name, namespace, version, check_lua_versions) |
| 254 | local query = queries.new(ns_name, version, false, "src|rockspec") | 254 | local query = queries.new(name, namespace, version, false, "src|rockspec") |
| 255 | local url, err = search.find_rock_checking_lua_versions(query, check_lua_versions) | 255 | local url, err = search.find_rock_checking_lua_versions(query, check_lua_versions) |
| 256 | if not url then | 256 | if not url then |
| 257 | return nil, "Could not find a result named "..tostring(query)..": "..err | 257 | 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) | |||
| 215 | return prog | 215 | return prog |
| 216 | end | 216 | end |
| 217 | 217 | ||
| 218 | function util.format_rock_name(name, namespace, version) | ||
| 219 | return (namespace and namespace.."/" or "")..name..(version and " "..version or "") | ||
| 220 | end | ||
| 221 | |||
| 218 | function util.deps_mode_option(parser, program) | 222 | function util.deps_mode_option(parser, program) |
| 219 | local cfg = require("luarocks.core.cfg") | 223 | local cfg = require("luarocks.core.cfg") |
| 220 | 224 | ||
| @@ -338,30 +342,6 @@ function util.LQ(s) | |||
| 338 | return ("%q"):format(s) | 342 | return ("%q"):format(s) |
| 339 | end | 343 | end |
| 340 | 344 | ||
| 341 | --- Normalize the --namespace option and the user/rock syntax for namespaces. | ||
| 342 | -- If a namespace is given in user/rock syntax, update the --namespace option; | ||
| 343 | -- If a namespace is given in --namespace option, update the user/rock syntax. | ||
| 344 | -- In case of conflicts, the user/rock syntax takes precedence. | ||
| 345 | function util.adjust_name_and_namespace(ns_name, args) | ||
| 346 | assert(type(ns_name) == "string" or not ns_name) | ||
| 347 | assert(type(args) == "table") | ||
| 348 | |||
| 349 | if not ns_name then | ||
| 350 | return | ||
| 351 | elseif ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then | ||
| 352 | return ns_name | ||
| 353 | end | ||
| 354 | |||
| 355 | local name, namespace = util.split_namespace(ns_name) | ||
| 356 | if namespace then | ||
| 357 | args.namespace = namespace | ||
| 358 | end | ||
| 359 | if args.namespace then | ||
| 360 | name = args.namespace .. "/" .. name | ||
| 361 | end | ||
| 362 | return name:lower() | ||
| 363 | end | ||
| 364 | |||
| 365 | -- Split name and namespace of a package name. | 345 | -- Split name and namespace of a package name. |
| 366 | -- @param ns_name a name that may be in "namespace/name" format | 346 | -- @param ns_name a name that may be in "namespace/name" format |
| 367 | -- @return string, string? - name and optionally a namespace | 347 | -- @return string, string? - name and optionally a namespace |
| @@ -373,6 +353,27 @@ function util.split_namespace(ns_name) | |||
| 373 | return ns_name | 353 | return ns_name |
| 374 | end | 354 | end |
| 375 | 355 | ||
| 356 | --- Argparse action callback for namespaced rock arguments. | ||
| 357 | function util.namespaced_name_action(args, target, ns_name) | ||
| 358 | assert(type(args) == "table") | ||
| 359 | assert(type(target) == "string") | ||
| 360 | assert(type(ns_name) == "string" or not ns_name) | ||
| 361 | |||
| 362 | if not ns_name then | ||
| 363 | return | ||
| 364 | end | ||
| 365 | |||
| 366 | if ns_name:match("%.rockspec$") or ns_name:match("%.rock$") then | ||
| 367 | args[target] = ns_name | ||
| 368 | else | ||
| 369 | local name, namespace = util.split_namespace(ns_name) | ||
| 370 | args[target] = name:lower() | ||
| 371 | if namespace then | ||
| 372 | args.namespace = namespace:lower() | ||
| 373 | end | ||
| 374 | end | ||
| 375 | end | ||
| 376 | |||
| 376 | function util.deep_copy(tbl) | 377 | function util.deep_copy(tbl) |
| 377 | local copy = {} | 378 | local copy = {} |
| 378 | for k, v in pairs(tbl) do | 379 | for k, v in pairs(tbl) do |
