From 0823c4dd62e15515ad1e77cd20681b720485c564 Mon Sep 17 00:00:00 2001 From: Paul Ouellette Date: Thu, 13 Jun 2019 20:41:14 -0400 Subject: Move remaining commands to argparse --- src/bin/luarocks | 1 - src/bin/luarocks-admin | 1 - src/luarocks/admin/cmd/add.lua | 39 +++++---- src/luarocks/admin/cmd/make_manifest.lua | 31 +++---- src/luarocks/admin/cmd/refresh_cache.lua | 21 ++--- src/luarocks/admin/cmd/remove.lua | 33 ++++---- src/luarocks/cmd.lua | 4 +- src/luarocks/cmd/doc.lua | 51 ++++++------ src/luarocks/cmd/download.lua | 44 +++++----- src/luarocks/cmd/init.lua | 19 +++-- src/luarocks/cmd/install.lua | 97 ++++++++++------------ src/luarocks/cmd/list.lua | 39 ++++----- src/luarocks/cmd/make.lua | 96 +++++++++++----------- src/luarocks/cmd/new_version.lua | 55 ++++++++----- src/luarocks/cmd/pack.lua | 42 ++++------ src/luarocks/cmd/path.lua | 52 ++++++------ src/luarocks/cmd/purge.lua | 34 ++++---- src/luarocks/cmd/remove.lua | 45 ++++++----- src/luarocks/cmd/search.lua | 50 ++++++------ src/luarocks/cmd/show.lua | 83 ++++++++++--------- src/luarocks/cmd/test.lua | 52 ++++++------ src/luarocks/cmd/unpack.lua | 35 ++++---- src/luarocks/cmd/upload.lua | 67 ++++++++------- src/luarocks/cmd/which.lua | 31 +++---- src/luarocks/cmd/write_rockspec.lua | 135 +++++++++++++++++++------------ src/luarocks/deps.lua | 5 +- src/luarocks/upload/api.lua | 4 +- 27 files changed, 598 insertions(+), 568 deletions(-) diff --git a/src/bin/luarocks b/src/bin/luarocks index f277b348..18c8fac6 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -9,7 +9,6 @@ local cmd = require("luarocks.cmd") local description = "LuaRocks main command-line interface" local commands = { - help = "luarocks.cmd.help", init = "luarocks.cmd.init", pack = "luarocks.cmd.pack", unpack = "luarocks.cmd.unpack", diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index ddbe0f48..db746bea 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin @@ -9,7 +9,6 @@ local cmd = require("luarocks.cmd") local description = "LuaRocks repository administration interface" local commands = { - help = "luarocks.cmd.help", make_manifest = "luarocks.admin.cmd.make_manifest", add = "luarocks.admin.cmd.add", remove = "luarocks.admin.cmd.remove", diff --git a/src/luarocks/admin/cmd/add.lua b/src/luarocks/admin/cmd/add.lua index 19990b3c..fa198baf 100644 --- a/src/luarocks/admin/cmd/add.lua +++ b/src/luarocks/admin/cmd/add.lua @@ -11,20 +11,21 @@ local fs = require("luarocks.fs") local cache = require("luarocks.admin.cache") local index = require("luarocks.admin.index") -add.help_summary = "Add a rock or rockspec to a rocks server." -add.help_arguments = "[--server=] [--no-refresh] {|...}" -add.help = [[ -Arguments are local files, which may be rockspecs or rocks. -The flag --server indicates which server to use. -If not given, the default server set in the upload_server variable -from the configuration file is used instead. - ---no-refresh The local cache should not be refreshed - prior to generation of the updated manifest. ---index Produce an index.html file for the manifest. - This flag is automatically set if an index.html - file already exists. -]] +function add.add_to_parser(parser) + local cmd = parser:command("add", "Add a rock or rockspec to a rocks server.", + util.see_also()) + :add_help(false) + + cmd:argument("rock", "A local rockspec or rock file.") + :args("+") + + cmd:option("--server", "The server to use. If not given, the default server ".. + "set in the upload_server variable from the configuration file is used instead.") + cmd:flag("--no-refresh", "Do not refresh the local cache prior to ".. + "generation of the updated manifest.") + cmd:flag("--index", "Produce an index.html file for the manifest. This ".. + "flag is automatically set if an index.html file already exists.") +end local function zip_manifests() for ver in util.lua_versions() do @@ -124,14 +125,10 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server, do return fs.execute(cmd) end -function add.command(flags, ...) - local files = {...} - if #files < 1 then - return nil, "Argument missing. "..util.see_help("add", "luarocks-admin") - end - local server, server_table = cache.get_upload_server(flags["server"]) +function add.command(args) + local server, server_table = cache.get_upload_server(args["server"]) if not server then return nil, server_table end - return add_files_to_server(not flags["no-refresh"], files, server, server_table, flags["index"]) + return add_files_to_server(not args["no_refresh"], files, server, server_table, args["index"]) end diff --git a/src/luarocks/admin/cmd/make_manifest.lua b/src/luarocks/admin/cmd/make_manifest.lua index f0b64135..dba7ccf8 100644 --- a/src/luarocks/admin/cmd/make_manifest.lua +++ b/src/luarocks/admin/cmd/make_manifest.lua @@ -11,36 +11,37 @@ local deps = require("luarocks.deps") local fs = require("luarocks.fs") local dir = require("luarocks.dir") -make_manifest.help_summary = "Compile a manifest file for a repository." +function make_manifest.add_to_parser(parser) + local cmd = parser:command("make_manifest", "Compile a manifest file for a repository.", + util.see_also()) + :add_help(false) -make_manifest.help = [[ -, if given, is a local repository pathname. + cmd:argument("repository", "Local repository pathname.") + :args("?") ---local-tree If given, do not write versioned versions of the manifest file. - Use this when rebuilding the manifest of a local rocks tree. -]] + cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n".. + "Use this when rebuilding the manifest of a local rocks tree.") + cmd:option("--deps-mode"):hidden(true) -- TODO: Description? +end --- Driver function for "make_manifest" command. --- @param repo string or nil: Pathname of a local repository. If not given, --- 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.command(flags, repo) - assert(type(repo) == "string" or not repo) - repo = repo or cfg.rocks_dir +function make_manifest.command(args) + local repo = args.repository or cfg.rocks_dir util.printout("Making manifest for "..repo) - if repo:match("/lib/luarocks") and not flags["local-tree"] then + if repo:match("/lib/luarocks") and not args["local_tree"] then util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") end - local ok, err = writer.make_manifest(repo, deps.get_deps_mode(flags), not flags["local-tree"]) - if ok and not flags["local-tree"] then + local ok, err = writer.make_manifest(repo, deps.get_deps_mode(args), not args["local_tree"]) + if ok and not args["local_tree"] then util.printout("Generating index.html for "..repo) index.make_index(repo) end - if flags["local-tree"] then + if args["local_tree"] then for luaver in util.lua_versions() do fs.delete(dir.path(repo, "manifest-"..luaver)) end diff --git a/src/luarocks/admin/cmd/refresh_cache.lua b/src/luarocks/admin/cmd/refresh_cache.lua index 3ffe56d9..0b2574b8 100644 --- a/src/luarocks/admin/cmd/refresh_cache.lua +++ b/src/luarocks/admin/cmd/refresh_cache.lua @@ -3,18 +3,21 @@ local refresh_cache = {} local cfg = require("luarocks.core.cfg") +local util = require("luarocks.util") local cache = require("luarocks.admin.cache") -refresh_cache.help_summary = "Refresh local cache of a remote rocks server." -refresh_cache.help_arguments = "[--from=]" -refresh_cache.help = [[ -The flag --from indicates which server to use. -If not given, the default server set in the upload_server variable -from the configuration file is used instead. -]] +function refresh_cache.add_to_parser(parser) + local cmd = parser:command( + "refresh_cache", "Refresh local cache of a remote rocks server.", util.see_also()) + :add_help(false) -function refresh_cache.command(flags) - local server, upload_server = cache.get_upload_server(flags["server"]) + cmd:option("--from", "The server to use. If not given, the default server ".. + "set in the upload_server variable from the configuration file is used instead.") + :argname("") +end + +function refresh_cache.command(args) + local server, upload_server = cache.get_upload_server(args["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/admin/cmd/remove.lua b/src/luarocks/admin/cmd/remove.lua index f005c83c..4c0125a9 100644 --- a/src/luarocks/admin/cmd/remove.lua +++ b/src/luarocks/admin/cmd/remove.lua @@ -11,16 +11,19 @@ local fs = require("luarocks.fs") local cache = require("luarocks.admin.cache") local index = require("luarocks.admin.index") -admin_remove.help_summary = "Remove a rock or rockspec from a rocks server." -admin_remove.help_arguments = "[--server=] [--no-refresh] {|...}" -admin_remove.help = [[ -Arguments are local files, which may be rockspecs or rocks. -The flag --server indicates which server to use. -If not given, the default server set in the upload_server variable -from the configuration file is used instead. -The flag --no-refresh indicates the local cache should not be refreshed -prior to generation of the updated manifest. -]] +function admin_remove.add_to_parser(parser) + local cmd = parser:command( + "remove", "Remove a rock or rockspec from a rocks server.", util.see_also()) + :add_help(false) + + cmd:argument("rock", "A local rockspec or rock file.") + :args("+") + + cmd:option("--server", "The server to use. If not given, the default server ".. + "set in the upload_server variable from the configuration file is used instead.") + cmd:flag("--no-refresh", "Do not refresh the local cache prior to ".. + "generation of the updated manifest.") +end local function remove_files_from_server(refresh, rockfiles, server, upload_server) assert(type(refresh) == "boolean" or not refresh) @@ -76,14 +79,10 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve return true end -function admin_remove.command(flags, ...) - local files = {...} - if #files < 1 then - return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin") - end - local server, server_table = cache.get_upload_server(flags["server"]) +function admin_remove.command(args) + local server, server_table = cache.get_upload_server(args["server"]) if not server then return nil, server_table end - return remove_files_from_server(not flags["no-refresh"], files, server, server_table) + return remove_files_from_server(not args["no_refresh"], files, server, server_table) end diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 4929b326..34dc75d8 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -394,9 +394,7 @@ Variables: parser:option("--only-sources-from"):target("only_sources"):hidden(true) for _, module in util.sortedpairs(cmd_modules) do - if module.add_to_parser then -- TODO: Remove this check. - module.add_to_parser(parser) - end + module.add_to_parser(parser) end return parser diff --git a/src/luarocks/cmd/doc.lua b/src/luarocks/cmd/doc.lua index a2472be4..74508fab 100644 --- a/src/luarocks/cmd/doc.lua +++ b/src/luarocks/cmd/doc.lua @@ -12,19 +12,23 @@ local fetch = require("luarocks.fetch") local fs = require("luarocks.fs") local download = require("luarocks.download") -doc.help_summary = "Show documentation for an installed rock." - -doc.help = [[ - is an existing package name. -Without any flags, tries to load the documentation -using a series of heuristics. -With these flags, return only the desired information: - ---home Open the home page of project. ---list List documentation files only. - -For more information about a rock, see the 'show' command. -]] +function doc.add_to_parser(parser) + local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n".. + "Without any flags, tries to load the documentation using a series of heuristics.\n".. + "With flags, return only the desired information.", util.see_also([[ + For more information about a rock, see the 'show' command. +]])) + :summary("Show documentation for an installed rock.") + :add_help(false) + + cmd:argument("rock", "Name of the rock.") + cmd:argument("version", "Version of the rock.") + :args("?") + + cmd:flag("--home", "Open the home page of project.") + cmd:flag("--list", "List documentation files only.") + cmd:flag("--porcelain"):hidden(true) -- TODO: Description? +end local function show_homepage(homepage, name, version) if not homepage then @@ -54,17 +58,12 @@ local function try_to_open_homepage(name, version) end --- Driver function for "doc" command. --- @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.command(flags, name, version) - if not name then - return nil, "Argument missing. "..util.see_help("doc") - end - - name = util.adjust_name_and_namespace(name, flags) +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 iname, iversion, repo = search.pick_installed_rock(query, flags["tree"]) + 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) @@ -75,7 +74,7 @@ function doc.command(flags, name, version) if not rockspec then return nil,err end local descript = rockspec.description or {} - if flags["home"] then + if args["home"] then return show_homepage(descript.homepage, name, version) end @@ -91,7 +90,7 @@ function doc.command(flags, name, version) end end if not docdir then - if descript.homepage and not flags["list"] then + if descript.homepage and not args["list"] then util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") fs.browser(descript.homepage) return true @@ -105,7 +104,7 @@ function doc.command(flags, name, version) local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" } local basenames = { "index", "readme", "manual" } - local porcelain = flags["porcelain"] + local porcelain = args["porcelain"] if #files > 0 then util.title("Documentation files for "..name.." "..version, porcelain) if porcelain then @@ -120,7 +119,7 @@ function doc.command(flags, name, version) end end - if flags["list"] then + if args["list"] then return true end diff --git a/src/luarocks/cmd/download.lua b/src/luarocks/cmd/download.lua index 50c10c0c..80897d5a 100644 --- a/src/luarocks/cmd/download.lua +++ b/src/luarocks/cmd/download.lua @@ -6,42 +6,46 @@ local cmd_download = {} local util = require("luarocks.util") local download = require("luarocks.download") -cmd_download.help_summary = "Download a specific rock file from a rocks server." -cmd_download.help_arguments = "[--all] [--arch= | --source | --rockspec] [ []]" -cmd_download.help = [[ ---all Download all files if there are multiple matches. ---source Download .src.rock if available. ---rockspec Download .rockspec if available. ---arch= Download rock for a specific architecture. -]] +function cmd_download.add_to_parser(parser) + local cmd = parser:command( + "download", "Download a specific rock file from a rocks server.", util.see_also()) + :add_help(false) + + cmd:argument("name", "Name of the rock.") + :args("?") + cmd:argument("version", "Version of the rock.") + :args("?") + + cmd:flag("--all", "Download all files if there are multiple matches.") + cmd:mutex( + cmd:flag("--source", "Download .src.rock if available."), + cmd:flag("--rockspec", "Download .rockspec if available."), + cmd:option("--arch", "Download rock for a specific architecture.")) +end --- Driver function for the "download" command. --- @param name string: a rock name. --- @param version string or nil: if the name of a package is given, a --- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function cmd_download.command(flags, name, version) - assert(type(version) == "string" or not version) - if type(name) ~= "string" and not flags["all"] then +function cmd_download.command(args) + if not args.name and not args["all"] then return nil, "Argument missing. "..util.see_help("download") end - name = util.adjust_name_and_namespace(name, flags) + local name = util.adjust_name_and_namespace(args.name, args) if not name then name, version = "", "" end local arch - if flags["source"] then + if args["source"] then arch = "src" - elseif flags["rockspec"] then + elseif args["rockspec"] then arch = "rockspec" - elseif flags["arch"] then - arch = flags["arch"] + elseif args["arch"] then + arch = args["arch"] end - local dl, err = download.download(arch, name:lower(), version, flags["all"]) + local dl, err = download.download(arch, name:lower(), version, args["all"]) return dl and true, err end diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua index fc14baf6..1053850d 100644 --- a/src/luarocks/cmd/init.lua +++ b/src/luarocks/cmd/init.lua @@ -14,8 +14,10 @@ function init.add_to_parser(parser) local cmd = parser:command("init", "Initialize a directory for a Lua project using LuaRocks.", util.see_also()) :add_help(false) - cmd:argument("name", "The project name."):args("?") - cmd:argument("version", "An optional project version."):args("?") + cmd:argument("name", "The project name.") + :args("?") + cmd:argument("version", "An optional project version.") + :args("?") cmd:flag("--reset", "Delete .luarocks/config-5.x.lua and ./lua and generate new ones.") cmd:group("Options for specifying rockspec data", @@ -60,15 +62,14 @@ function init.command(args) local pwd = fs.current_dir() - local name = args.name - if not name then - name = dir.base_name(pwd) - if name == "/" then + if not args.name then + args.name = dir.base_name(pwd) + if args.name == "/" then return nil, "When running from the root directory, please specify the argument" end end - util.title("Initializing project '" .. name .. "' for Lua " .. cfg.lua_version .. " ...") + util.title("Initializing project '" .. args.name .. "' for Lua " .. cfg.lua_version .. " ...") util.printout("Checking your Lua installation ...") if not cfg.lua_found then @@ -88,7 +89,9 @@ function init.command(args) end if not has_rockspec then - local ok, err = write_rockspec.command(args, name, args.version or "dev", pwd) + args.version = args.version or "dev" + args.location = pwd + local ok, err = write_rockspec.command(args) if not ok then util.printerr(err) end diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index ec6da14f..3d3f0fe2 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua @@ -16,32 +16,28 @@ local cfg = require("luarocks.core.cfg") local cmd = require("luarocks.cmd") local dir = require("luarocks.dir") -install.help_summary = "Install a rock." - -install.help_arguments = "{| []}" - -install.help = [[ -Argument may be the name of a rock to be fetched from a repository -or a filename of a locally available rock. - ---keep Do not remove previously installed versions of the - rock after installing a new one. This behavior can - be made permanent by setting keep_other_versions=true - in the configuration file. - ---only-deps Installs only the dependencies of the rock. - ---no-doc Installs the rock without its documentation. - ---verify Verify signature of the rock being installed. - If rock is being downloaded, LuaRocks will attempt - to download the signature as well. If the rock is - local, the signature file should be in the same - directory. - You need the signer’s public key in your local - keyring for this option to work properly. - -]]--..util.deps_mode_help() +function install.add_to_parser(parser) + local cmd = parser:command("install", "Install a rock.", util.see_also()) + :add_help(false) + + cmd:argument("rock", "The name of a rock to be fetched from a repository ".. + "or a filename of a locally available rock.") + cmd:argument("version", "Version of the rock.") + :args("?") + + cmd:flag("--keep", "Do not remove previously installed versions of the ".. + "rock after building a new one. This behavior can be made permanent by ".. + "setting keep_other_versions=true in the configuration file.") + cmd:flag("--only-deps", "Installs only the dependencies of the rock.") + cmd:flag("--no-doc", "Installs the rock without its documentation.") + cmd:flag("--verify", "Verify signature of the rockspec or src.rock being ".. + "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. + "attempt to download the signature as well. Otherwise, the signature ".. + "file should be already available locally in the same directory.\n".. + "You need the signer’s public key in your local keyring for this ".. + "option to work properly.") + util.deps_mode_option(cmd) +end install.opts = util.opts_table("install.opts", { namespace = "string?", @@ -208,51 +204,46 @@ local function install_rock_file(filename, opts) end --- Driver function for the "install" command. --- @param name string: name of a binary rock. If an URL or pathname --- to a binary rock is given, fetches and installs it. If a rockspec or a --- source rock is given, forwards the request to the "build" command. +-- If an URL or pathname to a binary rock is given, fetches and installs it. +-- If a rockspec or a source rock is given, forwards the request to the "build" +-- command. -- If a package name is given, forwards the request to "search" and, -- if returned a result, installs the matching rock. --- @param version string: When passing a package name, a version number --- 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.command(flags, name, version) - if type(name) ~= "string" then - return nil, "Argument missing. "..util.see_help("install") - end - - name = util.adjust_name_and_namespace(name, flags) +function install.command(args) + args.rock = util.adjust_name_and_namespace(args.rock, args) - local ok, err = fs.check_command_permissions(flags) + local ok, err = fs.check_command_permissions(args) if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end - if name:match("%.rockspec$") or name:match("%.src%.rock$") then + if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then local build = require("luarocks.cmd.build") - return build.command(flags, name) - elseif name:match("%.rock$") then - local deps_mode = deps.get_deps_mode(flags) + return build.command(args) + elseif args.rock:match("%.rock$") then + local deps_mode = deps.get_deps_mode(args) local opts = install.opts({ - namespace = flags["namespace"], - keep = not not flags["keep"], - force = not not flags["force"], - force_fast = not not flags["force-fast"], - no_doc = not not flags["no-doc"], + namespace = args["namespace"], + keep = not not args["keep"], + force = not not args["force"], + force_fast = not not args["force_fast"], + no_doc = not not args["no_doc"], deps_mode = deps_mode, - verify = not not flags["verify"], + verify = not not args["verify"], }) - if flags["only-deps"] then - return install_rock_file_deps(name, opts) + if args["only_deps"] then + return install_rock_file_deps(args.rock, opts) else - return install_rock_file(name, opts) + return install_rock_file(args.rock, opts) end else - local url, err = search.find_suitable_rock(queries.new(name:lower(), version), true) + local url, err = search.find_suitable_rock(queries.new(args.rock:lower(), args.version), true) if not url then return nil, err end util.printout("Installing "..url) - return install.command(flags, url) + args.rock = url + return install.command(args) end end diff --git a/src/luarocks/cmd/list.lua b/src/luarocks/cmd/list.lua index 5e5cfac8..2bb7660f 100644 --- a/src/luarocks/cmd/list.lua +++ b/src/luarocks/cmd/list.lua @@ -10,16 +10,19 @@ local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") local path = require("luarocks.path") -list.help_summary = "List currently installed rocks." -list.help_arguments = "[--porcelain] " -list.help = [[ - is a substring of a rock name to filter by. +function list.add_to_parser(parser) + local cmd = parser:command("list", "List currently installed rocks.", util.see_also()) + :add_help(false) ---outdated List only rocks for which there is a - higher version available in the rocks server. + cmd:argument("filter", "A substring of a rock name to filter by.") + :args("?") + cmd:argument("version", "Rock version to filter by.") + :args("?") ---porcelain Produce machine-friendly output. -]] + cmd:flag("--outdated", "List only rocks for which there is a higher ".. + "version available in the rocks server.") + cmd:flag("--porcelain", "Produce machine-friendly output.") +end local function check_outdated(trees, query) local results_installed = {} @@ -65,20 +68,18 @@ local function list_outdated(trees, query, porcelain) end --- Driver function for "list" command. --- @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.command(flags, filter, version) - local query = queries.new(filter and filter:lower() or "", version, true) +function list.command(args) + local query = queries.new(args.filter and args.filter:lower() or "", args.version, true) local trees = cfg.rocks_trees local title = "Rocks installed for Lua "..cfg.lua_version - if flags["tree"] then - trees = { flags["tree"] } - title = title .. " in " .. flags["tree"] + if args["tree"] then + trees = { args["tree"] } + title = title .. " in " .. args["tree"] end - if flags["outdated"] then - return list_outdated(trees, query, flags["porcelain"]) + if args["outdated"] then + return list_outdated(trees, query, args["porcelain"]) end local results = {} @@ -88,8 +89,8 @@ function list.command(flags, filter, version) util.warning(err) end end - util.title(title, flags["porcelain"]) - search.print_result_tree(results, flags["porcelain"]) + util.title(title, args["porcelain"]) + search.print_result_tree(results, args["porcelain"]) return true end diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index 4d813864..a8084293 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua @@ -16,9 +16,8 @@ local deps = require("luarocks.deps") local writer = require("luarocks.manif.writer") local cmd = require("luarocks.cmd") -make.help_summary = "Compile package in current directory using a rockspec." -make.help_arguments = "[--pack-binary-rock] []" -make.help = [[ +function make.add_to_parser(parser) + local cmd = parser:command("make", [[ Builds sources in the current directory, but unlike "build", it does not fetch sources, etc., assuming everything is available in the current directory. If no argument is given, @@ -34,89 +33,86 @@ To install rocks, you'll normally want to use the "install" and NB: Use `luarocks install` with the `--only-deps` flag if you want to install only dependencies of the rockspec (see `luarocks help install`). - ---pack-binary-rock Do not install rock. Instead, produce a .rock file - with the contents of compilation in the current - directory. - ---keep Do not remove previously installed versions of the - rock after installing a new one. This behavior can - be made permanent by setting keep_other_versions=true - in the configuration file. - ---branch= Override the `source.branch` field in the loaded - rockspec. Allows to specify a different branch to - fetch. Particularly for "dev" rocks. - ---verify Verify signature of the rockspec or src.rock being - built. If the rockspec or src.rock is being downloaded, - LuaRocks will attempt to download the signature as well. - Otherwise, the signature file should be already - available locally in the same directory. - You need the signer’s public key in your local - keyring for this option to work properly. - ---sign To be used with --pack-binary-rock. Also produce - a signature file for the generated .rock file. - -]] +]], util.see_also()) + :summary("Compile package in current directory using a rockspec.") + :add_help(false) + + cmd:argument("rockspec", "Rockspec for the rock to build.") + :args("?") + + cmd:flag("--pack-binary-rock", "Do not install rock. Instead, produce a ".. + ".rock file with the contents of compilation in the current directory.") + cmd:flag("--keep", "Do not remove previously installed versions of the ".. + "rock after building a new one. This behavior can be made permanent by ".. + "setting keep_other_versions=true in the configuration file.") + cmd:option("--branch", "Override the `source.branch` field in the loaded ".. + "rockspec. Allows to specify a different branch to fetch. Particularly ".. + 'for "dev" rocks.') + :argname("") + cmd:flag("--verify", "Verify signature of the rockspec or src.rock being ".. + "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. + "attempt to download the signature as well. Otherwise, the signature ".. + "file should be already available locally in the same directory.\n".. + "You need the signer’s public key in your local keyring for this ".. + "option to work properly.") + cmd:flag("--sign", "To be used with --pack-binary-rock. Also produce a ".. + "signature file for the generated .rock file.") +end --- Driver function for "make" command. --- @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.command(flags, rockspec_filename) - assert(type(rockspec_filename) == "string" or not rockspec_filename) - - if not rockspec_filename then +function make.command(args) + local rockspec + if not args.rockspec then local err - rockspec_filename, err = util.get_default_rockspec() - if not rockspec_filename then + rockspec, err = util.get_default_rockspec() + if not rockspec then return nil, err end end - if not rockspec_filename:match("rockspec$") then + if not rockspec:match("rockspec$") then return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make") end - local rockspec, err, errcode = fetch.load_rockspec(rockspec_filename) + local rockspec, err, errcode = fetch.load_rockspec(rockspec) if not rockspec then return nil, err end - local name = util.adjust_name_and_namespace(rockspec.name, flags) + local name = util.adjust_name_and_namespace(rockspec.name, args) local opts = build.opts({ need_to_fetch = false, minimal_mode = true, - deps_mode = deps.get_deps_mode(flags), + deps_mode = deps.get_deps_mode(args), build_only_deps = false, - namespace = flags["namespace"], - branch = not not flags["branch"], - verify = not not flags["verify"], + namespace = args["namespace"], + branch = not not args["branch"], + verify = not not args["verify"], }) - if flags["sign"] and not flags["pack-binary-rock"] then + if args["sign"] and not args["pack_binary_rock"] then return nil, "In the make command, --sign is meant to be used only with --pack-binary-rock" end - if flags["pack-binary-rock"] then - return pack.pack_binary_rock(name, rockspec.version, flags["sign"], function() + if args["pack_binary_rock"] then + return pack.pack_binary_rock(name, rockspec.version, args["sign"], function() return build.build_rockspec(rockspec, opts) end) else - local ok, err = fs.check_command_permissions(flags) + local ok, err = fs.check_command_permissions(args) if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end ok, err = build.build_rockspec(rockspec, opts) if not ok then return nil, err end local name, version = ok, err - if (not flags["keep"]) and not cfg.keep_other_versions then - local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"]) + if (not args["keep"]) and not cfg.keep_other_versions then + local ok, err = remove.remove_other_versions(name, version, args["force"], args["force_fast"]) if not ok then util.printerr(err) end end - writer.check_dependencies(nil, deps.get_deps_mode(flags)) + writer.check_dependencies(nil, deps.get_deps_mode(args)) return name, version end end diff --git a/src/luarocks/cmd/new_version.lua b/src/luarocks/cmd/new_version.lua index 19b5fa1e..37d4206e 100644 --- a/src/luarocks/cmd/new_version.lua +++ b/src/luarocks/cmd/new_version.lua @@ -11,9 +11,8 @@ local fs = require("luarocks.fs") local dir = require("luarocks.dir") local type_rockspec = require("luarocks.type.rockspec") -new_version.help_summary = "Auto-write a rockspec for a new version of a rock." -new_version.help_arguments = "[--tag=] [--dir=] [|] [] []" -new_version.help = [[ +function new_version.add_to_parser(parser) + local cmd = parser:command("new_version", [[ This is a utility function that writes a new rockspec, updating data from a previous one. @@ -22,7 +21,7 @@ default server. If a rockspec is given, it uses it instead. If no argument is given, it looks for a rockspec same way 'luarocks make' does. If the version number is not given and tag is passed using --tag, -it is used as the version, with 'v' removed from beginning. +it is used as the version, with 'v' removed from beginnnumbering. Otherwise, it only increments the revision number of the given (or downloaded) rockspec. @@ -38,8 +37,21 @@ an old tag but no new one passed, it is guessed in the same way URL is. If a directory is not given, it defaults to the current directory. WARNING: it writes the new rockspec to the given directory, -overwriting the file if it already exists. -]] +overwriting the file if it already exists.]], util.see_also()) + :summary("Auto-write a rockspec for a new version of a rock.") + :add_help(false) + + cmd:argument("rock", "Package name or rockspec.") + :args("?") + cmd:argument("new_version", "New version of the rock.") + :args("?") + cmd:argument("new_url", "New URL of the rock.") + :args("?") + + cmd:option("--dir", "Output directory for the new rockspec.") + cmd:option("--tag", "New SCM tag.") +end + local function try_replace(tbl, field, old, new) if not tbl[field] then @@ -126,24 +138,23 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver) return true end -function new_version.command(flags, input, version, url) - if not input then +function new_version.command(args) + if not args.input then local err - input, err = util.get_default_rockspec() - if not input then + args.input, err = util.get_default_rockspec() + if not args.input then return nil, err end end - assert(type(input) == "string") local filename, err - if input:match("rockspec$") then - filename, err = fetch.fetch_url(input) + if args.input:match("rockspec$") then + filename, err = fetch.fetch_url(args.input) if not filename then return nil, err end else - filename, err = download.download("rockspec", input:lower()) + filename, err = download.download("rockspec", args.input:lower()) if not filename then return nil, err end @@ -157,20 +168,20 @@ function new_version.command(flags, input, version, url) local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") local new_ver, new_rev - if flags.tag and not version then - version = flags.tag:gsub("^v", "") + if args.tag and not args.new_version then + args.new_version = args.tag:gsub("^v", "") end local out_dir - if flags.dir then - out_dir = dir.normalize(flags.dir) + if args.dir then + out_dir = dir.normalize(args.dir) end - if version then - new_ver, new_rev = version:match("(.*)%-(%d+)$") + if args.new_version then + new_ver, new_rev = args.new_version:match("(.*)%-(%d+)$") new_rev = tonumber(new_rev) if not new_rev then - new_ver = version + new_ver = args.new_version new_rev = 1 end else @@ -183,7 +194,7 @@ function new_version.command(flags, input, version, url) local out_name = out_rs.package:lower() out_rs.version = new_rockver.."-"..new_rev - local ok, err = update_source_section(out_rs, url, flags.tag, old_ver, new_ver) + local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver) if not ok then return nil, err end if out_rs.build and out_rs.build.type == "module" then diff --git a/src/luarocks/cmd/pack.lua b/src/luarocks/cmd/pack.lua index 7781a3bd..e5e7f525 100644 --- a/src/luarocks/cmd/pack.lua +++ b/src/luarocks/cmd/pack.lua @@ -8,39 +8,31 @@ local pack = require("luarocks.pack") local signing = require("luarocks.signing") local queries = require("luarocks.queries") -cmd_pack.help_summary = "Create a rock, packing sources or binaries." -cmd_pack.help_arguments = "{| []}" -cmd_pack.help = [[ ---sign Produce a signature file as well. +function cmd_pack.add_to_parser(parser) + local cmd = parser:command("pack", "Create a rock, packing sources or binaries.", util.see_also()) + :add_help(false) -Argument may be a rockspec file, for creating a source rock, -or the name of an installed package, for creating a binary rock. -In the latter case, the app version may be given as a second -argument. -]] + cmd:argument("rock", "A rockspec file, for creating a source rock, or the ".. + "name of an installed package, for creating a binary rock.") + cmd:argument("version", "A version may be given if the first argument is a rock name.") + :args("?") + + cmd:flag("--sign", "Produce a signature file as well.") +end --- Driver function for the "pack" command. --- @param arg string: may be a rockspec file, for creating a source rock, --- or the name of an installed package, for creating a binary rock. --- @param version string or nil: if the name of a package is given, a --- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function cmd_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") - end - +function cmd_pack.command(args) local file, err - if arg:match(".*%.rockspec") then - file, err = pack.pack_source_rock(arg) + if args.rock:match(".*%.rockspec") then + file, err = pack.pack_source_rock(args.rock) else - local name = util.adjust_name_and_namespace(arg, flags) - local query = queries.new(name, version) - file, err = pack.pack_installed_rock(query, flags["tree"]) + local name = util.adjust_name_and_namespace(args.rock, args) + local query = queries.new(name, args.version) + file, err = pack.pack_installed_rock(query, args["tree"]) end - return pack.report_and_sign_local_file(file, err, flags["sign"]) + return pack.report_and_sign_local_file(file, err, args["sign"]) end return cmd_pack diff --git a/src/luarocks/cmd/path.lua b/src/luarocks/cmd/path.lua index bb383ad9..8921d2a5 100644 --- a/src/luarocks/cmd/path.lua +++ b/src/luarocks/cmd/path.lua @@ -7,48 +7,46 @@ local util = require("luarocks.util") local cfg = require("luarocks.core.cfg") local fs = require("luarocks.fs") -path_cmd.help_summary = "Return the currently configured package path." -path_cmd.help_arguments = "" -path_cmd.help = [[ +function path_cmd.add_to_parser(parser) + local cmd = parser:command("path", [[ Returns the package path currently configured for this installation of LuaRocks, formatted as shell commands to update LUA_PATH and LUA_CPATH. ---no-bin Do not export the PATH variable - ---append Appends the paths to the existing paths. Default is to prefix - the LR paths to the existing paths. - ---lr-path Exports the Lua path (not formatted as shell command) - ---lr-cpath Exports the Lua cpath (not formatted as shell command) - ---lr-bin Exports the system path (not formatted as shell command) - - On Unix systems, you may run: eval `luarocks path` And on Windows: - luarocks path > "%temp%\_lrp.bat" && call "%temp%\_lrp.bat" && del "%temp%\_lrp.bat" -]] + luarocks path > "%temp%\_lrp.bat" && call "%temp%\_lrp.bat" && del "%temp%\_lrp.bat"]], + util.see_also()) + :summary("Return the currently configured package path.") + :add_help(false) + + cmd:flag("--no-bin", "Do not export the PATH variable.") + cmd:flag("--append", "Appends the paths to the existing paths. Default is ".. + "to prefix the LR paths to the existing paths.") + cmd:flag("--lr-path", "Exports the Lua path (not formatted as shell command).") + cmd:flag("--lr-cpath", "Exports the Lua cpath (not formatted as shell command).") + cmd:flag("--lr-bin", "Exports the system path (not formatted as shell command).") + cmd:flag("--bin"):hidden(true) +end --- Driver function for "path" command. -- @return boolean This function always succeeds. -function path_cmd.command(flags) - local lr_path, lr_cpath, lr_bin = cfg.package_paths(flags["tree"]) +function path_cmd.command(args) + local lr_path, lr_cpath, lr_bin = cfg.package_paths(args["tree"]) local path_sep = cfg.export_path_separator - if flags["lr-path"] then + if args["lr_path"] then util.printout(util.cleanup_path(lr_path, ';', cfg.lua_version)) return true - elseif flags["lr-cpath"] then + elseif args["lr_cpath"] then util.printout(util.cleanup_path(lr_cpath, ';', cfg.lua_version)) return true - elseif flags["lr-bin"] then + elseif args["lr_bin"] then util.printout(util.cleanup_path(lr_bin, path_sep)) return true end - if flags["append"] then + if args["append"] then lr_path = package.path .. ";" .. lr_path lr_cpath = package.cpath .. ";" .. lr_cpath lr_bin = os.getenv("PATH") .. path_sep .. lr_bin @@ -60,10 +58,10 @@ function path_cmd.command(flags) local lpath_var, lcpath_var = util.lua_path_variables() - util.printout(fs.export_cmd(lpath_var, util.cleanup_path(lr_path, ';', cfg.lua_version, flags["append"]))) - util.printout(fs.export_cmd(lcpath_var, util.cleanup_path(lr_cpath, ';', cfg.lua_version, flags["append"]))) - if not flags["no-bin"] then - util.printout(fs.export_cmd("PATH", util.cleanup_path(lr_bin, path_sep, nil, flags["append"]))) + util.printout(fs.export_cmd(lpath_var, util.cleanup_path(lr_path, ';', cfg.lua_version))) + util.printout(fs.export_cmd(lcpath_var, util.cleanup_path(lr_cpath, ';', cfg.lua_version))) + if not args["no_bin"] then + util.printout(fs.export_cmd("PATH", util.cleanup_path(lr_bin, path_sep))) end return true end diff --git a/src/luarocks/cmd/purge.lua b/src/luarocks/cmd/purge.lua index 98b76a0f..9b1e2ae9 100644 --- a/src/luarocks/cmd/purge.lua +++ b/src/luarocks/cmd/purge.lua @@ -15,24 +15,24 @@ local remove = require("luarocks.remove") local queries = require("luarocks.queries") local cmd = require("luarocks.cmd") -purge.help_summary = "Remove all installed rocks from a tree." -purge.help_arguments = "--tree= [--old-versions]" -purge.help = [[ +function purge.add_to_parser(parser) + local cmd = parser:command("purge", [[ This command removes rocks en masse from a given tree. By default, it removes all rocks from a tree. -The --tree argument is mandatory: luarocks purge does not -assume a default tree. +The --tree option is mandatory: luarocks purge does not assume a default tree.]], + util.see_also()) + :summary("Remove all installed rocks from a tree.") + :add_help(false) ---old-versions Keep the highest-numbered version of each - rock and remove the other ones. By default - it only removes old versions if they are - not needed as dependencies. This can be - overridden with the flag --force. -]] + cmd:flag("--old-versions", "Keep the highest-numbered version of each ".. + "rock and remove the other ones. By default it only removes old ".. + "versions if they are not needed as dependencies. This can be ".. + "overridden with the flag --force.") +end -function purge.command(flags) - local tree = flags["tree"] +function purge.command(args) + local tree = args["tree"] if type(tree) ~= "string" then return nil, "The --tree argument is mandatory. "..util.see_help("purge") @@ -43,21 +43,21 @@ function purge.command(flags) return nil, "Directory not found: "..tree end - local ok, err = fs.check_command_permissions(flags) + local ok, err = fs.check_command_permissions(args) if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end search.local_manifest_search(results, path.rocks_dir(tree), queries.all()) local sort = function(a,b) return vers.compare_versions(b,a) end - if flags["old-versions"] then + if args["old_versions"] then sort = vers.compare_versions end for package, versions in util.sortedpairs(results) do for version, _ in util.sortedpairs(versions, sort) do - if flags["old-versions"] then + if args["old_versions"] then util.printout("Keeping "..package.." "..version.."...") - local ok, err = remove.remove_other_versions(package, version, flags["force"], flags["force-fast"]) + local ok, err = remove.remove_other_versions(package, version, args["force"], args["force_fast"]) if not ok then util.printerr(err) end diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua index f9345670..e311f399 100644 --- a/src/luarocks/cmd/remove.lua +++ b/src/luarocks/cmd/remove.lua @@ -14,38 +14,39 @@ local writer = require("luarocks.manif.writer") local queries = require("luarocks.queries") local cmd = require("luarocks.cmd") -cmd_remove.help_summary = "Uninstall a rock." -cmd_remove.help_arguments = "[--force|--force-fast] []" -cmd_remove.help = [[ -Argument is the name of a rock to be uninstalled. +function cmd_remove.add_to_parser(parser) + local cmd = parser:command("remove", [[ +Uninstall a rock. + If a version is not given, try to remove all versions at once. Will only perform the removal if it does not break dependencies. -To override this check and force the removal, use --force. -To perform a forced removal without reporting dependency issues, -use --force-fast. +To override this check and force the removal, use --force or --force-fast.]], + util.see_also()) + :summary("Uninstall a rock.") + :add_help(false) + + cmd:argument("rock", "Name of the rock to be uninstalled.") + cmd:argument("version", "Version of the rock to uninstall.") + :args("?") -]]--..util.deps_mode_help() + cmd:flag("--force", "Force removal if it would break dependencies.") + cmd:flag("--force-fast", "Perform a forced removal without reporting dependency issues.") + util.deps_mode_option(cmd) +end --- Driver function for the "remove" command. --- @param name string: name of a rock. If a version is given, refer to --- a specific version; otherwise, try to remove all versions. --- @param version string: When passing a package name, a version number --- 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 cmd_remove.command(flags, name, version) - if type(name) ~= "string" then - return nil, "Argument missing. "..util.see_help("remove") - end - - name = util.adjust_name_and_namespace(name, flags) +function cmd_remove.command(args) + local name = util.adjust_name_and_namespace(args.rock, args) - local deps_mode = flags["deps-mode"] or cfg.deps_mode + local deps_mode = args["deps_mode"] or cfg.deps_mode - local ok, err = fs.check_command_permissions(flags) + local ok, err = fs.check_command_permissions(args) if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") + local version = args.version local filename = name if rock_type then name, version = path.parse_name(filename) @@ -59,12 +60,12 @@ function cmd_remove.command(flags, name, version) return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) end - local ok, err = remove.remove_search_results(results, name, deps_mode, flags["force"], flags["force-fast"]) + local ok, err = remove.remove_search_results(results, name, deps_mode, args["force"], args["force_fast"]) if not ok then return nil, err end - writer.check_dependencies(nil, deps.get_deps_mode(flags)) + writer.check_dependencies(nil, deps.get_deps_mode(args)) return true end diff --git a/src/luarocks/cmd/search.lua b/src/luarocks/cmd/search.lua index 8f4d014e..d1546e80 100644 --- a/src/luarocks/cmd/search.lua +++ b/src/luarocks/cmd/search.lua @@ -9,17 +9,23 @@ local search = require("luarocks.search") local queries = require("luarocks.queries") local results = require("luarocks.results") -cmd_search.help_summary = "Query the LuaRocks servers." -cmd_search.help_arguments = "[--source] [--binary] { [] | --all }" -cmd_search.help = [[ ---source Return only rockspecs and source rocks, - to be used with the "build" command. ---binary Return only pure Lua and binary rocks (rocks that can be used - with the "install" command without requiring a C toolchain). ---all List all contents of the server that are suitable to - this platform, do not filter by name. ---porcelain Return a machine readable format. -]] +function cmd_search.add_to_parser(parser) + local cmd = parser:command("search", "Query the LuaRocks servers.", util.see_also()) + :add_help(false) + + cmd:argument("name", "Name of the rock to search for.") + :args("?") + cmd:argument("version", "Rock version to search for.") + :args("?") + + cmd:flag("--source", "Return only rockspecs and source rocks, to be used ".. + 'with the "build" command.') + cmd:flag("--binary", "Return only pure Lua and binary rocks (rocks that ".. + 'can be used with the "install" command without requiring a C toolchain).') + cmd:flag("--all", "List all contents of the server that are suitable to ".. + "this platform, do not filter by name.") + cmd:flag("--porcelain", "Return a machine readable format.") +end --- Splits a list of search results into two lists, one for "source" results -- to be used with the "build" command, and one for "binary" results to be @@ -45,33 +51,31 @@ local function split_source_and_binary_results(result_tree) end --- Driver function for "search" command. --- @param name string: A substring of a rock name to search. --- @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 cmd_search.command(flags, name, version) +function cmd_search.command(args) - name = util.adjust_name_and_namespace(name, flags) + local name = util.adjust_name_and_namespace(args.name, args) - if flags["all"] then - name, version = "", nil + if args["all"] then + name, args.version = "", nil end - if type(name) ~= "string" and not flags["all"] then + if not args.name and not args["all"] then return nil, "Enter name and version or use --all. "..util.see_help("search") end - local query = queries.new(name:lower(), version, true) + local query = queries.new(name:lower(), args.version, true) local result_tree, err = search.search_repos(query) - local porcelain = flags["porcelain"] - local full_name = name .. (version and " " .. version or "") + local porcelain = args["porcelain"] + local full_name = name .. (args.version and " " .. args.version or "") 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 flags["binary"] then + if next(sources) and not args["binary"] then util.title("Rockspecs and source rocks:", porcelain) search.print_result_tree(sources, porcelain) end - if next(binaries) and not flags["source"] then + if next(binaries) and not args["source"] then util.title("Binary and pure-Lua rocks:", porcelain) search.print_result_tree(binaries, porcelain) end diff --git a/src/luarocks/cmd/show.lua b/src/luarocks/cmd/show.lua index 37c2c55e..9bfedd20 100644 --- a/src/luarocks/cmd/show.lua +++ b/src/luarocks/cmd/show.lua @@ -13,24 +13,34 @@ local fetch = require("luarocks.fetch") local manif = require("luarocks.manif") local repos = require("luarocks.repos") -show.help_summary = "Show information about an installed rock." +function show.add_to_parser(parser) + local cmd = parser:command("show", [[ +Show information about an installed rock. -show.help = [[ - is an existing package name. Without any flags, show all module information. -With these flags, return only the desired information: +With flags, return only the desired information.]], util.see_also()) + :summary("Show information about an installed rock.") + :add_help(false) ---home home page of project ---modules all modules provided by this package as used by require() ---deps packages this package depends on ---build-deps build-only dependencies for this package ---test-deps dependencies for testing this package ---rockspec the full path of the rockspec file ---mversion the package version ---rock-tree local tree where rock is installed ---rock-dir data directory of the installed rock -]] + cmd:argument("rock", "Name of an installed rock.") + cmd:argument("version", "Rock version.") + :args("?") + cmd:flag("--home", "Show home page of project.") + cmd:flag("--modules", "Show all modules provided by the package as used by require().") + cmd:flag("--deps", "Show packages the package depends on.") + cmd:flag("--build-deps", "Show build-only dependencies for the package.") + cmd:flag("--test-deps", "Show dependencies for testing the package.") + cmd:flag("--rockspec", "Show the full path of the rockspec file.") + cmd:flag("--mversion", "Show the package version.") + cmd:flag("--rock-tree", "Show local tree where rock is installed.") + cmd:flag("--rock-namespace", "Show rock namespace.") + cmd:flag("--rock-dir", "Show data directory of the installed rock.") + cmd:flag("--rock-license", "Show rock license.") + cmd:flag("--issues", "Show URL for project's issue tracker.") + cmd:flag("--labels", "List the labels of the rock.") + cmd:flag("--porcelain", "Produce machine-friendly output.") +end local friendly_template = [[ : @@ -249,19 +259,14 @@ local function show_rock(template, namespace, name, version, rockspec, repo, min end --- Driver function for "show" command. --- @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.command(flags, name, version) - if not name then - return nil, "Argument missing. "..util.see_help("show") - end - - name = util.adjust_name_and_namespace(name, flags) +function show.command(args) + local name = util.adjust_name_and_namespace(args.rock, args) + local version = args.verson local query = queries.new(name, version) local repo, repo_url - name, version, repo, repo_url = search.pick_installed_rock(query, flags["tree"]) + name, version, repo, repo_url = search.pick_installed_rock(query, args["tree"]) if not name then return nil, version end @@ -277,32 +282,32 @@ function show.command(flags, name, version) if not manifest then return nil,err end local minfo = manifest.repository[name][version][1] - if flags["rock-tree"] then util.printout(tree) - elseif flags["rock-namespace"] then util.printout(namespace) - elseif flags["rock-dir"] then util.printout(directory) - elseif flags["home"] then util.printout(descript.homepage) - elseif flags["rock-license"] then util.printout(descript.license) - elseif flags["issues"] then util.printout(descript.issues_url) - elseif flags["labels"] then util.printout(descript.labels and table.concat(descript.labels, "\n")) - elseif flags["modules"] then util.printout(keys_as_string(minfo.modules, "\n")) - elseif flags["deps"] then + if args["rock_tree"] then util.printout(tree) + elseif args["rock_namespace"] then util.printout(namespace) + elseif args["rock_dir"] then util.printout(directory) + elseif args["home"] then util.printout(descript.homepage) + elseif args["rock_license"] then util.printout(descript.license) + elseif args["issues"] then util.printout(descript.issues_url) + elseif args["labels"] then util.printout(descript.labels and table.concat(descript.labels, "\n")) + elseif args["modules"] then util.printout(keys_as_string(minfo.modules, "\n")) + elseif args["deps"] then for _, dep in ipairs(rockspec.dependencies) do util.printout(tostring(dep)) end - elseif flags["build-deps"] then + elseif args["build_deps"] then for _, dep in ipairs(rockspec.build_dependencies) do util.printout(tostring(dep)) end - elseif flags["test-deps"] then + elseif args["test_deps"] then for _, dep in ipairs(rockspec.test_dependencies) do util.printout(tostring(dep)) end - elseif flags["rockspec"] then util.printout(rockspec_file) - elseif flags["mversion"] then util.printout(version) - elseif flags["porcelain"] then - show_rock(porcelain_template, namespace, name, version, rockspec, repo, minfo, flags["tree"]) + elseif args["rockspec"] then util.printout(rockspec_file) + elseif args["mversion"] then util.printout(version) + elseif args["porcelain"] then + show_rock(porcelain_template, namespace, name, version, rockspec, repo, minfo, args["tree"]) else - show_rock(friendly_template, namespace, name, version, rockspec, repo, minfo, flags["tree"]) + show_rock(friendly_template, namespace, name, version, rockspec, repo, minfo, args["tree"]) end return true end diff --git a/src/luarocks/cmd/test.lua b/src/luarocks/cmd/test.lua index 06ac0068..baf7515e 100644 --- a/src/luarocks/cmd/test.lua +++ b/src/luarocks/cmd/test.lua @@ -6,42 +6,44 @@ local cmd_test = {} local util = require("luarocks.util") local test = require("luarocks.test") -cmd_test.help_summary = "Run the test suite in the current directory." -cmd_test.help_arguments = "[--test-type=] [] [-- ]" -cmd_test.help = [[ +function cmd_test.add_to_parser(parser) + local cmd = parser:command("test", [[ Run the test suite for the Lua project in the current directory. -If the first argument is a rockspec, it will use it to determine -the parameters for running tests; otherwise, it will attempt to -detect the rockspec. -Any additional arguments are forwarded to the test suite. -To make sure that any flags passed in are not interpreted -as LuaRocks flags, use -- to separate LuaRocks arguments from -test suite arguments. - ---test-type= Specify the test suite type manually if it was not - specified in the rockspec and it could not be - auto-detected. - -]]--..util.deps_mode_help() - -function cmd_test.command(flags, argument, ...) - assert(type(argument) == "string" or not argument) - - local arguments = { ... } +If the first argument is a rockspec, it will use it to determine the parameters +for running tests; otherwise, it will attempt to detect the rockspec. + +Any additional arguments are forwarded to the test suite. +To make sure that test suite flags are not interpreted as LuaRocks flags, use -- +to separate LuaRocks arguments from test suite arguments.]], + util.see_also()) + :summary("Run the test suite in the current directory.") + :add_help(false) + + cmd:argument("rockspec", "Project rockspec.") + :args("?") + cmd:argument("args", "Test suite arguments.") + :args("*") + + cmd:option("--test-type", "Specify the test suite type manually if it was ".. + "not specified in the rockspec and it could not be auto-detected.") + :argname("") + util.deps_mode_option(cmd) +end - if argument and argument:match("rockspec$") then - return test.run_test_suite(argument, flags["test-type"], arguments) +function cmd_test.command(args) + if args.rockspec and args.rockspec:match("rockspec$") then + return test.run_test_suite(args.rockspec, args["test_type"], args.args) end - table.insert(arguments, 1, argument) + table.insert(args.args, 1, args.rockspec) local rockspec, err = util.get_default_rockspec() if not rockspec then return nil, err end - return test.run_test_suite(rockspec, flags["test-type"], arguments) + return test.run_test_suite(rockspec, args["test_type"], args.args) end return cmd_test diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua index 99263f49..65ce5c7c 100644 --- a/src/luarocks/cmd/unpack.lua +++ b/src/luarocks/cmd/unpack.lua @@ -10,15 +10,21 @@ local build = require("luarocks.build") local dir = require("luarocks.dir") local search = require("luarocks.search") -unpack.help_summary = "Unpack the contents of a rock." -unpack.help_arguments = "[--force] {| []}" -unpack.help = [[ +function unpack.add_to_parser(parser) + local cmd = parser:command("unpack", [[ Unpacks the contents of a rock in a newly created directory. Argument may be a rock file, or the name of a rock in a rocks server. -In the latter case, the app version may be given as a second argument. +In the latter case, the rock version may be given as a second argument.]], + util.see_also()) + :summary("Unpack the contents of a rock.") + :add_help(false) ---force Unpack files even if the output directory already exists. -]] + cmd:argument("rock", "A rock file or the name of a rock.") + cmd:argument("version", "Rock version.") + :args("?") + + cmd:flag("--force", "Unpack files even if the output directory already exists.") +end --- Load a rockspec file to the given directory, fetches the source -- files specified in the rockspec, and unpack them inside the directory. @@ -141,31 +147,22 @@ local function run_unpacker(file, force) end --- Driver function for the "unpack" command. --- @param ns_name string: may be a rock filename, for unpacking a --- rock file or the name of a rock to be fetched and unpacked. --- @param version string or nil: if the name of a package is given, a --- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function unpack.command(flags, ns_name, version) - assert(type(version) == "string" or not version) - if type(ns_name) ~= "string" then - return nil, "Argument missing. "..util.see_help("unpack") - end - - ns_name = util.adjust_name_and_namespace(ns_name, flags) +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 else - url, err = search.find_src_or_rockspec(ns_name, version, true) + url, err = search.find_src_or_rockspec(ns_name, args.version, true) if not url then return nil, err end end - return run_unpacker(url, flags["force"]) + return run_unpacker(url, args["force"]) end return unpack diff --git a/src/luarocks/cmd/upload.lua b/src/luarocks/cmd/upload.lua index b052500e..64bf18ad 100644 --- a/src/luarocks/cmd/upload.lua +++ b/src/luarocks/cmd/upload.lua @@ -8,37 +8,34 @@ local pack = require("luarocks.pack") local cfg = require("luarocks.core.cfg") local Api = require("luarocks.upload.api") -upload.help_summary = "Upload a rockspec to the public rocks repository." -upload.help_arguments = "[--skip-pack] [--api-key=] [--force] " -upload.help = [[ - Pack a source rock file (.src.rock extension), - upload rockspec and source rock to server. - ---skip-pack Do not pack and send source rock. - ---api-key= Give it an API key. It will be stored for subsequent uses. - ---temp-key= Use the given a temporary API key in this invocation only. - It will not be stored. - ---force Replace existing rockspec if the same revision of - a module already exists. This should be used only - in case of upload mistakes: when updating a rockspec, - increment the revision number instead. - ---sign Upload a signature file alongside each file as well. -]] +function upload.add_to_parser(parser) + local cmd = parser:command("upload", "Pack a source rock file (.src.rock extension) ".. + "and upload it and the rockspec to the public rocks repository.", util.see_also()) + :summary("Upload a rockspec to the public rocks repository.") + :add_help(false) + + cmd:argument("rockspec", "Rockspec for the rock to upload.") + + cmd:flag("--skip-pack", "Do not pack and send source rock.") + cmd:option("--api-key", "Pass an API key. It will be stored for subsequent uses.") + :argname("") + cmd:option("--temp-key", "Use the given a temporary API key in this ".. + "invocation only. It will not be stored.") + :argname("") + cmd:flag("--force", "Replace existing rockspec if the same revision of a ".. + "module already exists. This should be used only in case of upload ".. + "mistakes: when updating a rockspec, increment the revision number ".. + "instead.") + cmd:flag("--sign", "Upload a signature file alongside each file as well.") + cmd:flag("--debug"):hidden(true) +end local function is_dev_version(version) return version:match("^dev") or version:match("^scm") end -function upload.command(flags, fname) - if not fname then - return nil, "Missing rockspec. "..util.see_help("upload") - end - - local api, err = Api.new(flags) +function upload.command(args) + local api, err = Api.new(args) if not api then return nil, err end @@ -46,12 +43,12 @@ function upload.command(flags, fname) api.debug = true end - local rockspec, err, errcode = fetch.load_rockspec(fname) + local rockspec, err, errcode = fetch.load_rockspec(args.rockspec) if err then return nil, err, errcode end - util.printout("Sending " .. tostring(fname) .. " ...") + util.printout("Sending " .. tostring(args.rockspec) .. " ...") local res, err = api:method("check_rockspec", { package = rockspec.package, version = rockspec.version @@ -61,15 +58,15 @@ function upload.command(flags, fname) if not res.module then util.printout("Will create new module (" .. tostring(rockspec.package) .. ")") end - if res.version and not flags["force"] then + if res.version and not args["force"] then return nil, "Revision "..rockspec.version.." already exists on the server. "..util.see_help("upload") end local sigfname local rock_sigfname - if flags["sign"] then - sigfname, err = signing.sign_file(fname) + if args["sign"] then + sigfname, err = signing.sign_file(args.rockspec) if err then return nil, "Failed signing rockspec: " .. err end @@ -77,13 +74,13 @@ function upload.command(flags, fname) end local rock_fname - if not flags["skip-pack"] and not is_dev_version(rockspec.version) then + if not args["skip_pack"] and not is_dev_version(rockspec.version) then util.printout("Packing " .. tostring(rockspec.package)) - rock_fname, err = pack.pack_source_rock(fname) + rock_fname, err = pack.pack_source_rock(args.rockspec) if not rock_fname then return nil, err end - if flags["sign"] then + if args["sign"] then rock_sigfname, err = signing.sign_file(rock_fname) if err then return nil, "Failed signing rock: " .. err @@ -95,7 +92,7 @@ function upload.command(flags, fname) local multipart = require("luarocks.upload.multipart") res, err = api:method("upload", nil, { - rockspec_file = multipart.new_file(fname), + rockspec_file = multipart.new_file(args.rockspec), rockspec_sig = sigfname and multipart.new_file(sigfname), }) if not res then return nil, err end diff --git a/src/luarocks/cmd/which.lua b/src/luarocks/cmd/which.lua index 56db5254..571d2638 100644 --- a/src/luarocks/cmd/which.lua +++ b/src/luarocks/cmd/which.lua @@ -8,20 +8,21 @@ local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") local fs = require("luarocks.fs") -which_cmd.help_summary = "Tell which file corresponds to a given module name." -which_cmd.help_arguments = "" -which_cmd.help = [[ -Given a module name like "foo.bar", output which file would be loaded to resolve -that module by luarocks.loader, like "/usr/local/lua/]]..cfg.lua_version..[[/foo/bar.lua". -]] - ---- Driver function for "lua" command. +function which_cmd.add_to_parser(parser) + local cmd = parser:command("which", 'Given a module name like "foo.bar", '.. + "output which file would be loaded to resolve that module by ".. + 'luarocks.loader, like "/usr/local/lua/'..cfg.lua_version..'/foo/bar.lua".', + util.see_also()) + :summary("Tell which file corresponds to a given module name.") + :add_help(false) + + cmd:argument("modname", "Module name.") +end + +--- Driver function for "which" command. -- @return boolean This function terminates the interpreter. -function which_cmd.command(_, modname) - if modname == nil then - return nil, "Missing module name. " .. util.see_help("which") - end - local pathname, rock_name, rock_version = loader.which(modname) +function which_cmd.command(args) + local pathname, rock_name, rock_version = loader.which(args.modname) if pathname then util.printout(pathname) @@ -29,7 +30,7 @@ function which_cmd.command(_, modname) return true end - local modpath = modname:gsub("%.", "/") + local modpath = args.modname:gsub("%.", "/") for _, v in ipairs({"path", "cpath"}) do for p in package[v]:gmatch("([^;]+)") do local pathname = p:gsub("%?", modpath) @@ -41,7 +42,7 @@ function which_cmd.command(_, modname) end end - return nil, "Module '" .. modname .. "' not found." + return nil, "Module '" .. args.modname .. "' not found." end return which_cmd diff --git a/src/luarocks/cmd/write_rockspec.lua b/src/luarocks/cmd/write_rockspec.lua index aad91910..4b16c0b7 100644 --- a/src/luarocks/cmd/write_rockspec.lua +++ b/src/luarocks/cmd/write_rockspec.lua @@ -11,36 +11,65 @@ local rockspecs = require("luarocks.rockspecs") local type_rockspec = require("luarocks.type.rockspec") local util = require("luarocks.util") -write_rockspec.help_summary = "Write a template for a rockspec file." -write_rockspec.help_arguments = "[--output= ...] [] [] [|]" -write_rockspec.help = [[ +local lua_versions = { + "5.1", + "5.2", + "5.3", + "5.4", + "5.1,5.2", + "5.2,5.3", + "5.3,5.4", + "5.1,5.2,5.3", + "5.2,5.3,5.4", + "5.1,5.2,5.3,5.4" +} + +function write_rockspec.add_to_parser(parser) + local cmd = parser:command("write_rockspec", [[ This command writes an initial version of a rockspec file, based on a name, a version, and a location (an URL or a local path). If only two arguments are given, the first one is considered the name and the second one is the location. + If only one argument is given, it must be the location. -If no arguments are given, current directory is used as location. +If no arguments are given, current directory is used as the location. LuaRocks will attempt to infer name and version if not given, using 'dev' as a fallback default version. Note that the generated file is a _starting point_ for writing a -rockspec, and is not guaranteed to be complete or correct. - ---output= Write the rockspec with the given filename. - If not given, a file is written in the current - directory with a filename based on given name and version. ---license="" A license string, such as "MIT/X11" or "GNU GPL v3". ---summary="" A short one-line description summary. ---detailed="" A longer description string. ---homepage= Project homepage. ---lua-versions= Supported Lua versions. Accepted values are: "5.1", "5.2", - "5.3", "5.4", "5.1,5.2", "5.2,5.3", "5.3,5.4", "5.1,5.2,5.3", - "5.2,5.3,5.4", or "5.1,5.2,5.3,5.4" ---rockspec-format= Rockspec format version, such as "1.0" or "1.1". ---tag= Tag to use. Will attempt to extract version number from it. ---lib=[,] A comma-separated list of libraries that C files need to - link to. -]] +rockspec, and is not guaranteed to be complete or correct. ]], util.see_also()) + :summary("Write a template for a rockspec file.") + :add_help(false) + + cmd:argument("name", "Name of the rock.") + :args("?") + cmd:argument("version", "Rock version.") + :args("?") + cmd:argument("location", "URL or path to the rock sources.") + :args("?") + + cmd:option("--output", "Write the rockspec with the given filename.\n".. + "If not given, a file is written in the current directory with a ".. + "filename based on given name and version.") + :argname("") + cmd:option("--license", 'A license string, such as "MIT/X11" or "GNU GPL v3".') + :argname("") + cmd:option("--summary", "A short one-line description summary.") + :argname("") + cmd:option("--detailed", "A longer description string.") + :argname("") + cmd:option("--homepage", "Project homepage.") + :argname("") + cmd:option("--lua-versions", 'Supported Lua versions. Accepted values are: "'.. + table.concat(lua_versions, '", "')..'".') + :argname("") + :choices(lua_versions) + cmd:option("--rockspec-format", 'Rockspec format version, such as "1.0" or "1.1".') + :argname("") + cmd:option("--tag", "Tag to use. Will attempt to extract version number from it.") + cmd:option("--lib", "A comma-separated list of libraries that C files need to link to.") + :argname("") +end local function open_file(name) return io.open(dir.path(fs.current_dir(), name), "r") @@ -229,40 +258,42 @@ local function rockspec_cleanup(rockspec) end end -function write_rockspec.command(flags, name, version, url_or_dir) +function write_rockspec.command(args) - name = util.adjust_name_and_namespace(name, flags) + local name = util.adjust_name_and_namespace(args.name, args) + local version = args.version + local location = args.location if not name then - url_or_dir = "." + location = "." elseif not version then - url_or_dir = name + location = name name = nil - elseif not url_or_dir then - url_or_dir = version + elseif not location then + location = version version = nil end - if flags["tag"] then + if args["tag"] then if not version then - version = flags["tag"]:gsub("^v", "") + version = args["tag"]:gsub("^v", "") end end - local protocol, pathname = dir.split_url(url_or_dir) + local protocol, pathname = dir.split_url(location) if protocol == "file" then if pathname == "." then name = name or dir.base_name(fs.current_dir()) end elseif dir.is_basic_protocol(protocol) then - local filename = dir.base_name(url_or_dir) + local filename = dir.base_name(location) local newname, newversion = filename:match("(.*)-([^-]+)") if newname then name = name or newname version = version or newversion:gsub("%.[a-z]+$", ""):gsub("%.tar$", "") end else - name = name or dir.base_name(url_or_dir):gsub("%.[^.]+$", "") + name = name or dir.base_name(location):gsub("%.[^.]+$", "") end if not name then @@ -270,27 +301,27 @@ function write_rockspec.command(flags, name, version, url_or_dir) end version = version or "dev" - local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") + local filename = args["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") - local url = detect_url(url_or_dir) - local homepage = detect_homepage(url, flags["homepage"]) + local url = detect_url(location) + local homepage = detect_homepage(url, args["homepage"]) local rockspec, err = rockspecs.from_persisted_table(filename, { - rockspec_format = flags["rockspec-format"], + rockspec_format = args["rockspec_format"], package = name, version = version.."-1", source = { url = url, - tag = flags["tag"], + tag = args["tag"], }, description = { - summary = flags["summary"] or "*** please specify description summary ***", - detailed = flags["detailed"] or "*** please enter a detailed description ***", + summary = args["summary"] or "*** please specify description summary ***", + detailed = args["detailed"] or "*** please enter a detailed description ***", homepage = homepage, - license = flags["license"] or "*** please specify a license ***", + license = args["license"] or "*** please specify a license ***", }, dependencies = { - lua_version_dep[flags["lua-versions"]], + lua_version_dep[args["lua_versions"]], }, build = {}, }) @@ -301,19 +332,19 @@ function write_rockspec.command(flags, name, version, url_or_dir) util.warning("Please specify supported Lua versions with --lua-versions=. "..util.see_help("write_rockspec")) end - local local_dir = url_or_dir + local local_dir = location - if url_or_dir:match("://") then - rockspec.source.file = dir.base_name(url_or_dir) + if location:match("://") then + rockspec.source.file = dir.base_name(location) if not dir.is_basic_protocol(rockspec.source.protocol) then if version ~= "dev" then - rockspec.source.tag = flags["tag"] or "v" .. version + rockspec.source.tag = args["tag"] or "v" .. version end end rockspec.source.dir = nil local ok, base_dir, temp_dir = fetch_url(rockspec) if ok then - if base_dir ~= dir.base_name(url_or_dir) then + if base_dir ~= dir.base_name(location) then rockspec.source.dir = base_dir end end @@ -329,10 +360,10 @@ function write_rockspec.command(flags, name, version, url_or_dir) end local libs = nil - if flags["lib"] then + if args["lib"] then libs = {} rockspec.external_dependencies = {} - for lib in flags["lib"]:gmatch("([^,]+)") do + for lib in args["lib"]:gmatch("([^,]+)") do table.insert(libs, lib) rockspec.external_dependencies[lib:upper()] = { library = lib @@ -343,13 +374,13 @@ function write_rockspec.command(flags, name, version, url_or_dir) local ok, err = fs.change_dir(local_dir) if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end - if not (flags["summary"] and flags["detailed"]) then + if not (args["summary"] and args["detailed"]) then local summary, detailed = detect_description() - rockspec.description.summary = flags["summary"] or summary - rockspec.description.detailed = flags["detailed"] or detailed + rockspec.description.summary = args["summary"] or summary + rockspec.description.detailed = args["detailed"] or detailed end - if not flags["license"] then + if not args["license"] then local license, fulltext = check_license() if license then rockspec.description.license = license diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index af05ed05..93148de3 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -170,12 +170,13 @@ function deps.fulfill_dependency(dep, deps_mode, name, version, rocks_provided, return nil, "Could not satisfy dependency "..tostring(dep)..": "..search_err end util.printout("Installing "..url) - local install_flags = { + local install_args = { + rock = url, deps_mode = deps_mode, namespace = dep.namespace, verify = verify, } - local ok, install_err, errcode = install.command(install_flags, url) + local ok, install_err, errcode = install.command(install_args) if not ok then return nil, "Failed installing dependency: "..url.." - "..install_err, errcode end diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index 0e71432f..bd584d1a 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua @@ -251,14 +251,14 @@ function api.new(flags) self.config = self:load_config() or {} self.config.server = flags["server"] or self.config.server or cfg.upload.server self.config.version = self.config.version or cfg.upload.version - self.config.key = flags["temp-key"] or flags["api-key"] or self.config.key + self.config.key = flags["temp_key"] or flags["api_key"] or self.config.key self.debug = flags["debug"] if not self.config.key then return nil, "You need an API key to upload rocks.\n" .. "Navigate to "..self.config.server.."/settings to get a key\n" .. "and then pass it through the --api-key= flag." end - if flags["api-key"] then + if flags["api_key"] then self:save_config() end return self -- cgit v1.2.3-55-g6feb