aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Ouellette <oue.paul18@gmail.com>2019-06-13 20:41:14 -0400
committerPaul Ouellette <oue.paul18@gmail.com>2019-08-01 23:53:03 -0400
commit0823c4dd62e15515ad1e77cd20681b720485c564 (patch)
tree7d94b92eb0d2fd9b45d8295176474c8a7cce3eba
parentd6f296e108972982cf071d42cee37ac0cb122174 (diff)
downloadluarocks-0823c4dd62e15515ad1e77cd20681b720485c564.tar.gz
luarocks-0823c4dd62e15515ad1e77cd20681b720485c564.tar.bz2
luarocks-0823c4dd62e15515ad1e77cd20681b720485c564.zip
Move remaining commands to argparse
-rwxr-xr-xsrc/bin/luarocks1
-rwxr-xr-xsrc/bin/luarocks-admin1
-rw-r--r--src/luarocks/admin/cmd/add.lua39
-rw-r--r--src/luarocks/admin/cmd/make_manifest.lua31
-rw-r--r--src/luarocks/admin/cmd/refresh_cache.lua21
-rw-r--r--src/luarocks/admin/cmd/remove.lua33
-rw-r--r--src/luarocks/cmd.lua4
-rw-r--r--src/luarocks/cmd/doc.lua51
-rw-r--r--src/luarocks/cmd/download.lua44
-rw-r--r--src/luarocks/cmd/init.lua19
-rw-r--r--src/luarocks/cmd/install.lua97
-rw-r--r--src/luarocks/cmd/list.lua39
-rw-r--r--src/luarocks/cmd/make.lua96
-rw-r--r--src/luarocks/cmd/new_version.lua55
-rw-r--r--src/luarocks/cmd/pack.lua42
-rw-r--r--src/luarocks/cmd/path.lua52
-rw-r--r--src/luarocks/cmd/purge.lua34
-rw-r--r--src/luarocks/cmd/remove.lua45
-rw-r--r--src/luarocks/cmd/search.lua50
-rw-r--r--src/luarocks/cmd/show.lua83
-rw-r--r--src/luarocks/cmd/test.lua52
-rw-r--r--src/luarocks/cmd/unpack.lua35
-rw-r--r--src/luarocks/cmd/upload.lua67
-rw-r--r--src/luarocks/cmd/which.lua31
-rw-r--r--src/luarocks/cmd/write_rockspec.lua135
-rw-r--r--src/luarocks/deps.lua5
-rw-r--r--src/luarocks/upload/api.lua4
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")
9local description = "LuaRocks main command-line interface" 9local description = "LuaRocks main command-line interface"
10 10
11local commands = { 11local commands = {
12 help = "luarocks.cmd.help",
13 init = "luarocks.cmd.init", 12 init = "luarocks.cmd.init",
14 pack = "luarocks.cmd.pack", 13 pack = "luarocks.cmd.pack",
15 unpack = "luarocks.cmd.unpack", 14 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")
9local description = "LuaRocks repository administration interface" 9local description = "LuaRocks repository administration interface"
10 10
11local commands = { 11local commands = {
12 help = "luarocks.cmd.help",
13 make_manifest = "luarocks.admin.cmd.make_manifest", 12 make_manifest = "luarocks.admin.cmd.make_manifest",
14 add = "luarocks.admin.cmd.add", 13 add = "luarocks.admin.cmd.add",
15 remove = "luarocks.admin.cmd.remove", 14 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")
11local cache = require("luarocks.admin.cache") 11local cache = require("luarocks.admin.cache")
12local index = require("luarocks.admin.index") 12local index = require("luarocks.admin.index")
13 13
14add.help_summary = "Add a rock or rockspec to a rocks server." 14function add.add_to_parser(parser)
15add.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" 15 local cmd = parser:command("add", "Add a rock or rockspec to a rocks server.",
16add.help = [[ 16 util.see_also())
17Arguments are local files, which may be rockspecs or rocks. 17 :add_help(false)
18The flag --server indicates which server to use. 18
19If not given, the default server set in the upload_server variable 19 cmd:argument("rock", "A local rockspec or rock file.")
20from the configuration file is used instead. 20 :args("+")
21 21
22--no-refresh The local cache should not be refreshed 22 cmd:option("--server", "The server to use. If not given, the default server "..
23 prior to generation of the updated manifest. 23 "set in the upload_server variable from the configuration file is used instead.")
24--index Produce an index.html file for the manifest. 24 cmd:flag("--no-refresh", "Do not refresh the local cache prior to "..
25 This flag is automatically set if an index.html 25 "generation of the updated manifest.")
26 file already exists. 26 cmd:flag("--index", "Produce an index.html file for the manifest. This "..
27]] 27 "flag is automatically set if an index.html file already exists.")
28end
28 29
29local function zip_manifests() 30local function zip_manifests()
30 for ver in util.lua_versions() do 31 for ver in util.lua_versions() do
@@ -124,14 +125,10 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server, do
124 return fs.execute(cmd) 125 return fs.execute(cmd)
125end 126end
126 127
127function add.command(flags, ...) 128function add.command(args)
128 local files = {...} 129 local server, server_table = cache.get_upload_server(args["server"])
129 if #files < 1 then
130 return nil, "Argument missing. "..util.see_help("add", "luarocks-admin")
131 end
132 local server, server_table = cache.get_upload_server(flags["server"])
133 if not server then return nil, server_table end 130 if not server then return nil, server_table end
134 return add_files_to_server(not flags["no-refresh"], files, server, server_table, flags["index"]) 131 return add_files_to_server(not args["no_refresh"], files, server, server_table, args["index"])
135end 132end
136 133
137 134
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")
11local fs = require("luarocks.fs") 11local fs = require("luarocks.fs")
12local dir = require("luarocks.dir") 12local dir = require("luarocks.dir")
13 13
14make_manifest.help_summary = "Compile a manifest file for a repository." 14function make_manifest.add_to_parser(parser)
15 local cmd = parser:command("make_manifest", "Compile a manifest file for a repository.",
16 util.see_also())
17 :add_help(false)
15 18
16make_manifest.help = [[ 19 cmd:argument("repository", "Local repository pathname.")
17<argument>, if given, is a local repository pathname. 20 :args("?")
18 21
19--local-tree If given, do not write versioned versions of the manifest file. 22 cmd:flag("--local-tree", "If given, do not write versioned versions of the manifest file.\n"..
20 Use this when rebuilding the manifest of a local rocks tree. 23 "Use this when rebuilding the manifest of a local rocks tree.")
21]] 24 cmd:option("--deps-mode"):hidden(true) -- TODO: Description?
25end
22 26
23--- Driver function for "make_manifest" command. 27--- Driver function for "make_manifest" command.
24-- @param repo string or nil: Pathname of a local repository. If not given,
25-- the default local repository configured as cfg.rocks_dir is used.
26-- @return boolean or (nil, string): True if manifest was generated, 28-- @return boolean or (nil, string): True if manifest was generated,
27-- or nil and an error message. 29-- or nil and an error message.
28function make_manifest.command(flags, repo) 30function make_manifest.command(args)
29 assert(type(repo) == "string" or not repo) 31 local repo = args.repository or cfg.rocks_dir
30 repo = repo or cfg.rocks_dir
31 32
32 util.printout("Making manifest for "..repo) 33 util.printout("Making manifest for "..repo)
33 34
34 if repo:match("/lib/luarocks") and not flags["local-tree"] then 35 if repo:match("/lib/luarocks") and not args["local_tree"] then
35 util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") 36 util.warning("This looks like a local rocks tree, but you did not pass --local-tree.")
36 end 37 end
37 38
38 local ok, err = writer.make_manifest(repo, deps.get_deps_mode(flags), not flags["local-tree"]) 39 local ok, err = writer.make_manifest(repo, deps.get_deps_mode(args), not args["local_tree"])
39 if ok and not flags["local-tree"] then 40 if ok and not args["local_tree"] then
40 util.printout("Generating index.html for "..repo) 41 util.printout("Generating index.html for "..repo)
41 index.make_index(repo) 42 index.make_index(repo)
42 end 43 end
43 if flags["local-tree"] then 44 if args["local_tree"] then
44 for luaver in util.lua_versions() do 45 for luaver in util.lua_versions() do
45 fs.delete(dir.path(repo, "manifest-"..luaver)) 46 fs.delete(dir.path(repo, "manifest-"..luaver))
46 end 47 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 @@
3local refresh_cache = {} 3local refresh_cache = {}
4 4
5local cfg = require("luarocks.core.cfg") 5local cfg = require("luarocks.core.cfg")
6local util = require("luarocks.util")
6local cache = require("luarocks.admin.cache") 7local cache = require("luarocks.admin.cache")
7 8
8refresh_cache.help_summary = "Refresh local cache of a remote rocks server." 9function refresh_cache.add_to_parser(parser)
9refresh_cache.help_arguments = "[--from=<server>]" 10 local cmd = parser:command(
10refresh_cache.help = [[ 11 "refresh_cache", "Refresh local cache of a remote rocks server.", util.see_also())
11The flag --from indicates which server to use. 12 :add_help(false)
12If not given, the default server set in the upload_server variable
13from the configuration file is used instead.
14]]
15 13
16function refresh_cache.command(flags) 14 cmd:option("--from", "The server to use. If not given, the default server "..
17 local server, upload_server = cache.get_upload_server(flags["server"]) 15 "set in the upload_server variable from the configuration file is used instead.")
16 :argname("<server>")
17end
18
19function refresh_cache.command(args)
20 local server, upload_server = cache.get_upload_server(args["server"])
18 if not server then return nil, upload_server end 21 if not server then return nil, upload_server end
19 local download_url = cache.get_server_urls(server, upload_server) 22 local download_url = cache.get_server_urls(server, upload_server)
20 23
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")
11local cache = require("luarocks.admin.cache") 11local cache = require("luarocks.admin.cache")
12local index = require("luarocks.admin.index") 12local index = require("luarocks.admin.index")
13 13
14admin_remove.help_summary = "Remove a rock or rockspec from a rocks server." 14function admin_remove.add_to_parser(parser)
15admin_remove.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" 15 local cmd = parser:command(
16admin_remove.help = [[ 16 "remove", "Remove a rock or rockspec from a rocks server.", util.see_also())
17Arguments are local files, which may be rockspecs or rocks. 17 :add_help(false)
18The flag --server indicates which server to use. 18
19If not given, the default server set in the upload_server variable 19 cmd:argument("rock", "A local rockspec or rock file.")
20from the configuration file is used instead. 20 :args("+")
21The flag --no-refresh indicates the local cache should not be refreshed 21
22prior to generation of the updated manifest. 22 cmd:option("--server", "The server to use. If not given, the default server "..
23]] 23 "set in the upload_server variable from the configuration file is used instead.")
24 cmd:flag("--no-refresh", "Do not refresh the local cache prior to "..
25 "generation of the updated manifest.")
26end
24 27
25local function remove_files_from_server(refresh, rockfiles, server, upload_server) 28local function remove_files_from_server(refresh, rockfiles, server, upload_server)
26 assert(type(refresh) == "boolean" or not refresh) 29 assert(type(refresh) == "boolean" or not refresh)
@@ -76,14 +79,10 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve
76 return true 79 return true
77end 80end
78 81
79function admin_remove.command(flags, ...) 82function admin_remove.command(args)
80 local files = {...} 83 local server, server_table = cache.get_upload_server(args["server"])
81 if #files < 1 then
82 return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin")
83 end
84 local server, server_table = cache.get_upload_server(flags["server"])
85 if not server then return nil, server_table end 84 if not server then return nil, server_table end
86 return remove_files_from_server(not flags["no-refresh"], files, server, server_table) 85 return remove_files_from_server(not args["no_refresh"], files, server, server_table)
87end 86end
88 87
89 88
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:
394 parser:option("--only-sources-from"):target("only_sources"):hidden(true) 394 parser:option("--only-sources-from"):target("only_sources"):hidden(true)
395 395
396 for _, module in util.sortedpairs(cmd_modules) do 396 for _, module in util.sortedpairs(cmd_modules) do
397 if module.add_to_parser then -- TODO: Remove this check. 397 module.add_to_parser(parser)
398 module.add_to_parser(parser)
399 end
400 end 398 end
401 399
402 return parser 400 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")
12local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
13local download = require("luarocks.download") 13local download = require("luarocks.download")
14 14
15doc.help_summary = "Show documentation for an installed rock." 15function doc.add_to_parser(parser)
16 16 local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n"..
17doc.help = [[ 17 "Without any flags, tries to load the documentation using a series of heuristics.\n"..
18<argument> is an existing package name. 18 "With flags, return only the desired information.", util.see_also([[
19Without any flags, tries to load the documentation 19 For more information about a rock, see the 'show' command.
20using a series of heuristics. 20]]))
21With these flags, return only the desired information: 21 :summary("Show documentation for an installed rock.")
22 22 :add_help(false)
23--home Open the home page of project. 23
24--list List documentation files only. 24 cmd:argument("rock", "Name of the rock.")
25 25 cmd:argument("version", "Version of the rock.")
26For more information about a rock, see the 'show' command. 26 :args("?")
27]] 27
28 cmd:flag("--home", "Open the home page of project.")
29 cmd:flag("--list", "List documentation files only.")
30 cmd:flag("--porcelain"):hidden(true) -- TODO: Description?
31end
28 32
29local function show_homepage(homepage, name, version) 33local function show_homepage(homepage, name, version)
30 if not homepage then 34 if not homepage then
@@ -54,17 +58,12 @@ local function try_to_open_homepage(name, version)
54end 58end
55 59
56--- Driver function for "doc" command. 60--- Driver function for "doc" command.
57-- @param name or nil: an existing package name.
58-- @param version string or nil: a version may also be passed.
59-- @return boolean: True if succeeded, nil on errors. 61-- @return boolean: True if succeeded, nil on errors.
60function doc.command(flags, name, version) 62function doc.command(args)
61 if not name then 63 local name = util.adjust_name_and_namespace(args.rock, args)
62 return nil, "Argument missing. "..util.see_help("doc") 64 local version = args.version
63 end
64
65 name = util.adjust_name_and_namespace(name, flags)
66 local query = queries.new(name, version) 65 local query = queries.new(name, version)
67 local iname, iversion, repo = search.pick_installed_rock(query, flags["tree"]) 66 local iname, iversion, repo = search.pick_installed_rock(query, args["tree"])
68 if not iname then 67 if not iname then
69 util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...") 68 util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...")
70 return try_to_open_homepage(name, version) 69 return try_to_open_homepage(name, version)
@@ -75,7 +74,7 @@ function doc.command(flags, name, version)
75 if not rockspec then return nil,err end 74 if not rockspec then return nil,err end
76 local descript = rockspec.description or {} 75 local descript = rockspec.description or {}
77 76
78 if flags["home"] then 77 if args["home"] then
79 return show_homepage(descript.homepage, name, version) 78 return show_homepage(descript.homepage, name, version)
80 end 79 end
81 80
@@ -91,7 +90,7 @@ function doc.command(flags, name, version)
91 end 90 end
92 end 91 end
93 if not docdir then 92 if not docdir then
94 if descript.homepage and not flags["list"] then 93 if descript.homepage and not args["list"] then
95 util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") 94 util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...")
96 fs.browser(descript.homepage) 95 fs.browser(descript.homepage)
97 return true 96 return true
@@ -105,7 +104,7 @@ function doc.command(flags, name, version)
105 local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" } 104 local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" }
106 local basenames = { "index", "readme", "manual" } 105 local basenames = { "index", "readme", "manual" }
107 106
108 local porcelain = flags["porcelain"] 107 local porcelain = args["porcelain"]
109 if #files > 0 then 108 if #files > 0 then
110 util.title("Documentation files for "..name.." "..version, porcelain) 109 util.title("Documentation files for "..name.." "..version, porcelain)
111 if porcelain then 110 if porcelain then
@@ -120,7 +119,7 @@ function doc.command(flags, name, version)
120 end 119 end
121 end 120 end
122 121
123 if flags["list"] then 122 if args["list"] then
124 return true 123 return true
125 end 124 end
126 125
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 = {}
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7local download = require("luarocks.download") 7local download = require("luarocks.download")
8 8
9cmd_download.help_summary = "Download a specific rock file from a rocks server." 9function cmd_download.add_to_parser(parser)
10cmd_download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" 10 local cmd = parser:command(
11cmd_download.help = [[ 11 "download", "Download a specific rock file from a rocks server.", util.see_also())
12--all Download all files if there are multiple matches. 12 :add_help(false)
13--source Download .src.rock if available. 13
14--rockspec Download .rockspec if available. 14 cmd:argument("name", "Name of the rock.")
15--arch=<arch> Download rock for a specific architecture. 15 :args("?")
16]] 16 cmd:argument("version", "Version of the rock.")
17 :args("?")
18
19 cmd:flag("--all", "Download all files if there are multiple matches.")
20 cmd:mutex(
21 cmd:flag("--source", "Download .src.rock if available."),
22 cmd:flag("--rockspec", "Download .rockspec if available."),
23 cmd:option("--arch", "Download rock for a specific architecture."))
24end
17 25
18--- Driver function for the "download" command. 26--- Driver function for the "download" command.
19-- @param name string: a rock name.
20-- @param version string or nil: if the name of a package is given, a
21-- version may also be passed.
22-- @return boolean or (nil, string): true if successful or nil followed 27-- @return boolean or (nil, string): true if successful or nil followed
23-- by an error message. 28-- by an error message.
24function cmd_download.command(flags, name, version) 29function cmd_download.command(args)
25 assert(type(version) == "string" or not version) 30 if not args.name and not args["all"] then
26 if type(name) ~= "string" and not flags["all"] then
27 return nil, "Argument missing. "..util.see_help("download") 31 return nil, "Argument missing. "..util.see_help("download")
28 end 32 end
29 33
30 name = util.adjust_name_and_namespace(name, flags) 34 local name = util.adjust_name_and_namespace(args.name, args)
31 35
32 if not name then name, version = "", "" end 36 if not name then name, version = "", "" end
33 37
34 local arch 38 local arch
35 39
36 if flags["source"] then 40 if args["source"] then
37 arch = "src" 41 arch = "src"
38 elseif flags["rockspec"] then 42 elseif args["rockspec"] then
39 arch = "rockspec" 43 arch = "rockspec"
40 elseif flags["arch"] then 44 elseif args["arch"] then
41 arch = flags["arch"] 45 arch = args["arch"]
42 end 46 end
43 47
44 local dl, err = download.download(arch, name:lower(), version, flags["all"]) 48 local dl, err = download.download(arch, name:lower(), version, args["all"])
45 return dl and true, err 49 return dl and true, err
46end 50end
47 51
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)
14 local cmd = parser:command("init", "Initialize a directory for a Lua project using LuaRocks.", util.see_also()) 14 local cmd = parser:command("init", "Initialize a directory for a Lua project using LuaRocks.", util.see_also())
15 :add_help(false) 15 :add_help(false)
16 16
17 cmd:argument("name", "The project name."):args("?") 17 cmd:argument("name", "The project name.")
18 cmd:argument("version", "An optional project version."):args("?") 18 :args("?")
19 cmd:argument("version", "An optional project version.")
20 :args("?")
19 cmd:flag("--reset", "Delete .luarocks/config-5.x.lua and ./lua and generate new ones.") 21 cmd:flag("--reset", "Delete .luarocks/config-5.x.lua and ./lua and generate new ones.")
20 22
21 cmd:group("Options for specifying rockspec data", 23 cmd:group("Options for specifying rockspec data",
@@ -60,15 +62,14 @@ function init.command(args)
60 62
61 local pwd = fs.current_dir() 63 local pwd = fs.current_dir()
62 64
63 local name = args.name 65 if not args.name then
64 if not name then 66 args.name = dir.base_name(pwd)
65 name = dir.base_name(pwd) 67 if args.name == "/" then
66 if name == "/" then
67 return nil, "When running from the root directory, please specify the <name> argument" 68 return nil, "When running from the root directory, please specify the <name> argument"
68 end 69 end
69 end 70 end
70 71
71 util.title("Initializing project '" .. name .. "' for Lua " .. cfg.lua_version .. " ...") 72 util.title("Initializing project '" .. args.name .. "' for Lua " .. cfg.lua_version .. " ...")
72 73
73 util.printout("Checking your Lua installation ...") 74 util.printout("Checking your Lua installation ...")
74 if not cfg.lua_found then 75 if not cfg.lua_found then
@@ -88,7 +89,9 @@ function init.command(args)
88 end 89 end
89 90
90 if not has_rockspec then 91 if not has_rockspec then
91 local ok, err = write_rockspec.command(args, name, args.version or "dev", pwd) 92 args.version = args.version or "dev"
93 args.location = pwd
94 local ok, err = write_rockspec.command(args)
92 if not ok then 95 if not ok then
93 util.printerr(err) 96 util.printerr(err)
94 end 97 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")
16local cmd = require("luarocks.cmd") 16local cmd = require("luarocks.cmd")
17local dir = require("luarocks.dir") 17local dir = require("luarocks.dir")
18 18
19install.help_summary = "Install a rock." 19function install.add_to_parser(parser)
20 20 local cmd = parser:command("install", "Install a rock.", util.see_also())
21install.help_arguments = "{<rock>|<name> [<version>]}" 21 :add_help(false)
22 22
23install.help = [[ 23 cmd:argument("rock", "The name of a rock to be fetched from a repository "..
24Argument may be the name of a rock to be fetched from a repository 24 "or a filename of a locally available rock.")
25or a filename of a locally available rock. 25 cmd:argument("version", "Version of the rock.")
26 26 :args("?")
27--keep Do not remove previously installed versions of the 27
28 rock after installing a new one. This behavior can 28 cmd:flag("--keep", "Do not remove previously installed versions of the "..
29 be made permanent by setting keep_other_versions=true 29 "rock after building a new one. This behavior can be made permanent by "..
30 in the configuration file. 30 "setting keep_other_versions=true in the configuration file.")
31 31 cmd:flag("--only-deps", "Installs only the dependencies of the rock.")
32--only-deps Installs only the dependencies of the rock. 32 cmd:flag("--no-doc", "Installs the rock without its documentation.")
33 33 cmd:flag("--verify", "Verify signature of the rockspec or src.rock being "..
34--no-doc Installs the rock without its documentation. 34 "built. If the rockspec or src.rock is being downloaded, LuaRocks will "..
35 35 "attempt to download the signature as well. Otherwise, the signature "..
36--verify Verify signature of the rock being installed. 36 "file should be already available locally in the same directory.\n"..
37 If rock is being downloaded, LuaRocks will attempt 37 "You need the signer’s public key in your local keyring for this "..
38 to download the signature as well. If the rock is 38 "option to work properly.")
39 local, the signature file should be in the same 39 util.deps_mode_option(cmd)
40 directory. 40end
41 You need the signer’s public key in your local
42 keyring for this option to work properly.
43
44]]--..util.deps_mode_help()
45 41
46install.opts = util.opts_table("install.opts", { 42install.opts = util.opts_table("install.opts", {
47 namespace = "string?", 43 namespace = "string?",
@@ -208,51 +204,46 @@ local function install_rock_file(filename, opts)
208end 204end
209 205
210--- Driver function for the "install" command. 206--- Driver function for the "install" command.
211-- @param name string: name of a binary rock. If an URL or pathname 207-- If an URL or pathname to a binary rock is given, fetches and installs it.
212-- to a binary rock is given, fetches and installs it. If a rockspec or a 208-- If a rockspec or a source rock is given, forwards the request to the "build"
213-- source rock is given, forwards the request to the "build" command. 209-- command.
214-- If a package name is given, forwards the request to "search" and, 210-- If a package name is given, forwards the request to "search" and,
215-- if returned a result, installs the matching rock. 211-- if returned a result, installs the matching rock.
216-- @param version string: When passing a package name, a version number
217-- may also be given.
218-- @return boolean or (nil, string, exitcode): True if installation was 212-- @return boolean or (nil, string, exitcode): True if installation was
219-- successful, nil and an error message otherwise. exitcode is optionally returned. 213-- successful, nil and an error message otherwise. exitcode is optionally returned.
220function install.command(flags, name, version) 214function install.command(args)
221 if type(name) ~= "string" then 215 args.rock = util.adjust_name_and_namespace(args.rock, args)
222 return nil, "Argument missing. "..util.see_help("install")
223 end
224
225 name = util.adjust_name_and_namespace(name, flags)
226 216
227 local ok, err = fs.check_command_permissions(flags) 217 local ok, err = fs.check_command_permissions(args)
228 if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end 218 if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end
229 219
230 if name:match("%.rockspec$") or name:match("%.src%.rock$") then 220 if args.rock:match("%.rockspec$") or args.rock:match("%.src%.rock$") then
231 local build = require("luarocks.cmd.build") 221 local build = require("luarocks.cmd.build")
232 return build.command(flags, name) 222 return build.command(args)
233 elseif name:match("%.rock$") then 223 elseif args.rock:match("%.rock$") then
234 local deps_mode = deps.get_deps_mode(flags) 224 local deps_mode = deps.get_deps_mode(args)
235 local opts = install.opts({ 225 local opts = install.opts({
236 namespace = flags["namespace"], 226 namespace = args["namespace"],
237 keep = not not flags["keep"], 227 keep = not not args["keep"],
238 force = not not flags["force"], 228 force = not not args["force"],
239 force_fast = not not flags["force-fast"], 229 force_fast = not not args["force_fast"],
240 no_doc = not not flags["no-doc"], 230 no_doc = not not args["no_doc"],
241 deps_mode = deps_mode, 231 deps_mode = deps_mode,
242 verify = not not flags["verify"], 232 verify = not not args["verify"],
243 }) 233 })
244 if flags["only-deps"] then 234 if args["only_deps"] then
245 return install_rock_file_deps(name, opts) 235 return install_rock_file_deps(args.rock, opts)
246 else 236 else
247 return install_rock_file(name, opts) 237 return install_rock_file(args.rock, opts)
248 end 238 end
249 else 239 else
250 local url, err = search.find_suitable_rock(queries.new(name:lower(), version), true) 240 local url, err = search.find_suitable_rock(queries.new(args.rock:lower(), args.version), true)
251 if not url then 241 if not url then
252 return nil, err 242 return nil, err
253 end 243 end
254 util.printout("Installing "..url) 244 util.printout("Installing "..url)
255 return install.command(flags, url) 245 args.rock = url
246 return install.command(args)
256 end 247 end
257end 248end
258 249
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")
10local util = require("luarocks.util") 10local util = require("luarocks.util")
11local path = require("luarocks.path") 11local path = require("luarocks.path")
12 12
13list.help_summary = "List currently installed rocks." 13function list.add_to_parser(parser)
14list.help_arguments = "[--porcelain] <filter>" 14 local cmd = parser:command("list", "List currently installed rocks.", util.see_also())
15list.help = [[ 15 :add_help(false)
16<filter> is a substring of a rock name to filter by.
17 16
18--outdated List only rocks for which there is a 17 cmd:argument("filter", "A substring of a rock name to filter by.")
19 higher version available in the rocks server. 18 :args("?")
19 cmd:argument("version", "Rock version to filter by.")
20 :args("?")
20 21
21--porcelain Produce machine-friendly output. 22 cmd:flag("--outdated", "List only rocks for which there is a higher "..
22]] 23 "version available in the rocks server.")
24 cmd:flag("--porcelain", "Produce machine-friendly output.")
25end
23 26
24local function check_outdated(trees, query) 27local function check_outdated(trees, query)
25 local results_installed = {} 28 local results_installed = {}
@@ -65,20 +68,18 @@ local function list_outdated(trees, query, porcelain)
65end 68end
66 69
67--- Driver function for "list" command. 70--- Driver function for "list" command.
68-- @param filter string or nil: A substring of a rock name to filter by.
69-- @param version string or nil: a version may also be passed.
70-- @return boolean: True if succeeded, nil on errors. 71-- @return boolean: True if succeeded, nil on errors.
71function list.command(flags, filter, version) 72function list.command(args)
72 local query = queries.new(filter and filter:lower() or "", version, true) 73 local query = queries.new(args.filter and args.filter:lower() or "", args.version, true)
73 local trees = cfg.rocks_trees 74 local trees = cfg.rocks_trees
74 local title = "Rocks installed for Lua "..cfg.lua_version 75 local title = "Rocks installed for Lua "..cfg.lua_version
75 if flags["tree"] then 76 if args["tree"] then
76 trees = { flags["tree"] } 77 trees = { args["tree"] }
77 title = title .. " in " .. flags["tree"] 78 title = title .. " in " .. args["tree"]
78 end 79 end
79 80
80 if flags["outdated"] then 81 if args["outdated"] then
81 return list_outdated(trees, query, flags["porcelain"]) 82 return list_outdated(trees, query, args["porcelain"])
82 end 83 end
83 84
84 local results = {} 85 local results = {}
@@ -88,8 +89,8 @@ function list.command(flags, filter, version)
88 util.warning(err) 89 util.warning(err)
89 end 90 end
90 end 91 end
91 util.title(title, flags["porcelain"]) 92 util.title(title, args["porcelain"])
92 search.print_result_tree(results, flags["porcelain"]) 93 search.print_result_tree(results, args["porcelain"])
93 return true 94 return true
94end 95end
95 96
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")
16local writer = require("luarocks.manif.writer") 16local writer = require("luarocks.manif.writer")
17local cmd = require("luarocks.cmd") 17local cmd = require("luarocks.cmd")
18 18
19make.help_summary = "Compile package in current directory using a rockspec." 19function make.add_to_parser(parser)
20make.help_arguments = "[--pack-binary-rock] [<rockspec>]" 20 local cmd = parser:command("make", [[
21make.help = [[
22Builds sources in the current directory, but unlike "build", 21Builds sources in the current directory, but unlike "build",
23it does not fetch sources, etc., assuming everything is 22it does not fetch sources, etc., assuming everything is
24available in the current directory. If no argument is given, 23available 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
34 33
35NB: Use `luarocks install` with the `--only-deps` flag if you want to install 34NB: Use `luarocks install` with the `--only-deps` flag if you want to install
36only dependencies of the rockspec (see `luarocks help install`). 35only dependencies of the rockspec (see `luarocks help install`).
37 36]], util.see_also())
38--pack-binary-rock Do not install rock. Instead, produce a .rock file 37 :summary("Compile package in current directory using a rockspec.")
39 with the contents of compilation in the current 38 :add_help(false)
40 directory. 39
41 40 cmd:argument("rockspec", "Rockspec for the rock to build.")
42--keep Do not remove previously installed versions of the 41 :args("?")
43 rock after installing a new one. This behavior can 42
44 be made permanent by setting keep_other_versions=true 43 cmd:flag("--pack-binary-rock", "Do not install rock. Instead, produce a "..
45 in the configuration file. 44 ".rock file with the contents of compilation in the current directory.")
46 45 cmd:flag("--keep", "Do not remove previously installed versions of the "..
47--branch=<name> Override the `source.branch` field in the loaded 46 "rock after building a new one. This behavior can be made permanent by "..
48 rockspec. Allows to specify a different branch to 47 "setting keep_other_versions=true in the configuration file.")
49 fetch. Particularly for "dev" rocks. 48 cmd:option("--branch", "Override the `source.branch` field in the loaded "..
50 49 "rockspec. Allows to specify a different branch to fetch. Particularly "..
51--verify Verify signature of the rockspec or src.rock being 50 'for "dev" rocks.')
52 built. If the rockspec or src.rock is being downloaded, 51 :argname("<name>")
53 LuaRocks will attempt to download the signature as well. 52 cmd:flag("--verify", "Verify signature of the rockspec or src.rock being "..
54 Otherwise, the signature file should be already 53 "built. If the rockspec or src.rock is being downloaded, LuaRocks will "..
55 available locally in the same directory. 54 "attempt to download the signature as well. Otherwise, the signature "..
56 You need the signer’s public key in your local 55 "file should be already available locally in the same directory.\n"..
57 keyring for this option to work properly. 56 "You need the signer’s public key in your local keyring for this "..
58 57 "option to work properly.")
59--sign To be used with --pack-binary-rock. Also produce 58 cmd:flag("--sign", "To be used with --pack-binary-rock. Also produce a "..
60 a signature file for the generated .rock file. 59 "signature file for the generated .rock file.")
61 60end
62]]
63 61
64--- Driver function for "make" command. 62--- Driver function for "make" command.
65-- @param name string: A local rockspec.
66-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an 63-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
67-- error message otherwise. exitcode is optionally returned. 64-- error message otherwise. exitcode is optionally returned.
68function make.command(flags, rockspec_filename) 65function make.command(args)
69 assert(type(rockspec_filename) == "string" or not rockspec_filename) 66 local rockspec
70 67 if not args.rockspec then
71 if not rockspec_filename then
72 local err 68 local err
73 rockspec_filename, err = util.get_default_rockspec() 69 rockspec, err = util.get_default_rockspec()
74 if not rockspec_filename then 70 if not rockspec then
75 return nil, err 71 return nil, err
76 end 72 end
77 end 73 end
78 if not rockspec_filename:match("rockspec$") then 74 if not rockspec:match("rockspec$") then
79 return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make") 75 return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make")
80 end 76 end
81 77
82 local rockspec, err, errcode = fetch.load_rockspec(rockspec_filename) 78 local rockspec, err, errcode = fetch.load_rockspec(rockspec)
83 if not rockspec then 79 if not rockspec then
84 return nil, err 80 return nil, err
85 end 81 end
86 82
87 local name = util.adjust_name_and_namespace(rockspec.name, flags) 83 local name = util.adjust_name_and_namespace(rockspec.name, args)
88 84
89 local opts = build.opts({ 85 local opts = build.opts({
90 need_to_fetch = false, 86 need_to_fetch = false,
91 minimal_mode = true, 87 minimal_mode = true,
92 deps_mode = deps.get_deps_mode(flags), 88 deps_mode = deps.get_deps_mode(args),
93 build_only_deps = false, 89 build_only_deps = false,
94 namespace = flags["namespace"], 90 namespace = args["namespace"],
95 branch = not not flags["branch"], 91 branch = not not args["branch"],
96 verify = not not flags["verify"], 92 verify = not not args["verify"],
97 }) 93 })
98 94
99 if flags["sign"] and not flags["pack-binary-rock"] then 95 if args["sign"] and not args["pack_binary_rock"] then
100 return nil, "In the make command, --sign is meant to be used only with --pack-binary-rock" 96 return nil, "In the make command, --sign is meant to be used only with --pack-binary-rock"
101 end 97 end
102 98
103 if flags["pack-binary-rock"] then 99 if args["pack_binary_rock"] then
104 return pack.pack_binary_rock(name, rockspec.version, flags["sign"], function() 100 return pack.pack_binary_rock(name, rockspec.version, args["sign"], function()
105 return build.build_rockspec(rockspec, opts) 101 return build.build_rockspec(rockspec, opts)
106 end) 102 end)
107 else 103 else
108 local ok, err = fs.check_command_permissions(flags) 104 local ok, err = fs.check_command_permissions(args)
109 if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end 105 if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end
110 ok, err = build.build_rockspec(rockspec, opts) 106 ok, err = build.build_rockspec(rockspec, opts)
111 if not ok then return nil, err end 107 if not ok then return nil, err end
112 local name, version = ok, err 108 local name, version = ok, err
113 109
114 if (not flags["keep"]) and not cfg.keep_other_versions then 110 if (not args["keep"]) and not cfg.keep_other_versions then
115 local ok, err = remove.remove_other_versions(name, version, flags["force"], flags["force-fast"]) 111 local ok, err = remove.remove_other_versions(name, version, args["force"], args["force_fast"])
116 if not ok then util.printerr(err) end 112 if not ok then util.printerr(err) end
117 end 113 end
118 114
119 writer.check_dependencies(nil, deps.get_deps_mode(flags)) 115 writer.check_dependencies(nil, deps.get_deps_mode(args))
120 return name, version 116 return name, version
121 end 117 end
122end 118end
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")
11local dir = require("luarocks.dir") 11local dir = require("luarocks.dir")
12local type_rockspec = require("luarocks.type.rockspec") 12local type_rockspec = require("luarocks.type.rockspec")
13 13
14new_version.help_summary = "Auto-write a rockspec for a new version of a rock." 14function new_version.add_to_parser(parser)
15new_version.help_arguments = "[--tag=<tag>] [--dir=<path>] [<package>|<rockspec>] [<new_version>] [<new_url>]" 15 local cmd = parser:command("new_version", [[
16new_version.help = [[
17This is a utility function that writes a new rockspec, updating data 16This is a utility function that writes a new rockspec, updating data
18from a previous one. 17from a previous one.
19 18
@@ -22,7 +21,7 @@ default server. If a rockspec is given, it uses it instead. If no argument
22is given, it looks for a rockspec same way 'luarocks make' does. 21is given, it looks for a rockspec same way 'luarocks make' does.
23 22
24If the version number is not given and tag is passed using --tag, 23If the version number is not given and tag is passed using --tag,
25it is used as the version, with 'v' removed from beginning. 24it is used as the version, with 'v' removed from beginnnumbering.
26Otherwise, it only increments the revision number of the given 25Otherwise, it only increments the revision number of the given
27(or downloaded) rockspec. 26(or downloaded) rockspec.
28 27
@@ -38,8 +37,21 @@ an old tag but no new one passed, it is guessed in the same way URL is.
38If a directory is not given, it defaults to the current directory. 37If a directory is not given, it defaults to the current directory.
39 38
40WARNING: it writes the new rockspec to the given directory, 39WARNING: it writes the new rockspec to the given directory,
41overwriting the file if it already exists. 40overwriting the file if it already exists.]], util.see_also())
42]] 41 :summary("Auto-write a rockspec for a new version of a rock.")
42 :add_help(false)
43
44 cmd:argument("rock", "Package name or rockspec.")
45 :args("?")
46 cmd:argument("new_version", "New version of the rock.")
47 :args("?")
48 cmd:argument("new_url", "New URL of the rock.")
49 :args("?")
50
51 cmd:option("--dir", "Output directory for the new rockspec.")
52 cmd:option("--tag", "New SCM tag.")
53end
54
43 55
44local function try_replace(tbl, field, old, new) 56local function try_replace(tbl, field, old, new)
45 if not tbl[field] then 57 if not tbl[field] then
@@ -126,24 +138,23 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver)
126 return true 138 return true
127end 139end
128 140
129function new_version.command(flags, input, version, url) 141function new_version.command(args)
130 if not input then 142 if not args.input then
131 local err 143 local err
132 input, err = util.get_default_rockspec() 144 args.input, err = util.get_default_rockspec()
133 if not input then 145 if not args.input then
134 return nil, err 146 return nil, err
135 end 147 end
136 end 148 end
137 assert(type(input) == "string")
138 149
139 local filename, err 150 local filename, err
140 if input:match("rockspec$") then 151 if args.input:match("rockspec$") then
141 filename, err = fetch.fetch_url(input) 152 filename, err = fetch.fetch_url(args.input)
142 if not filename then 153 if not filename then
143 return nil, err 154 return nil, err
144 end 155 end
145 else 156 else
146 filename, err = download.download("rockspec", input:lower()) 157 filename, err = download.download("rockspec", args.input:lower())
147 if not filename then 158 if not filename then
148 return nil, err 159 return nil, err
149 end 160 end
@@ -157,20 +168,20 @@ function new_version.command(flags, input, version, url)
157 local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") 168 local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$")
158 local new_ver, new_rev 169 local new_ver, new_rev
159 170
160 if flags.tag and not version then 171 if args.tag and not args.new_version then
161 version = flags.tag:gsub("^v", "") 172 args.new_version = args.tag:gsub("^v", "")
162 end 173 end
163 174
164 local out_dir 175 local out_dir
165 if flags.dir then 176 if args.dir then
166 out_dir = dir.normalize(flags.dir) 177 out_dir = dir.normalize(args.dir)
167 end 178 end
168 179
169 if version then 180 if args.new_version then
170 new_ver, new_rev = version:match("(.*)%-(%d+)$") 181 new_ver, new_rev = args.new_version:match("(.*)%-(%d+)$")
171 new_rev = tonumber(new_rev) 182 new_rev = tonumber(new_rev)
172 if not new_rev then 183 if not new_rev then
173 new_ver = version 184 new_ver = args.new_version
174 new_rev = 1 185 new_rev = 1
175 end 186 end
176 else 187 else
@@ -183,7 +194,7 @@ function new_version.command(flags, input, version, url)
183 local out_name = out_rs.package:lower() 194 local out_name = out_rs.package:lower()
184 out_rs.version = new_rockver.."-"..new_rev 195 out_rs.version = new_rockver.."-"..new_rev
185 196
186 local ok, err = update_source_section(out_rs, url, flags.tag, old_ver, new_ver) 197 local ok, err = update_source_section(out_rs, args.new_url, args.tag, old_ver, new_ver)
187 if not ok then return nil, err end 198 if not ok then return nil, err end
188 199
189 if out_rs.build and out_rs.build.type == "module" then 200 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")
8local signing = require("luarocks.signing") 8local signing = require("luarocks.signing")
9local queries = require("luarocks.queries") 9local queries = require("luarocks.queries")
10 10
11cmd_pack.help_summary = "Create a rock, packing sources or binaries." 11function cmd_pack.add_to_parser(parser)
12cmd_pack.help_arguments = "{<rockspec>|<name> [<version>]}" 12 local cmd = parser:command("pack", "Create a rock, packing sources or binaries.", util.see_also())
13cmd_pack.help = [[ 13 :add_help(false)
14--sign Produce a signature file as well.
15 14
16Argument may be a rockspec file, for creating a source rock, 15 cmd:argument("rock", "A rockspec file, for creating a source rock, or the "..
17or the name of an installed package, for creating a binary rock. 16 "name of an installed package, for creating a binary rock.")
18In the latter case, the app version may be given as a second 17 cmd:argument("version", "A version may be given if the first argument is a rock name.")
19argument. 18 :args("?")
20]] 19
20 cmd:flag("--sign", "Produce a signature file as well.")
21end
21 22
22--- Driver function for the "pack" command. 23--- Driver function for the "pack" command.
23-- @param arg string: may be a rockspec file, for creating a source rock,
24-- or the name of an installed package, for creating a binary rock.
25-- @param version string or nil: if the name of a package is given, a
26-- version may also be passed.
27-- @return boolean or (nil, string): true if successful or nil followed 24-- @return boolean or (nil, string): true if successful or nil followed
28-- by an error message. 25-- by an error message.
29function cmd_pack.command(flags, arg, version) 26function cmd_pack.command(args)
30 assert(type(version) == "string" or not version)
31 if type(arg) ~= "string" then
32 return nil, "Argument missing. "..util.see_help("pack")
33 end
34
35 local file, err 27 local file, err
36 if arg:match(".*%.rockspec") then 28 if args.rock:match(".*%.rockspec") then
37 file, err = pack.pack_source_rock(arg) 29 file, err = pack.pack_source_rock(args.rock)
38 else 30 else
39 local name = util.adjust_name_and_namespace(arg, flags) 31 local name = util.adjust_name_and_namespace(args.rock, args)
40 local query = queries.new(name, version) 32 local query = queries.new(name, args.version)
41 file, err = pack.pack_installed_rock(query, flags["tree"]) 33 file, err = pack.pack_installed_rock(query, args["tree"])
42 end 34 end
43 return pack.report_and_sign_local_file(file, err, flags["sign"]) 35 return pack.report_and_sign_local_file(file, err, args["sign"])
44end 36end
45 37
46return cmd_pack 38return 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")
7local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
8local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
9 9
10path_cmd.help_summary = "Return the currently configured package path." 10function path_cmd.add_to_parser(parser)
11path_cmd.help_arguments = "" 11 local cmd = parser:command("path", [[
12path_cmd.help = [[
13Returns the package path currently configured for this installation 12Returns the package path currently configured for this installation
14of LuaRocks, formatted as shell commands to update LUA_PATH and LUA_CPATH. 13of LuaRocks, formatted as shell commands to update LUA_PATH and LUA_CPATH.
15 14
16--no-bin Do not export the PATH variable
17
18--append Appends the paths to the existing paths. Default is to prefix
19 the LR paths to the existing paths.
20
21--lr-path Exports the Lua path (not formatted as shell command)
22
23--lr-cpath Exports the Lua cpath (not formatted as shell command)
24
25--lr-bin Exports the system path (not formatted as shell command)
26
27
28On Unix systems, you may run: 15On Unix systems, you may run:
29 eval `luarocks path` 16 eval `luarocks path`
30And on Windows: 17And on Windows:
31 luarocks path > "%temp%\_lrp.bat" && call "%temp%\_lrp.bat" && del "%temp%\_lrp.bat" 18 luarocks path > "%temp%\_lrp.bat" && call "%temp%\_lrp.bat" && del "%temp%\_lrp.bat"]],
32]] 19 util.see_also())
20 :summary("Return the currently configured package path.")
21 :add_help(false)
22
23 cmd:flag("--no-bin", "Do not export the PATH variable.")
24 cmd:flag("--append", "Appends the paths to the existing paths. Default is "..
25 "to prefix the LR paths to the existing paths.")
26 cmd:flag("--lr-path", "Exports the Lua path (not formatted as shell command).")
27 cmd:flag("--lr-cpath", "Exports the Lua cpath (not formatted as shell command).")
28 cmd:flag("--lr-bin", "Exports the system path (not formatted as shell command).")
29 cmd:flag("--bin"):hidden(true)
30end
33 31
34--- Driver function for "path" command. 32--- Driver function for "path" command.
35-- @return boolean This function always succeeds. 33-- @return boolean This function always succeeds.
36function path_cmd.command(flags) 34function path_cmd.command(args)
37 local lr_path, lr_cpath, lr_bin = cfg.package_paths(flags["tree"]) 35 local lr_path, lr_cpath, lr_bin = cfg.package_paths(args["tree"])
38 local path_sep = cfg.export_path_separator 36 local path_sep = cfg.export_path_separator
39 37
40 if flags["lr-path"] then 38 if args["lr_path"] then
41 util.printout(util.cleanup_path(lr_path, ';', cfg.lua_version)) 39 util.printout(util.cleanup_path(lr_path, ';', cfg.lua_version))
42 return true 40 return true
43 elseif flags["lr-cpath"] then 41 elseif args["lr_cpath"] then
44 util.printout(util.cleanup_path(lr_cpath, ';', cfg.lua_version)) 42 util.printout(util.cleanup_path(lr_cpath, ';', cfg.lua_version))
45 return true 43 return true
46 elseif flags["lr-bin"] then 44 elseif args["lr_bin"] then
47 util.printout(util.cleanup_path(lr_bin, path_sep)) 45 util.printout(util.cleanup_path(lr_bin, path_sep))
48 return true 46 return true
49 end 47 end
50 48
51 if flags["append"] then 49 if args["append"] then
52 lr_path = package.path .. ";" .. lr_path 50 lr_path = package.path .. ";" .. lr_path
53 lr_cpath = package.cpath .. ";" .. lr_cpath 51 lr_cpath = package.cpath .. ";" .. lr_cpath
54 lr_bin = os.getenv("PATH") .. path_sep .. lr_bin 52 lr_bin = os.getenv("PATH") .. path_sep .. lr_bin
@@ -60,10 +58,10 @@ function path_cmd.command(flags)
60 58
61 local lpath_var, lcpath_var = util.lua_path_variables() 59 local lpath_var, lcpath_var = util.lua_path_variables()
62 60
63 util.printout(fs.export_cmd(lpath_var, util.cleanup_path(lr_path, ';', cfg.lua_version, flags["append"]))) 61 util.printout(fs.export_cmd(lpath_var, util.cleanup_path(lr_path, ';', cfg.lua_version)))
64 util.printout(fs.export_cmd(lcpath_var, util.cleanup_path(lr_cpath, ';', cfg.lua_version, flags["append"]))) 62 util.printout(fs.export_cmd(lcpath_var, util.cleanup_path(lr_cpath, ';', cfg.lua_version)))
65 if not flags["no-bin"] then 63 if not args["no_bin"] then
66 util.printout(fs.export_cmd("PATH", util.cleanup_path(lr_bin, path_sep, nil, flags["append"]))) 64 util.printout(fs.export_cmd("PATH", util.cleanup_path(lr_bin, path_sep)))
67 end 65 end
68 return true 66 return true
69end 67end
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")
15local queries = require("luarocks.queries") 15local queries = require("luarocks.queries")
16local cmd = require("luarocks.cmd") 16local cmd = require("luarocks.cmd")
17 17
18purge.help_summary = "Remove all installed rocks from a tree." 18function purge.add_to_parser(parser)
19purge.help_arguments = "--tree=<tree> [--old-versions]" 19 local cmd = parser:command("purge", [[
20purge.help = [[
21This command removes rocks en masse from a given tree. 20This command removes rocks en masse from a given tree.
22By default, it removes all rocks from a tree. 21By default, it removes all rocks from a tree.
23 22
24The --tree argument is mandatory: luarocks purge does not 23The --tree option is mandatory: luarocks purge does not assume a default tree.]],
25assume a default tree. 24 util.see_also())
25 :summary("Remove all installed rocks from a tree.")
26 :add_help(false)
26 27
27--old-versions Keep the highest-numbered version of each 28 cmd:flag("--old-versions", "Keep the highest-numbered version of each "..
28 rock and remove the other ones. By default 29 "rock and remove the other ones. By default it only removes old "..
29 it only removes old versions if they are 30 "versions if they are not needed as dependencies. This can be "..
30 not needed as dependencies. This can be 31 "overridden with the flag --force.")
31 overridden with the flag --force. 32end
32]]
33 33
34function purge.command(flags) 34function purge.command(args)
35 local tree = flags["tree"] 35 local tree = args["tree"]
36 36
37 if type(tree) ~= "string" then 37 if type(tree) ~= "string" then
38 return nil, "The --tree argument is mandatory. "..util.see_help("purge") 38 return nil, "The --tree argument is mandatory. "..util.see_help("purge")
@@ -43,21 +43,21 @@ function purge.command(flags)
43 return nil, "Directory not found: "..tree 43 return nil, "Directory not found: "..tree
44 end 44 end
45 45
46 local ok, err = fs.check_command_permissions(flags) 46 local ok, err = fs.check_command_permissions(args)
47 if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end 47 if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end
48 48
49 search.local_manifest_search(results, path.rocks_dir(tree), queries.all()) 49 search.local_manifest_search(results, path.rocks_dir(tree), queries.all())
50 50
51 local sort = function(a,b) return vers.compare_versions(b,a) end 51 local sort = function(a,b) return vers.compare_versions(b,a) end
52 if flags["old-versions"] then 52 if args["old_versions"] then
53 sort = vers.compare_versions 53 sort = vers.compare_versions
54 end 54 end
55 55
56 for package, versions in util.sortedpairs(results) do 56 for package, versions in util.sortedpairs(results) do
57 for version, _ in util.sortedpairs(versions, sort) do 57 for version, _ in util.sortedpairs(versions, sort) do
58 if flags["old-versions"] then 58 if args["old_versions"] then
59 util.printout("Keeping "..package.." "..version.."...") 59 util.printout("Keeping "..package.." "..version.."...")
60 local ok, err = remove.remove_other_versions(package, version, flags["force"], flags["force-fast"]) 60 local ok, err = remove.remove_other_versions(package, version, args["force"], args["force_fast"])
61 if not ok then 61 if not ok then
62 util.printerr(err) 62 util.printerr(err)
63 end 63 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")
14local queries = require("luarocks.queries") 14local queries = require("luarocks.queries")
15local cmd = require("luarocks.cmd") 15local cmd = require("luarocks.cmd")
16 16
17cmd_remove.help_summary = "Uninstall a rock." 17function cmd_remove.add_to_parser(parser)
18cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]" 18 local cmd = parser:command("remove", [[
19cmd_remove.help = [[ 19Uninstall a rock.
20Argument is the name of a rock to be uninstalled. 20
21If a version is not given, try to remove all versions at once. 21If a version is not given, try to remove all versions at once.
22Will only perform the removal if it does not break dependencies. 22Will only perform the removal if it does not break dependencies.
23To override this check and force the removal, use --force. 23To override this check and force the removal, use --force or --force-fast.]],
24To perform a forced removal without reporting dependency issues, 24 util.see_also())
25use --force-fast. 25 :summary("Uninstall a rock.")
26 :add_help(false)
27
28 cmd:argument("rock", "Name of the rock to be uninstalled.")
29 cmd:argument("version", "Version of the rock to uninstall.")
30 :args("?")
26 31
27]]--..util.deps_mode_help() 32 cmd:flag("--force", "Force removal if it would break dependencies.")
33 cmd:flag("--force-fast", "Perform a forced removal without reporting dependency issues.")
34 util.deps_mode_option(cmd)
35end
28 36
29--- Driver function for the "remove" command. 37--- Driver function for the "remove" command.
30-- @param name string: name of a rock. If a version is given, refer to
31-- a specific version; otherwise, try to remove all versions.
32-- @param version string: When passing a package name, a version number
33-- may also be given.
34-- @return boolean or (nil, string, exitcode): True if removal was 38-- @return boolean or (nil, string, exitcode): True if removal was
35-- successful, nil and an error message otherwise. exitcode is optionally returned. 39-- successful, nil and an error message otherwise. exitcode is optionally returned.
36function cmd_remove.command(flags, name, version) 40function cmd_remove.command(args)
37 if type(name) ~= "string" then 41 local name = util.adjust_name_and_namespace(args.rock, args)
38 return nil, "Argument missing. "..util.see_help("remove")
39 end
40
41 name = util.adjust_name_and_namespace(name, flags)
42 42
43 local deps_mode = flags["deps-mode"] or cfg.deps_mode 43 local deps_mode = args["deps_mode"] or cfg.deps_mode
44 44
45 local ok, err = fs.check_command_permissions(flags) 45 local ok, err = fs.check_command_permissions(args)
46 if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end 46 if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end
47 47
48 local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") 48 local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$")
49 local version = args.version
49 local filename = name 50 local filename = name
50 if rock_type then 51 if rock_type then
51 name, version = path.parse_name(filename) 52 name, version = path.parse_name(filename)
@@ -59,12 +60,12 @@ function cmd_remove.command(flags, name, version)
59 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) 60 return nil, "Could not find rock '"..name..(version and " "..version or "").."' 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, flags["force"], flags["force-fast"]) 63 local ok, err = remove.remove_search_results(results, name, deps_mode, args["force"], args["force_fast"])
63 if not ok then 64 if not ok then
64 return nil, err 65 return nil, err
65 end 66 end
66 67
67 writer.check_dependencies(nil, deps.get_deps_mode(flags)) 68 writer.check_dependencies(nil, deps.get_deps_mode(args))
68 return true 69 return true
69end 70end
70 71
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")
9local queries = require("luarocks.queries") 9local queries = require("luarocks.queries")
10local results = require("luarocks.results") 10local results = require("luarocks.results")
11 11
12cmd_search.help_summary = "Query the LuaRocks servers." 12function cmd_search.add_to_parser(parser)
13cmd_search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" 13 local cmd = parser:command("search", "Query the LuaRocks servers.", util.see_also())
14cmd_search.help = [[ 14 :add_help(false)
15--source Return only rockspecs and source rocks, 15
16 to be used with the "build" command. 16 cmd:argument("name", "Name of the rock to search for.")
17--binary Return only pure Lua and binary rocks (rocks that can be used 17 :args("?")
18 with the "install" command without requiring a C toolchain). 18 cmd:argument("version", "Rock version to search for.")
19--all List all contents of the server that are suitable to 19 :args("?")
20 this platform, do not filter by name. 20
21--porcelain Return a machine readable format. 21 cmd:flag("--source", "Return only rockspecs and source rocks, to be used "..
22]] 22 'with the "build" command.')
23 cmd:flag("--binary", "Return only pure Lua and binary rocks (rocks that "..
24 'can be used with the "install" command without requiring a C toolchain).')
25 cmd:flag("--all", "List all contents of the server that are suitable to "..
26 "this platform, do not filter by name.")
27 cmd:flag("--porcelain", "Return a machine readable format.")
28end
23 29
24--- Splits a list of search results into two lists, one for "source" results 30--- Splits a list of search results into two lists, one for "source" results
25-- to be used with the "build" command, and one for "binary" results to be 31-- 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)
45end 51end
46 52
47--- Driver function for "search" command. 53--- Driver function for "search" command.
48-- @param name string: A substring of a rock name to search.
49-- @param version string or nil: a version may also be passed.
50-- @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
51-- error message otherwise. 55-- error message otherwise.
52function cmd_search.command(flags, name, version) 56function cmd_search.command(args)
53 57
54 name = util.adjust_name_and_namespace(name, flags) 58 local name = util.adjust_name_and_namespace(args.name, args)
55 59
56 if flags["all"] then 60 if args["all"] then
57 name, version = "", nil 61 name, args.version = "", nil
58 end 62 end
59 63
60 if type(name) ~= "string" and not flags["all"] then 64 if not args.name and not args["all"] then
61 return nil, "Enter name and version or use --all. "..util.see_help("search") 65 return nil, "Enter name and version or use --all. "..util.see_help("search")
62 end 66 end
63 67
64 local query = queries.new(name:lower(), version, true) 68 local query = queries.new(name:lower(), args.version, true)
65 local result_tree, err = search.search_repos(query) 69 local result_tree, err = search.search_repos(query)
66 local porcelain = flags["porcelain"] 70 local porcelain = args["porcelain"]
67 local full_name = name .. (version and " " .. version or "") 71 local full_name = name .. (args.version and " " .. args.version or "")
68 util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=") 72 util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=")
69 local sources, binaries = split_source_and_binary_results(result_tree) 73 local sources, binaries = split_source_and_binary_results(result_tree)
70 if next(sources) and not flags["binary"] then 74 if next(sources) and not args["binary"] then
71 util.title("Rockspecs and source rocks:", porcelain) 75 util.title("Rockspecs and source rocks:", porcelain)
72 search.print_result_tree(sources, porcelain) 76 search.print_result_tree(sources, porcelain)
73 end 77 end
74 if next(binaries) and not flags["source"] then 78 if next(binaries) and not args["source"] then
75 util.title("Binary and pure-Lua rocks:", porcelain) 79 util.title("Binary and pure-Lua rocks:", porcelain)
76 search.print_result_tree(binaries, porcelain) 80 search.print_result_tree(binaries, porcelain)
77 end 81 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")
13local manif = require("luarocks.manif") 13local manif = require("luarocks.manif")
14local repos = require("luarocks.repos") 14local repos = require("luarocks.repos")
15 15
16show.help_summary = "Show information about an installed rock." 16function show.add_to_parser(parser)
17 local cmd = parser:command("show", [[
18Show information about an installed rock.
17 19
18show.help = [[
19<argument> is an existing package name.
20Without any flags, show all module information. 20Without any flags, show all module information.
21With these flags, return only the desired information: 21With flags, return only the desired information.]], util.see_also())
22 :summary("Show information about an installed rock.")
23 :add_help(false)
22 24
23--home home page of project 25 cmd:argument("rock", "Name of an installed rock.")
24--modules all modules provided by this package as used by require() 26 cmd:argument("version", "Rock version.")
25--deps packages this package depends on 27 :args("?")
26--build-deps build-only dependencies for this package
27--test-deps dependencies for testing this package
28--rockspec the full path of the rockspec file
29--mversion the package version
30--rock-tree local tree where rock is installed
31--rock-dir data directory of the installed rock
32]]
33 28
29 cmd:flag("--home", "Show home page of project.")
30 cmd:flag("--modules", "Show all modules provided by the package as used by require().")
31 cmd:flag("--deps", "Show packages the package depends on.")
32 cmd:flag("--build-deps", "Show build-only dependencies for the package.")
33 cmd:flag("--test-deps", "Show dependencies for testing the package.")
34 cmd:flag("--rockspec", "Show the full path of the rockspec file.")
35 cmd:flag("--mversion", "Show the package version.")
36 cmd:flag("--rock-tree", "Show local tree where rock is installed.")
37 cmd:flag("--rock-namespace", "Show rock namespace.")
38 cmd:flag("--rock-dir", "Show data directory of the installed rock.")
39 cmd:flag("--rock-license", "Show rock license.")
40 cmd:flag("--issues", "Show URL for project's issue tracker.")
41 cmd:flag("--labels", "List the labels of the rock.")
42 cmd:flag("--porcelain", "Produce machine-friendly output.")
43end
34 44
35local friendly_template = [[ 45local friendly_template = [[
36 : 46 :
@@ -249,19 +259,14 @@ local function show_rock(template, namespace, name, version, rockspec, repo, min
249end 259end
250 260
251--- Driver function for "show" command. 261--- Driver function for "show" command.
252-- @param name or nil: an existing package name.
253-- @param version string or nil: a version may also be passed.
254-- @return boolean: True if succeeded, nil on errors. 262-- @return boolean: True if succeeded, nil on errors.
255function show.command(flags, name, version) 263function show.command(args)
256 if not name then 264 local name = util.adjust_name_and_namespace(args.rock, args)
257 return nil, "Argument missing. "..util.see_help("show") 265 local version = args.verson
258 end
259
260 name = util.adjust_name_and_namespace(name, flags)
261 local query = queries.new(name, version) 266 local query = queries.new(name, version)
262 267
263 local repo, repo_url 268 local repo, repo_url
264 name, version, repo, repo_url = search.pick_installed_rock(query, flags["tree"]) 269 name, version, repo, repo_url = search.pick_installed_rock(query, args["tree"])
265 if not name then 270 if not name then
266 return nil, version 271 return nil, version
267 end 272 end
@@ -277,32 +282,32 @@ function show.command(flags, name, version)
277 if not manifest then return nil,err end 282 if not manifest then return nil,err end
278 local minfo = manifest.repository[name][version][1] 283 local minfo = manifest.repository[name][version][1]
279 284
280 if flags["rock-tree"] then util.printout(tree) 285 if args["rock_tree"] then util.printout(tree)
281 elseif flags["rock-namespace"] then util.printout(namespace) 286 elseif args["rock_namespace"] then util.printout(namespace)
282 elseif flags["rock-dir"] then util.printout(directory) 287 elseif args["rock_dir"] then util.printout(directory)
283 elseif flags["home"] then util.printout(descript.homepage) 288 elseif args["home"] then util.printout(descript.homepage)
284 elseif flags["rock-license"] then util.printout(descript.license) 289 elseif args["rock_license"] then util.printout(descript.license)
285 elseif flags["issues"] then util.printout(descript.issues_url) 290 elseif args["issues"] then util.printout(descript.issues_url)
286 elseif flags["labels"] then util.printout(descript.labels and table.concat(descript.labels, "\n")) 291 elseif args["labels"] then util.printout(descript.labels and table.concat(descript.labels, "\n"))
287 elseif flags["modules"] then util.printout(keys_as_string(minfo.modules, "\n")) 292 elseif args["modules"] then util.printout(keys_as_string(minfo.modules, "\n"))
288 elseif flags["deps"] then 293 elseif args["deps"] then
289 for _, dep in ipairs(rockspec.dependencies) do 294 for _, dep in ipairs(rockspec.dependencies) do
290 util.printout(tostring(dep)) 295 util.printout(tostring(dep))
291 end 296 end
292 elseif flags["build-deps"] then 297 elseif args["build_deps"] then
293 for _, dep in ipairs(rockspec.build_dependencies) do 298 for _, dep in ipairs(rockspec.build_dependencies) do
294 util.printout(tostring(dep)) 299 util.printout(tostring(dep))
295 end 300 end
296 elseif flags["test-deps"] then 301 elseif args["test_deps"] then
297 for _, dep in ipairs(rockspec.test_dependencies) do 302 for _, dep in ipairs(rockspec.test_dependencies) do
298 util.printout(tostring(dep)) 303 util.printout(tostring(dep))
299 end 304 end
300 elseif flags["rockspec"] then util.printout(rockspec_file) 305 elseif args["rockspec"] then util.printout(rockspec_file)
301 elseif flags["mversion"] then util.printout(version) 306 elseif args["mversion"] then util.printout(version)
302 elseif flags["porcelain"] then 307 elseif args["porcelain"] then
303 show_rock(porcelain_template, namespace, name, version, rockspec, repo, minfo, flags["tree"]) 308 show_rock(porcelain_template, namespace, name, version, rockspec, repo, minfo, args["tree"])
304 else 309 else
305 show_rock(friendly_template, namespace, name, version, rockspec, repo, minfo, flags["tree"]) 310 show_rock(friendly_template, namespace, name, version, rockspec, repo, minfo, args["tree"])
306 end 311 end
307 return true 312 return true
308end 313end
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 = {}
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7local test = require("luarocks.test") 7local test = require("luarocks.test")
8 8
9cmd_test.help_summary = "Run the test suite in the current directory." 9function cmd_test.add_to_parser(parser)
10cmd_test.help_arguments = "[--test-type=<type>] [<rockspec>] [-- <args>]" 10 local cmd = parser:command("test", [[
11cmd_test.help = [[
12Run the test suite for the Lua project in the current directory. 11Run the test suite for the Lua project in the current directory.
13If the first argument is a rockspec, it will use it to determine
14the parameters for running tests; otherwise, it will attempt to
15detect the rockspec.
16 12
17Any additional arguments are forwarded to the test suite. 13If the first argument is a rockspec, it will use it to determine the parameters
18To make sure that any flags passed in <args> are not interpreted 14for running tests; otherwise, it will attempt to detect the rockspec.
19as LuaRocks flags, use -- to separate LuaRocks arguments from 15
20test suite arguments. 16Any additional arguments are forwarded to the test suite.
21 17To make sure that test suite flags are not interpreted as LuaRocks flags, use --
22--test-type=<type> Specify the test suite type manually if it was not 18to separate LuaRocks arguments from test suite arguments.]],
23 specified in the rockspec and it could not be 19 util.see_also())
24 auto-detected. 20 :summary("Run the test suite in the current directory.")
25 21 :add_help(false)
26]]--..util.deps_mode_help() 22
27 23 cmd:argument("rockspec", "Project rockspec.")
28function cmd_test.command(flags, argument, ...) 24 :args("?")
29 assert(type(argument) == "string" or not argument) 25 cmd:argument("args", "Test suite arguments.")
30 26 :args("*")
31 local arguments = { ... } 27
28 cmd:option("--test-type", "Specify the test suite type manually if it was "..
29 "not specified in the rockspec and it could not be auto-detected.")
30 :argname("<type>")
31 util.deps_mode_option(cmd)
32end
32 33
33 if argument and argument:match("rockspec$") then 34function cmd_test.command(args)
34 return test.run_test_suite(argument, flags["test-type"], arguments) 35 if args.rockspec and args.rockspec:match("rockspec$") then
36 return test.run_test_suite(args.rockspec, args["test_type"], args.args)
35 end 37 end
36 38
37 table.insert(arguments, 1, argument) 39 table.insert(args.args, 1, args.rockspec)
38 40
39 local rockspec, err = util.get_default_rockspec() 41 local rockspec, err = util.get_default_rockspec()
40 if not rockspec then 42 if not rockspec then
41 return nil, err 43 return nil, err
42 end 44 end
43 45
44 return test.run_test_suite(rockspec, flags["test-type"], arguments) 46 return test.run_test_suite(rockspec, args["test_type"], args.args)
45end 47end
46 48
47return cmd_test 49return 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")
10local dir = require("luarocks.dir") 10local dir = require("luarocks.dir")
11local search = require("luarocks.search") 11local search = require("luarocks.search")
12 12
13unpack.help_summary = "Unpack the contents of a rock." 13function unpack.add_to_parser(parser)
14unpack.help_arguments = "[--force] {<rock>|<name> [<version>]}" 14 local cmd = parser:command("unpack", [[
15unpack.help = [[
16Unpacks the contents of a rock in a newly created directory. 15Unpacks the contents of a rock in a newly created directory.
17Argument may be a rock file, or the name of a rock in a rocks server. 16Argument may be a rock file, or the name of a rock in a rocks server.
18In the latter case, the app version may be given as a second argument. 17In the latter case, the rock version may be given as a second argument.]],
18 util.see_also())
19 :summary("Unpack the contents of a rock.")
20 :add_help(false)
19 21
20--force Unpack files even if the output directory already exists. 22 cmd:argument("rock", "A rock file or the name of a rock.")
21]] 23 cmd:argument("version", "Rock version.")
24 :args("?")
25
26 cmd:flag("--force", "Unpack files even if the output directory already exists.")
27end
22 28
23--- Load a rockspec file to the given directory, fetches the source 29--- Load a rockspec file to the given directory, fetches the source
24-- files specified in the rockspec, and unpack them inside the directory. 30-- files specified in the rockspec, and unpack them inside the directory.
@@ -141,31 +147,22 @@ local function run_unpacker(file, force)
141end 147end
142 148
143--- Driver function for the "unpack" command. 149--- Driver function for the "unpack" command.
144-- @param ns_name string: may be a rock filename, for unpacking a
145-- rock file or the name of a rock to be fetched and unpacked.
146-- @param version string or nil: if the name of a package is given, a
147-- version may also be passed.
148-- @return boolean or (nil, string): true if successful or nil followed 150-- @return boolean or (nil, string): true if successful or nil followed
149-- by an error message. 151-- by an error message.
150function unpack.command(flags, ns_name, version) 152function unpack.command(args)
151 assert(type(version) == "string" or not version) 153 local ns_name = util.adjust_name_and_namespace(args.rock, args)
152 if type(ns_name) ~= "string" then
153 return nil, "Argument missing. "..util.see_help("unpack")
154 end
155
156 ns_name = util.adjust_name_and_namespace(ns_name, flags)
157 154
158 local url, err 155 local url, err
159 if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then 156 if ns_name:match(".*%.rock") or ns_name:match(".*%.rockspec") then
160 url = ns_name 157 url = ns_name
161 else 158 else
162 url, err = search.find_src_or_rockspec(ns_name, version, true) 159 url, err = search.find_src_or_rockspec(ns_name, args.version, true)
163 if not url then 160 if not url then
164 return nil, err 161 return nil, err
165 end 162 end
166 end 163 end
167 164
168 return run_unpacker(url, flags["force"]) 165 return run_unpacker(url, args["force"])
169end 166end
170 167
171return unpack 168return 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")
8local cfg = require("luarocks.core.cfg") 8local cfg = require("luarocks.core.cfg")
9local Api = require("luarocks.upload.api") 9local Api = require("luarocks.upload.api")
10 10
11upload.help_summary = "Upload a rockspec to the public rocks repository." 11function upload.add_to_parser(parser)
12upload.help_arguments = "[--skip-pack] [--api-key=<key>] [--force] <rockspec>" 12 local cmd = parser:command("upload", "Pack a source rock file (.src.rock extension) "..
13upload.help = [[ 13 "and upload it and the rockspec to the public rocks repository.", util.see_also())
14<rockspec> Pack a source rock file (.src.rock extension), 14 :summary("Upload a rockspec to the public rocks repository.")
15 upload rockspec and source rock to server. 15 :add_help(false)
16 16
17--skip-pack Do not pack and send source rock. 17 cmd:argument("rockspec", "Rockspec for the rock to upload.")
18 18
19--api-key=<key> Give it an API key. It will be stored for subsequent uses. 19 cmd:flag("--skip-pack", "Do not pack and send source rock.")
20 20 cmd:option("--api-key", "Pass an API key. It will be stored for subsequent uses.")
21--temp-key=<key> Use the given a temporary API key in this invocation only. 21 :argname("<key>")
22 It will not be stored. 22 cmd:option("--temp-key", "Use the given a temporary API key in this "..
23 23 "invocation only. It will not be stored.")
24--force Replace existing rockspec if the same revision of 24 :argname("<key>")
25 a module already exists. This should be used only 25 cmd:flag("--force", "Replace existing rockspec if the same revision of a "..
26 in case of upload mistakes: when updating a rockspec, 26 "module already exists. This should be used only in case of upload "..
27 increment the revision number instead. 27 "mistakes: when updating a rockspec, increment the revision number "..
28 28 "instead.")
29--sign Upload a signature file alongside each file as well. 29 cmd:flag("--sign", "Upload a signature file alongside each file as well.")
30]] 30 cmd:flag("--debug"):hidden(true)
31end
31 32
32local function is_dev_version(version) 33local function is_dev_version(version)
33 return version:match("^dev") or version:match("^scm") 34 return version:match("^dev") or version:match("^scm")
34end 35end
35 36
36function upload.command(flags, fname) 37function upload.command(args)
37 if not fname then 38 local api, err = Api.new(args)
38 return nil, "Missing rockspec. "..util.see_help("upload")
39 end
40
41 local api, err = Api.new(flags)
42 if not api then 39 if not api then
43 return nil, err 40 return nil, err
44 end 41 end
@@ -46,12 +43,12 @@ function upload.command(flags, fname)
46 api.debug = true 43 api.debug = true
47 end 44 end
48 45
49 local rockspec, err, errcode = fetch.load_rockspec(fname) 46 local rockspec, err, errcode = fetch.load_rockspec(args.rockspec)
50 if err then 47 if err then
51 return nil, err, errcode 48 return nil, err, errcode
52 end 49 end
53 50
54 util.printout("Sending " .. tostring(fname) .. " ...") 51 util.printout("Sending " .. tostring(args.rockspec) .. " ...")
55 local res, err = api:method("check_rockspec", { 52 local res, err = api:method("check_rockspec", {
56 package = rockspec.package, 53 package = rockspec.package,
57 version = rockspec.version 54 version = rockspec.version
@@ -61,15 +58,15 @@ function upload.command(flags, fname)
61 if not res.module then 58 if not res.module then
62 util.printout("Will create new module (" .. tostring(rockspec.package) .. ")") 59 util.printout("Will create new module (" .. tostring(rockspec.package) .. ")")
63 end 60 end
64 if res.version and not flags["force"] then 61 if res.version and not args["force"] then
65 return nil, "Revision "..rockspec.version.." already exists on the server. "..util.see_help("upload") 62 return nil, "Revision "..rockspec.version.." already exists on the server. "..util.see_help("upload")
66 end 63 end
67 64
68 local sigfname 65 local sigfname
69 local rock_sigfname 66 local rock_sigfname
70 67
71 if flags["sign"] then 68 if args["sign"] then
72 sigfname, err = signing.sign_file(fname) 69 sigfname, err = signing.sign_file(args.rockspec)
73 if err then 70 if err then
74 return nil, "Failed signing rockspec: " .. err 71 return nil, "Failed signing rockspec: " .. err
75 end 72 end
@@ -77,13 +74,13 @@ function upload.command(flags, fname)
77 end 74 end
78 75
79 local rock_fname 76 local rock_fname
80 if not flags["skip-pack"] and not is_dev_version(rockspec.version) then 77 if not args["skip_pack"] and not is_dev_version(rockspec.version) then
81 util.printout("Packing " .. tostring(rockspec.package)) 78 util.printout("Packing " .. tostring(rockspec.package))
82 rock_fname, err = pack.pack_source_rock(fname) 79 rock_fname, err = pack.pack_source_rock(args.rockspec)
83 if not rock_fname then 80 if not rock_fname then
84 return nil, err 81 return nil, err
85 end 82 end
86 if flags["sign"] then 83 if args["sign"] then
87 rock_sigfname, err = signing.sign_file(rock_fname) 84 rock_sigfname, err = signing.sign_file(rock_fname)
88 if err then 85 if err then
89 return nil, "Failed signing rock: " .. err 86 return nil, "Failed signing rock: " .. err
@@ -95,7 +92,7 @@ function upload.command(flags, fname)
95 local multipart = require("luarocks.upload.multipart") 92 local multipart = require("luarocks.upload.multipart")
96 93
97 res, err = api:method("upload", nil, { 94 res, err = api:method("upload", nil, {
98 rockspec_file = multipart.new_file(fname), 95 rockspec_file = multipart.new_file(args.rockspec),
99 rockspec_sig = sigfname and multipart.new_file(sigfname), 96 rockspec_sig = sigfname and multipart.new_file(sigfname),
100 }) 97 })
101 if not res then return nil, err end 98 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")
8local util = require("luarocks.util") 8local util = require("luarocks.util")
9local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
10 10
11which_cmd.help_summary = "Tell which file corresponds to a given module name." 11function which_cmd.add_to_parser(parser)
12which_cmd.help_arguments = "<modname>" 12 local cmd = parser:command("which", 'Given a module name like "foo.bar", '..
13which_cmd.help = [[ 13 "output which file would be loaded to resolve that module by "..
14Given a module name like "foo.bar", output which file would be loaded to resolve 14 'luarocks.loader, like "/usr/local/lua/'..cfg.lua_version..'/foo/bar.lua".',
15that module by luarocks.loader, like "/usr/local/lua/]]..cfg.lua_version..[[/foo/bar.lua". 15 util.see_also())
16]] 16 :summary("Tell which file corresponds to a given module name.")
17 17 :add_help(false)
18--- Driver function for "lua" command. 18
19 cmd:argument("modname", "Module name.")
20end
21
22--- Driver function for "which" command.
19-- @return boolean This function terminates the interpreter. 23-- @return boolean This function terminates the interpreter.
20function which_cmd.command(_, modname) 24function which_cmd.command(args)
21 if modname == nil then 25 local pathname, rock_name, rock_version = loader.which(args.modname)
22 return nil, "Missing module name. " .. util.see_help("which")
23 end
24 local pathname, rock_name, rock_version = loader.which(modname)
25 26
26 if pathname then 27 if pathname then
27 util.printout(pathname) 28 util.printout(pathname)
@@ -29,7 +30,7 @@ function which_cmd.command(_, modname)
29 return true 30 return true
30 end 31 end
31 32
32 local modpath = modname:gsub("%.", "/") 33 local modpath = args.modname:gsub("%.", "/")
33 for _, v in ipairs({"path", "cpath"}) do 34 for _, v in ipairs({"path", "cpath"}) do
34 for p in package[v]:gmatch("([^;]+)") do 35 for p in package[v]:gmatch("([^;]+)") do
35 local pathname = p:gsub("%?", modpath) 36 local pathname = p:gsub("%?", modpath)
@@ -41,7 +42,7 @@ function which_cmd.command(_, modname)
41 end 42 end
42 end 43 end
43 44
44 return nil, "Module '" .. modname .. "' not found." 45 return nil, "Module '" .. args.modname .. "' not found."
45end 46end
46 47
47return which_cmd 48return 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")
11local type_rockspec = require("luarocks.type.rockspec") 11local type_rockspec = require("luarocks.type.rockspec")
12local util = require("luarocks.util") 12local util = require("luarocks.util")
13 13
14write_rockspec.help_summary = "Write a template for a rockspec file." 14local lua_versions = {
15write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] [<url>|<path>]" 15 "5.1",
16write_rockspec.help = [[ 16 "5.2",
17 "5.3",
18 "5.4",
19 "5.1,5.2",
20 "5.2,5.3",
21 "5.3,5.4",
22 "5.1,5.2,5.3",
23 "5.2,5.3,5.4",
24 "5.1,5.2,5.3,5.4"
25}
26
27function write_rockspec.add_to_parser(parser)
28 local cmd = parser:command("write_rockspec", [[
17This command writes an initial version of a rockspec file, 29This command writes an initial version of a rockspec file,
18based on a name, a version, and a location (an URL or a local path). 30based on a name, a version, and a location (an URL or a local path).
19If only two arguments are given, the first one is considered the name and the 31If only two arguments are given, the first one is considered the name and the
20second one is the location. 32second one is the location.
33
21If only one argument is given, it must be the location. 34If only one argument is given, it must be the location.
22If no arguments are given, current directory is used as location. 35If no arguments are given, current directory is used as the location.
23LuaRocks will attempt to infer name and version if not given, 36LuaRocks will attempt to infer name and version if not given,
24using 'dev' as a fallback default version. 37using 'dev' as a fallback default version.
25 38
26Note that the generated file is a _starting point_ for writing a 39Note that the generated file is a _starting point_ for writing a
27rockspec, and is not guaranteed to be complete or correct. 40rockspec, and is not guaranteed to be complete or correct. ]], util.see_also())
28 41 :summary("Write a template for a rockspec file.")
29--output=<file> Write the rockspec with the given filename. 42 :add_help(false)
30 If not given, a file is written in the current 43
31 directory with a filename based on given name and version. 44 cmd:argument("name", "Name of the rock.")
32--license="<string>" A license string, such as "MIT/X11" or "GNU GPL v3". 45 :args("?")
33--summary="<txt>" A short one-line description summary. 46 cmd:argument("version", "Rock version.")
34--detailed="<txt>" A longer description string. 47 :args("?")
35--homepage=<url> Project homepage. 48 cmd:argument("location", "URL or path to the rock sources.")
36--lua-versions=<ver> Supported Lua versions. Accepted values are: "5.1", "5.2", 49 :args("?")
37 "5.3", "5.4", "5.1,5.2", "5.2,5.3", "5.3,5.4", "5.1,5.2,5.3", 50
38 "5.2,5.3,5.4", or "5.1,5.2,5.3,5.4" 51 cmd:option("--output", "Write the rockspec with the given filename.\n"..
39--rockspec-format=<ver> Rockspec format version, such as "1.0" or "1.1". 52 "If not given, a file is written in the current directory with a "..
40--tag=<tag> Tag to use. Will attempt to extract version number from it. 53 "filename based on given name and version.")
41--lib=<lib>[,<lib>] A comma-separated list of libraries that C files need to 54 :argname("<file>")
42 link to. 55 cmd:option("--license", 'A license string, such as "MIT/X11" or "GNU GPL v3".')
43]] 56 :argname("<string>")
57 cmd:option("--summary", "A short one-line description summary.")
58 :argname("<txt>")
59 cmd:option("--detailed", "A longer description string.")
60 :argname("<txt>")
61 cmd:option("--homepage", "Project homepage.")
62 :argname("<txt>")
63 cmd:option("--lua-versions", 'Supported Lua versions. Accepted values are: "'..
64 table.concat(lua_versions, '", "')..'".')
65 :argname("<ver>")
66 :choices(lua_versions)
67 cmd:option("--rockspec-format", 'Rockspec format version, such as "1.0" or "1.1".')
68 :argname("<ver>")
69 cmd:option("--tag", "Tag to use. Will attempt to extract version number from it.")
70 cmd:option("--lib", "A comma-separated list of libraries that C files need to link to.")
71 :argname("<libs>")
72end
44 73
45local function open_file(name) 74local function open_file(name)
46 return io.open(dir.path(fs.current_dir(), name), "r") 75 return io.open(dir.path(fs.current_dir(), name), "r")
@@ -229,40 +258,42 @@ local function rockspec_cleanup(rockspec)
229 end 258 end
230end 259end
231 260
232function write_rockspec.command(flags, name, version, url_or_dir) 261function write_rockspec.command(args)
233 262
234 name = util.adjust_name_and_namespace(name, flags) 263 local name = util.adjust_name_and_namespace(args.name, args)
264 local version = args.version
265 local location = args.location
235 266
236 if not name then 267 if not name then
237 url_or_dir = "." 268 location = "."
238 elseif not version then 269 elseif not version then
239 url_or_dir = name 270 location = name
240 name = nil 271 name = nil
241 elseif not url_or_dir then 272 elseif not location then
242 url_or_dir = version 273 location = version
243 version = nil 274 version = nil
244 end 275 end
245 276
246 if flags["tag"] then 277 if args["tag"] then
247 if not version then 278 if not version then
248 version = flags["tag"]:gsub("^v", "") 279 version = args["tag"]:gsub("^v", "")
249 end 280 end
250 end 281 end
251 282
252 local protocol, pathname = dir.split_url(url_or_dir) 283 local protocol, pathname = dir.split_url(location)
253 if protocol == "file" then 284 if protocol == "file" then
254 if pathname == "." then 285 if pathname == "." then
255 name = name or dir.base_name(fs.current_dir()) 286 name = name or dir.base_name(fs.current_dir())
256 end 287 end
257 elseif dir.is_basic_protocol(protocol) then 288 elseif dir.is_basic_protocol(protocol) then
258 local filename = dir.base_name(url_or_dir) 289 local filename = dir.base_name(location)
259 local newname, newversion = filename:match("(.*)-([^-]+)") 290 local newname, newversion = filename:match("(.*)-([^-]+)")
260 if newname then 291 if newname then
261 name = name or newname 292 name = name or newname
262 version = version or newversion:gsub("%.[a-z]+$", ""):gsub("%.tar$", "") 293 version = version or newversion:gsub("%.[a-z]+$", ""):gsub("%.tar$", "")
263 end 294 end
264 else 295 else
265 name = name or dir.base_name(url_or_dir):gsub("%.[^.]+$", "") 296 name = name or dir.base_name(location):gsub("%.[^.]+$", "")
266 end 297 end
267 298
268 if not name then 299 if not name then
@@ -270,27 +301,27 @@ function write_rockspec.command(flags, name, version, url_or_dir)
270 end 301 end
271 version = version or "dev" 302 version = version or "dev"
272 303
273 local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") 304 local filename = args["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec")
274 305
275 local url = detect_url(url_or_dir) 306 local url = detect_url(location)
276 local homepage = detect_homepage(url, flags["homepage"]) 307 local homepage = detect_homepage(url, args["homepage"])
277 308
278 local rockspec, err = rockspecs.from_persisted_table(filename, { 309 local rockspec, err = rockspecs.from_persisted_table(filename, {
279 rockspec_format = flags["rockspec-format"], 310 rockspec_format = args["rockspec_format"],
280 package = name, 311 package = name,
281 version = version.."-1", 312 version = version.."-1",
282 source = { 313 source = {
283 url = url, 314 url = url,
284 tag = flags["tag"], 315 tag = args["tag"],
285 }, 316 },
286 description = { 317 description = {
287 summary = flags["summary"] or "*** please specify description summary ***", 318 summary = args["summary"] or "*** please specify description summary ***",
288 detailed = flags["detailed"] or "*** please enter a detailed description ***", 319 detailed = args["detailed"] or "*** please enter a detailed description ***",
289 homepage = homepage, 320 homepage = homepage,
290 license = flags["license"] or "*** please specify a license ***", 321 license = args["license"] or "*** please specify a license ***",
291 }, 322 },
292 dependencies = { 323 dependencies = {
293 lua_version_dep[flags["lua-versions"]], 324 lua_version_dep[args["lua_versions"]],
294 }, 325 },
295 build = {}, 326 build = {},
296 }) 327 })
@@ -301,19 +332,19 @@ function write_rockspec.command(flags, name, version, url_or_dir)
301 util.warning("Please specify supported Lua versions with --lua-versions=<ver>. "..util.see_help("write_rockspec")) 332 util.warning("Please specify supported Lua versions with --lua-versions=<ver>. "..util.see_help("write_rockspec"))
302 end 333 end
303 334
304 local local_dir = url_or_dir 335 local local_dir = location
305 336
306 if url_or_dir:match("://") then 337 if location:match("://") then
307 rockspec.source.file = dir.base_name(url_or_dir) 338 rockspec.source.file = dir.base_name(location)
308 if not dir.is_basic_protocol(rockspec.source.protocol) then 339 if not dir.is_basic_protocol(rockspec.source.protocol) then
309 if version ~= "dev" then 340 if version ~= "dev" then
310 rockspec.source.tag = flags["tag"] or "v" .. version 341 rockspec.source.tag = args["tag"] or "v" .. version
311 end 342 end
312 end 343 end
313 rockspec.source.dir = nil 344 rockspec.source.dir = nil
314 local ok, base_dir, temp_dir = fetch_url(rockspec) 345 local ok, base_dir, temp_dir = fetch_url(rockspec)
315 if ok then 346 if ok then
316 if base_dir ~= dir.base_name(url_or_dir) then 347 if base_dir ~= dir.base_name(location) then
317 rockspec.source.dir = base_dir 348 rockspec.source.dir = base_dir
318 end 349 end
319 end 350 end
@@ -329,10 +360,10 @@ function write_rockspec.command(flags, name, version, url_or_dir)
329 end 360 end
330 361
331 local libs = nil 362 local libs = nil
332 if flags["lib"] then 363 if args["lib"] then
333 libs = {} 364 libs = {}
334 rockspec.external_dependencies = {} 365 rockspec.external_dependencies = {}
335 for lib in flags["lib"]:gmatch("([^,]+)") do 366 for lib in args["lib"]:gmatch("([^,]+)") do
336 table.insert(libs, lib) 367 table.insert(libs, lib)
337 rockspec.external_dependencies[lib:upper()] = { 368 rockspec.external_dependencies[lib:upper()] = {
338 library = lib 369 library = lib
@@ -343,13 +374,13 @@ function write_rockspec.command(flags, name, version, url_or_dir)
343 local ok, err = fs.change_dir(local_dir) 374 local ok, err = fs.change_dir(local_dir)
344 if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end 375 if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end
345 376
346 if not (flags["summary"] and flags["detailed"]) then 377 if not (args["summary"] and args["detailed"]) then
347 local summary, detailed = detect_description() 378 local summary, detailed = detect_description()
348 rockspec.description.summary = flags["summary"] or summary 379 rockspec.description.summary = args["summary"] or summary
349 rockspec.description.detailed = flags["detailed"] or detailed 380 rockspec.description.detailed = args["detailed"] or detailed
350 end 381 end
351 382
352 if not flags["license"] then 383 if not args["license"] then
353 local license, fulltext = check_license() 384 local license, fulltext = check_license()
354 if license then 385 if license then
355 rockspec.description.license = license 386 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,
170 return nil, "Could not satisfy dependency "..tostring(dep)..": "..search_err 170 return nil, "Could not satisfy dependency "..tostring(dep)..": "..search_err
171 end 171 end
172 util.printout("Installing "..url) 172 util.printout("Installing "..url)
173 local install_flags = { 173 local install_args = {
174 rock = url,
174 deps_mode = deps_mode, 175 deps_mode = deps_mode,
175 namespace = dep.namespace, 176 namespace = dep.namespace,
176 verify = verify, 177 verify = verify,
177 } 178 }
178 local ok, install_err, errcode = install.command(install_flags, url) 179 local ok, install_err, errcode = install.command(install_args)
179 if not ok then 180 if not ok then
180 return nil, "Failed installing dependency: "..url.." - "..install_err, errcode 181 return nil, "Failed installing dependency: "..url.." - "..install_err, errcode
181 end 182 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)
251 self.config = self:load_config() or {} 251 self.config = self:load_config() or {}
252 self.config.server = flags["server"] or self.config.server or cfg.upload.server 252 self.config.server = flags["server"] or self.config.server or cfg.upload.server
253 self.config.version = self.config.version or cfg.upload.version 253 self.config.version = self.config.version or cfg.upload.version
254 self.config.key = flags["temp-key"] or flags["api-key"] or self.config.key 254 self.config.key = flags["temp_key"] or flags["api_key"] or self.config.key
255 self.debug = flags["debug"] 255 self.debug = flags["debug"]
256 if not self.config.key then 256 if not self.config.key then
257 return nil, "You need an API key to upload rocks.\n" .. 257 return nil, "You need an API key to upload rocks.\n" ..
258 "Navigate to "..self.config.server.."/settings to get a key\n" .. 258 "Navigate to "..self.config.server.."/settings to get a key\n" ..
259 "and then pass it through the --api-key=<key> flag." 259 "and then pass it through the --api-key=<key> flag."
260 end 260 end
261 if flags["api-key"] then 261 if flags["api_key"] then
262 self:save_config() 262 self:save_config()
263 end 263 end
264 return self 264 return self