aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-19 00:18:23 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-19 00:18:23 +0300
commitedfe8c0e5ea6b77a22a406df1a91102d70623041 (patch)
tree7c68cfa912910e60be76dfec28769d7d9a9c3203
parent9ada3aebd73450e29c64b2b6b56f85eba98e2634 (diff)
downloadluarocks-edfe8c0e5ea6b77a22a406df1a91102d70623041.tar.gz
luarocks-edfe8c0e5ea6b77a22a406df1a91102d70623041.tar.bz2
luarocks-edfe8c0e5ea6b77a22a406df1a91102d70623041.zip
cmd
-rw-r--r--src/luarocks/cmd/build.tl2
-rw-r--r--src/luarocks/cmd/init.tl2
-rw-r--r--src/luarocks/cmd/install.tl2
-rw-r--r--src/luarocks/cmd/list.tl46
-rw-r--r--src/luarocks/cmd/make.tl2
-rw-r--r--src/luarocks/cmd/new_version.tl45
-rw-r--r--src/luarocks/cmd/pack.tl15
-rw-r--r--src/luarocks/cmd/path.tl13
-rw-r--r--src/luarocks/cmd/purge.tl19
-rw-r--r--src/luarocks/cmd/remove.tl18
-rw-r--r--src/luarocks/cmd/search.tl20
-rw-r--r--src/luarocks/cmd/show.tl98
-rw-r--r--src/luarocks/cmd/test.tl13
-rw-r--r--src/luarocks/cmd/unpack.tl47
-rw-r--r--src/luarocks/cmd/upload.tl49
-rw-r--r--src/luarocks/cmd/which.tl15
-rw-r--r--src/luarocks/cmd/write_rockspec.tl2
-rw-r--r--src/luarocks/core/cfg.d.tl3
-rw-r--r--src/luarocks/core/types/args.d.tl30
-rw-r--r--src/luarocks/core/types/rockspec.tl2
-rw-r--r--src/luarocks/fs.d.tl1
-rw-r--r--src/luarocks/upload/multipart.tl2
-rw-r--r--src/luarocks/util.tl2
23 files changed, 311 insertions, 137 deletions
diff --git a/src/luarocks/cmd/build.tl b/src/luarocks/cmd/build.tl
index 13577c1a..9ec58c3e 100644
--- a/src/luarocks/cmd/build.tl
+++ b/src/luarocks/cmd/build.tl
@@ -54,7 +54,7 @@ function cmd_build.add_to_parser(parser: Parser)
54 "versions of each dependency found for this rock (recursively), ".. 54 "versions of each dependency found for this rock (recursively), "..
55 "and store it in the rock's directory. ".. 55 "and store it in the rock's directory. "..
56 "Ignores any existing luarocks.lock file in the rock's sources.") 56 "Ignores any existing luarocks.lock file in the rock's sources.")
57 make.cmd_options(cmd) --! 57 make.cmd_options(cmd as Parser)
58end 58end
59 59
60--- Build and install a rock. 60--- Build and install a rock.
diff --git a/src/luarocks/cmd/init.tl b/src/luarocks/cmd/init.tl
index 5223d01c..df365b75 100644
--- a/src/luarocks/cmd/init.tl
+++ b/src/luarocks/cmd/init.tl
@@ -38,7 +38,7 @@ function init.add_to_parser(parser: Parser)
38 cmd:flag("--no-wrapper-scripts", "Do not generate wrapper ./lua and ./luarocks launcher scripts.") 38 cmd:flag("--no-wrapper-scripts", "Do not generate wrapper ./lua and ./luarocks launcher scripts.")
39 cmd:flag("--no-gitignore", "Do not generate a .gitignore file.") 39 cmd:flag("--no-gitignore", "Do not generate a .gitignore file.")
40 40
41 cmd:group("Options for specifying rockspec data", write_rockspec.cmd_options(cmd)) --! 41 cmd:group("Options for specifying rockspec data", write_rockspec.cmd_options(cmd as Parser))
42end 42end
43 43
44local function gitignore_path(pwd: string, wrapper_dir: string, filename: string): string 44local function gitignore_path(pwd: string, wrapper_dir: string, filename: string): string
diff --git a/src/luarocks/cmd/install.tl b/src/luarocks/cmd/install.tl
index db72c77d..40f6c782 100644
--- a/src/luarocks/cmd/install.tl
+++ b/src/luarocks/cmd/install.tl
@@ -54,7 +54,7 @@ function install.add_to_parser(parser: Parser)
54 "option to work properly.") 54 "option to work properly.")
55 cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. 55 cmd:flag("--check-lua-versions", "If the rock can't be found, check repository "..
56 "and report if it is available for another Lua version.") 56 "and report if it is available for another Lua version.")
57 util.deps_mode_option(cmd) --! 57 util.deps_mode_option(cmd as Parser)
58 cmd:flag("--no-manifest", "Skip creating/updating the manifest") 58 cmd:flag("--no-manifest", "Skip creating/updating the manifest")
59 cmd:flag("--pin", "If the installed rock is a Lua module, create a ".. 59 cmd:flag("--pin", "If the installed rock is a Lua module, create a "..
60 "luarocks.lock file listing the exact versions of each dependency found for ".. 60 "luarocks.lock file listing the exact versions of each dependency found for "..
diff --git a/src/luarocks/cmd/list.tl b/src/luarocks/cmd/list.tl
index 56f4de02..558ea09a 100644
--- a/src/luarocks/cmd/list.tl
+++ b/src/luarocks/cmd/list.tl
@@ -2,6 +2,12 @@
2--- Module implementing the LuaRocks "list" command. 2--- Module implementing the LuaRocks "list" command.
3-- Lists currently installed rocks. 3-- Lists currently installed rocks.
4local record list 4local record list
5 record Outdated
6 name: string
7 installed: string
8 available: string
9 repo: string
10 end
5end 11end
6 12
7local search = require("luarocks.search") 13local search = require("luarocks.search")
@@ -11,33 +17,21 @@ local cfg = require("luarocks.core.cfg")
11local util = require("luarocks.util") 17local util = require("luarocks.util")
12local path = require("luarocks.path") 18local path = require("luarocks.path")
13 19
20local type Outdated = list.Outdated
21
14local argparse = require("luarocks.vendor.argparse") 22local argparse = require("luarocks.vendor.argparse")
15local type Parser = argparse.Parser 23local type Parser = argparse.Parser
16local type Option = argparse.Option
17 24
18local type a = require("luarocks.core.types.args") 25local type a = require("luarocks.core.types.args")
19local type Args = a.Args 26local type Args = a.Args
20 27
21local type bo = require("luarocks.core.types.bopts")
22local type BOpts = bo.BOpts
23
24local type i = require("luarocks.core.types.installs")
25local type IOpts = i.IOpts
26
27local type p = require("luarocks.core.types.persist")
28local type PersistableTable = p.PersistableTable
29
30local type t = require("luarocks.core.types.tree") 28local type t = require("luarocks.core.types.tree")
31local type Tree = t.Tree 29local type Tree = t.Tree
32 30
33local type b = require("luarocks.core.types.build") 31local type q = require("luarocks.core.types.query")
34local type BuiltinBuild = b.BuiltinBuild 32local type Query = q.Query
35
36local type r = require("luarocks.core.types.rockspec")
37local type Rockspec = r.Rockspec
38local type Dependencies = r.Dependencies
39 33
40function list.add_to_parser(parser) 34function list.add_to_parser(parser: Parser)
41 local cmd = parser:command("list", "List currently installed rocks.", util.see_also()) 35 local cmd = parser:command("list", "List currently installed rocks.", util.see_also())
42 36
43 cmd:argument("filter", "A substring of a rock name to filter by.") 37 cmd:argument("filter", "A substring of a rock name to filter by.")
@@ -50,19 +44,19 @@ function list.add_to_parser(parser)
50 cmd:flag("--porcelain", "Produce machine-friendly output.") 44 cmd:flag("--porcelain", "Produce machine-friendly output.")
51end 45end
52 46
53local function check_outdated(trees, query) 47local function check_outdated(trees: {string | Tree}, query: Query): {Outdated}
54 local results_installed = {} 48 local results_installed = {}
55 for _, tree in ipairs(trees) do 49 for _, tree in ipairs(trees) do
56 search.local_manifest_search(results_installed, path.rocks_dir(tree), query) 50 search.local_manifest_search(results_installed, path.rocks_dir(tree), query)
57 end 51 end
58 local outdated = {} 52 local outdated: {Outdated} = {}
59 for name, versions in util.sortedpairs(results_installed) do 53 for name, versions in util.sortedpairs(results_installed) do
60 versions = util.keys(versions) 54 local versionsk = util.keys(versions)
61 table.sort(versions, vers.compare_versions) 55 table.sort(versionsk, vers.compare_versions)
62 local latest_installed = versions[1] 56 local latest_installed = versionsk[1]
63 57
64 local query_available = queries.new(name:lower()) 58 local query_available = queries.new(name:lower())
65 local results_available, err = search.search_repos(query_available) 59 local results_available = search.search_repos(query_available)
66 60
67 if results_available[name] then 61 if results_available[name] then
68 local available_versions = util.keys(results_available[name]) 62 local available_versions = util.keys(results_available[name])
@@ -71,14 +65,14 @@ local function check_outdated(trees, query)
71 local latest_available_repo = results_available[name][latest_available][1].repo 65 local latest_available_repo = results_available[name][latest_available][1].repo
72 66
73 if vers.compare_versions(latest_available, latest_installed) then 67 if vers.compare_versions(latest_available, latest_installed) then
74 table.insert(outdated, { name = name, installed = latest_installed, available = latest_available, repo = latest_available_repo }) 68 table.insert(outdated, { name = name, installed = latest_installed, available = latest_available, repo = latest_available_repo } as Outdated)
75 end 69 end
76 end 70 end
77 end 71 end
78 return outdated 72 return outdated
79end 73end
80 74
81local function list_outdated(trees, query, porcelain) 75local function list_outdated(trees: {string | Tree}, query: Query, porcelain: boolean): boolean
82 util.title("Outdated rocks:", porcelain) 76 util.title("Outdated rocks:", porcelain)
83 local outdated = check_outdated(trees, query) 77 local outdated = check_outdated(trees, query)
84 for _, item in ipairs(outdated) do 78 for _, item in ipairs(outdated) do
@@ -95,7 +89,7 @@ end
95 89
96--- Driver function for "list" command. 90--- Driver function for "list" command.
97-- @return boolean: True if succeeded, nil on errors. 91-- @return boolean: True if succeeded, nil on errors.
98function list.command(args) 92function list.command(args: Args): boolean, string
99 local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true) 93 local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true)
100 local trees = cfg.rocks_trees 94 local trees = cfg.rocks_trees
101 local title = "Rocks installed for Lua "..cfg.lua_version 95 local title = "Rocks installed for Lua "..cfg.lua_version
diff --git a/src/luarocks/cmd/make.tl b/src/luarocks/cmd/make.tl
index ab6c83da..f151c950 100644
--- a/src/luarocks/cmd/make.tl
+++ b/src/luarocks/cmd/make.tl
@@ -81,7 +81,7 @@ overrides and recreates this file scanning dependency based on ranges.
81 cmd:argument("rockspec", "Rockspec for the rock to build.") 81 cmd:argument("rockspec", "Rockspec for the rock to build.")
82 :args("?") 82 :args("?")
83 83
84 make.cmd_options(cmd) --! 84 make.cmd_options(cmd as Parser) --!
85end 85end
86 86
87--- Driver function for "make" command. 87--- Driver function for "make" command.
diff --git a/src/luarocks/cmd/new_version.tl b/src/luarocks/cmd/new_version.tl
index 2ec084e0..d61cb48b 100644
--- a/src/luarocks/cmd/new_version.tl
+++ b/src/luarocks/cmd/new_version.tl
@@ -1,7 +1,8 @@
1 1
2--- Module implementing the LuaRocks "new_version" command. 2--- Module implementing the LuaRocks "new_version" command.
3-- Utility function that writes a new rockspec, updating data from a previous one. 3-- Utility function that writes a new rockspec, updating data from a previous one.
4local new_version = {} 4local record new_version
5end
5 6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local download = require("luarocks.download") 8local download = require("luarocks.download")
@@ -11,7 +12,19 @@ local fs = require("luarocks.fs")
11local dir = require("luarocks.dir") 12local dir = require("luarocks.dir")
12local type_rockspec = require("luarocks.type.rockspec") 13local type_rockspec = require("luarocks.type.rockspec")
13 14
14function new_version.add_to_parser(parser) 15local argparse = require("luarocks.vendor.argparse")
16local type Parser = argparse.Parser
17
18local type a = require("luarocks.core.types.args")
19local type Args = a.Args
20
21local type p = require("luarocks.core.types.persist")
22local type PersistableTable = p.PersistableTable
23
24local type r = require("luarocks.core.types.rockspec")
25local type Rockspec = r.Rockspec
26
27function new_version.add_to_parser(parser: Parser)
15 local cmd = parser:command("new_version", [[ 28 local cmd = parser:command("new_version", [[
16This is a utility function that writes a new rockspec, updating data from a 29This is a utility function that writes a new rockspec, updating data from a
17previous one. 30previous one.
@@ -51,7 +64,7 @@ if it already exists.]], util.see_also())
51end 64end
52 65
53 66
54local function try_replace(tbl, field, old, new) 67local function try_replace(tbl: {string: string}, field: string, old: string, new: string): boolean
55 if not tbl[field] then 68 if not tbl[field] then
56 return false 69 return false
57 end 70 end
@@ -69,7 +82,7 @@ end
69-- If it specified MD5, update it. 82-- If it specified MD5, update it.
70-- @return (true, false) if MD5 was not specified or it stayed same, 83-- @return (true, false) if MD5 was not specified or it stayed same,
71-- (true, true) if MD5 changed, (nil, string) on error. 84-- (true, true) if MD5 changed, (nil, string) on error.
72local function check_url_and_update_md5(out_rs, invalid_is_error) 85local function check_url_and_update_md5(out_rs: Rockspec, invalid_is_error?: boolean): boolean, string | boolean --!
73 local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package) 86 local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package)
74 if not file then 87 if not file then
75 if invalid_is_error then 88 if invalid_is_error then
@@ -105,7 +118,7 @@ local function check_url_and_update_md5(out_rs, invalid_is_error)
105 end 118 end
106end 119end
107 120
108local function update_source_section(out_rs, url, tag, old_ver, new_ver) 121local function update_source_section(out_rs: Rockspec, url: string, tag: string, old_ver: string, new_ver: string): boolean, string | boolean
109 if tag then 122 if tag then
110 out_rs.source.tag = tag 123 out_rs.source.tag = tag
111 end 124 end
@@ -117,21 +130,21 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver)
117 return true 130 return true
118 end 131 end
119 if out_rs.source.dir then 132 if out_rs.source.dir then
120 try_replace(out_rs.source, "dir", old_ver, new_ver) 133 try_replace(out_rs.source as {string: string}, "dir", old_ver, new_ver)
121 end 134 end
122 if out_rs.source.file then 135 if out_rs.source.file then
123 try_replace(out_rs.source, "file", old_ver, new_ver) 136 try_replace(out_rs.source as {string: string}, "file", old_ver, new_ver)
124 end 137 end
125 138
126 local old_url = out_rs.source.url 139 local old_url = out_rs.source.url
127 if try_replace(out_rs.source, "url", old_ver, new_ver) then 140 if try_replace(out_rs.source as {string: string}, "url", old_ver, new_ver) then
128 local ok, md5_changed = check_url_and_update_md5(out_rs, true) 141 local ok, md5_changed = check_url_and_update_md5(out_rs, true)
129 if ok then 142 if ok then
130 return ok, md5_changed 143 return ok, md5_changed
131 end 144 end
132 out_rs.source.url = old_url 145 out_rs.source.url = old_url
133 end 146 end
134 if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then 147 if tag or try_replace(out_rs.source as {string: string}, "tag", old_ver, new_ver) then
135 return true 148 return true
136 end 149 end
137 -- Couldn't replace anything significant, use the old URL. 150 -- Couldn't replace anything significant, use the old URL.
@@ -145,16 +158,16 @@ local function update_source_section(out_rs, url, tag, old_ver, new_ver)
145 return true 158 return true
146end 159end
147 160
148function new_version.command(args) 161function new_version.command(args: Args): boolean, string | boolean
149 if not args.rock then 162 if not args.rock then
150 local err 163 local err: string
151 args.rock, err = util.get_default_rockspec() 164 args.rock, err = util.get_default_rockspec()
152 if not args.rock then 165 if not args.rock then
153 return nil, err 166 return nil, err
154 end 167 end
155 end 168 end
156 169
157 local filename, err 170 local filename, err: string, string
158 if args.rock:match("rockspec$") then 171 if args.rock:match("rockspec$") then
159 filename, err = fetch.fetch_url(args.rock) 172 filename, err = fetch.fetch_url(args.rock)
160 if not filename then 173 if not filename then
@@ -173,13 +186,13 @@ function new_version.command(args)
173 end 186 end
174 187
175 local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") 188 local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$")
176 local new_ver, new_rev 189 local new_ver, new_rev: string, string
177 190
178 if args.tag and not args.new_version then 191 if args.tag and not args.new_version then
179 args.new_version = args.tag:gsub("^v", "") 192 args.new_version = args.tag:gsub("^v", "")
180 end 193 end
181 194
182 local out_dir 195 local out_dir: string
183 if args.dir then 196 if args.dir then
184 out_dir = dir.normalize(args.dir) 197 out_dir = dir.normalize(args.dir)
185 end 198 end
@@ -197,7 +210,7 @@ function new_version.command(args)
197 end 210 end
198 local new_rockver = new_ver:gsub("-", "") 211 local new_rockver = new_ver:gsub("-", "")
199 212
200 local out_rs, err = persist.load_into_table(filename) 213 local out_rs, err = persist.load_into_table(filename) as Rockspec, string
201 local out_name = out_rs.package:lower() 214 local out_name = out_rs.package:lower()
202 out_rs.version = new_rockver.."-"..new_rev 215 out_rs.version = new_rockver.."-"..new_rev
203 216
@@ -213,7 +226,7 @@ function new_version.command(args)
213 out_filename = dir.path(out_dir, out_filename) 226 out_filename = dir.path(out_dir, out_filename)
214 fs.make_dir(out_dir) 227 fs.make_dir(out_dir)
215 end 228 end
216 persist.save_from_table(out_filename, out_rs, type_rockspec.order) 229 persist.save_from_table(out_filename, out_rs as PersistableTable, type_rockspec.order)
217 230
218 util.printout("Wrote "..out_filename) 231 util.printout("Wrote "..out_filename)
219 232
diff --git a/src/luarocks/cmd/pack.tl b/src/luarocks/cmd/pack.tl
index 29a43e7b..0baaab10 100644
--- a/src/luarocks/cmd/pack.tl
+++ b/src/luarocks/cmd/pack.tl
@@ -1,13 +1,20 @@
1 1
2--- Module implementing the LuaRocks "pack" command. 2--- Module implementing the LuaRocks "pack" command.
3-- Creates a rock, packing sources or binaries. 3-- Creates a rock, packing sources or binaries.
4local cmd_pack = {} 4local record cmd_pack
5end
5 6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local pack = require("luarocks.pack") 8local pack = require("luarocks.pack")
8local queries = require("luarocks.queries") 9local queries = require("luarocks.queries")
9 10
10function cmd_pack.add_to_parser(parser) 11local argparse = require("luarocks.vendor.argparse")
12local type Parser = argparse.Parser
13
14local type a = require("luarocks.core.types.args")
15local type Args = a.Args
16
17function cmd_pack.add_to_parser(parser: Parser)
11 local cmd = parser:command("pack", "Create a rock, packing sources or binaries.", util.see_also()) 18 local cmd = parser:command("pack", "Create a rock, packing sources or binaries.", util.see_also())
12 19
13 cmd:argument("rock", "A rockspec file, for creating a source rock, or the ".. 20 cmd:argument("rock", "A rockspec file, for creating a source rock, or the "..
@@ -22,8 +29,8 @@ end
22--- Driver function for the "pack" command. 29--- Driver function for the "pack" command.
23-- @return boolean or (nil, string): true if successful or nil followed 30-- @return boolean or (nil, string): true if successful or nil followed
24-- by an error message. 31-- by an error message.
25function cmd_pack.command(args) 32function cmd_pack.command(args: Args): boolean, string
26 local file, err 33 local file, err: string, string
27 if args.rock:match(".*%.rockspec") then 34 if args.rock:match(".*%.rockspec") then
28 file, err = pack.pack_source_rock(args.rock) 35 file, err = pack.pack_source_rock(args.rock)
29 else 36 else
diff --git a/src/luarocks/cmd/path.tl b/src/luarocks/cmd/path.tl
index ba346550..082c96bf 100644
--- a/src/luarocks/cmd/path.tl
+++ b/src/luarocks/cmd/path.tl
@@ -1,13 +1,20 @@
1 1
2--- @module luarocks.path_cmd 2--- @module luarocks.path_cmd
3-- Driver for the `luarocks path` command. 3-- Driver for the `luarocks path` command.
4local path_cmd = {} 4local record path_cmd
5end
5 6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local cfg = require("luarocks.core.cfg") 8local cfg = require("luarocks.core.cfg")
8local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
9 10
10function path_cmd.add_to_parser(parser) 11local argparse = require("luarocks.vendor.argparse")
12local type Parser = argparse.Parser
13
14local type a = require("luarocks.core.types.args")
15local type Args = a.Args
16
17function path_cmd.add_to_parser(parser: Parser)
11 local cmd = parser:command("path", [[ 18 local cmd = parser:command("path", [[
12Returns the package path currently configured for this installation 19Returns the package path currently configured for this installation
13of LuaRocks, formatted as shell commands to update LUA_PATH and LUA_CPATH. 20of LuaRocks, formatted as shell commands to update LUA_PATH and LUA_CPATH.
@@ -38,7 +45,7 @@ end
38 45
39--- Driver function for "path" command. 46--- Driver function for "path" command.
40-- @return boolean This function always succeeds. 47-- @return boolean This function always succeeds.
41function path_cmd.command(args) 48function path_cmd.command(args: Args): boolean, string
42 local lr_path, lr_cpath, lr_bin = cfg.package_paths(args.tree) 49 local lr_path, lr_cpath, lr_bin = cfg.package_paths(args.tree)
43 local path_sep = cfg.export_path_separator 50 local path_sep = cfg.export_path_separator
44 51
diff --git a/src/luarocks/cmd/purge.tl b/src/luarocks/cmd/purge.tl
index fda8ab88..b83f8e52 100644
--- a/src/luarocks/cmd/purge.tl
+++ b/src/luarocks/cmd/purge.tl
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "purge" command. 2--- Module implementing the LuaRocks "purge" command.
3-- Remove all rocks from a given tree. 3-- Remove all rocks from a given tree.
4local purge = {} 4local record purge
5 needs_lock: function(Args): boolean
6end
5 7
6local util = require("luarocks.util") 8local util = require("luarocks.util")
7local path = require("luarocks.path") 9local path = require("luarocks.path")
@@ -12,7 +14,14 @@ local cfg = require("luarocks.core.cfg")
12local remove = require("luarocks.remove") 14local remove = require("luarocks.remove")
13local queries = require("luarocks.queries") 15local queries = require("luarocks.queries")
14 16
15function purge.add_to_parser(parser) 17local argparse = require("luarocks.vendor.argparse")
18local type Parser = argparse.Parser
19
20local type args = require("luarocks.core.types.args")
21local type Args = args.Args
22
23
24function purge.add_to_parser(parser: Parser)
16 -- luacheck: push ignore 431 25 -- luacheck: push ignore 431
17 local cmd = parser:command("purge", [[ 26 local cmd = parser:command("purge", [[
18This command removes rocks en masse from a given tree. 27This command removes rocks en masse from a given tree.
@@ -33,13 +42,13 @@ The --tree option is mandatory: luarocks purge does not assume a default tree.]]
33 "without reporting dependency issues.") 42 "without reporting dependency issues.")
34end 43end
35 44
36function purge.command(args) 45function purge.command(args: Args): boolean, string
37 local tree = args.tree 46 local tree = args.tree
38 47
39 local results = {} 48 local results = {}
40 search.local_manifest_search(results, path.rocks_dir(tree), queries.all()) 49 search.local_manifest_search(results, path.rocks_dir(tree), queries.all())
41 50
42 local sort = function(a,b) return vers.compare_versions(b,a) end 51 local sort = function(a: string,b: string): boolean return vers.compare_versions(b,a) end
43 if args.old_versions then 52 if args.old_versions then
44 sort = vers.compare_versions 53 sort = vers.compare_versions
45 end 54 end
@@ -67,6 +76,6 @@ function purge.command(args)
67 return repo_writer.refresh_manifest(cfg.rocks_dir) 76 return repo_writer.refresh_manifest(cfg.rocks_dir)
68end 77end
69 78
70purge.needs_lock = function() return true end 79purge.needs_lock = function(): boolean return true end
71 80
72return purge 81return purge
diff --git a/src/luarocks/cmd/remove.tl b/src/luarocks/cmd/remove.tl
index 630303ca..4dbef645 100644
--- a/src/luarocks/cmd/remove.tl
+++ b/src/luarocks/cmd/remove.tl
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "remove" command. 2--- Module implementing the LuaRocks "remove" command.
3-- Uninstalls rocks. 3-- Uninstalls rocks.
4local cmd_remove = {} 4local record cmd_remove
5 needs_lock: function(Args): boolean
6end
5 7
6local remove = require("luarocks.remove") 8local remove = require("luarocks.remove")
7local util = require("luarocks.util") 9local util = require("luarocks.util")
@@ -11,7 +13,13 @@ local path = require("luarocks.path")
11local deps = require("luarocks.deps") 13local deps = require("luarocks.deps")
12local queries = require("luarocks.queries") 14local queries = require("luarocks.queries")
13 15
14function cmd_remove.add_to_parser(parser) 16local argparse = require("luarocks.vendor.argparse")
17local type Parser = argparse.Parser
18
19local type a = require("luarocks.core.types.args")
20local type Args = a.Args
21
22function cmd_remove.add_to_parser(parser: Parser)
15 -- luacheck: push ignore 431 23 -- luacheck: push ignore 431
16 local cmd = parser:command("remove", [[ 24 local cmd = parser:command("remove", [[
17Uninstall a rock. 25Uninstall a rock.
@@ -30,13 +38,13 @@ To override this check and force the removal, use --force or --force-fast.]],
30 38
31 cmd:flag("--force", "Force removal if it would break dependencies.") 39 cmd:flag("--force", "Force removal if it would break dependencies.")
32 cmd:flag("--force-fast", "Perform a forced removal without reporting dependency issues.") 40 cmd:flag("--force-fast", "Perform a forced removal without reporting dependency issues.")
33 util.deps_mode_option(cmd) 41 util.deps_mode_option(cmd as Parser)
34end 42end
35 43
36--- Driver function for the "remove" command. 44--- Driver function for the "remove" command.
37-- @return boolean or (nil, string, exitcode): True if removal was 45-- @return boolean or (nil, string, exitcode): True if removal was
38-- successful, nil and an error message otherwise. exitcode is optionally returned. 46-- successful, nil and an error message otherwise. exitcode is optionally returned.
39function cmd_remove.command(args) 47function cmd_remove.command(args: Args): boolean, string
40 local name = args.rock 48 local name = args.rock
41 local deps_mode = deps.get_deps_mode(args) 49 local deps_mode = deps.get_deps_mode(args)
42 50
@@ -66,6 +74,6 @@ function cmd_remove.command(args)
66 return true 74 return true
67end 75end
68 76
69cmd_remove.needs_lock = function() return true end 77cmd_remove.needs_lock = function(): boolean return true end
70 78
71return cmd_remove 79return cmd_remove
diff --git a/src/luarocks/cmd/search.tl b/src/luarocks/cmd/search.tl
index 6cab6d80..8474cf60 100644
--- a/src/luarocks/cmd/search.tl
+++ b/src/luarocks/cmd/search.tl
@@ -1,7 +1,8 @@
1 1
2--- Module implementing the LuaRocks "search" command. 2--- Module implementing the LuaRocks "search" command.
3-- Queries LuaRocks servers. 3-- Queries LuaRocks servers.
4local cmd_search = {} 4local record cmd_search
5end
5 6
6local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
7local util = require("luarocks.util") 8local util = require("luarocks.util")
@@ -9,7 +10,16 @@ local search = require("luarocks.search")
9local queries = require("luarocks.queries") 10local queries = require("luarocks.queries")
10local results = require("luarocks.results") 11local results = require("luarocks.results")
11 12
12function cmd_search.add_to_parser(parser) 13local argparse = require("luarocks.vendor.argparse")
14local type Parser = argparse.Parser
15
16local type a = require("luarocks.core.types.args")
17local type Args = a.Args
18
19local type res = require("luarocks.core.types.result")
20local type Result = res.Result
21
22function cmd_search.add_to_parser(parser: Parser)
13 local cmd = parser:command("search", "Query the LuaRocks servers.", util.see_also()) 23 local cmd = parser:command("search", "Query the LuaRocks servers.", util.see_also())
14 24
15 cmd:argument("name", "Name of the rock to search for.") 25 cmd:argument("name", "Name of the rock to search for.")
@@ -33,7 +43,7 @@ end
33-- @param result_tree table: A search results table. 43-- @param result_tree table: A search results table.
34-- @return (table, table): Two tables, one for source and one for binary 44-- @return (table, table): Two tables, one for source and one for binary
35-- results. 45-- results.
36local function split_source_and_binary_results(result_tree) 46local function split_source_and_binary_results(result_tree: {string: {string: {Result}}}): {string : {string : {Result}}}, {string : {string : {Result}}}
37 local sources, binaries = {}, {} 47 local sources, binaries = {}, {}
38 for name, versions in pairs(result_tree) do 48 for name, versions in pairs(result_tree) do
39 for version, repositories in pairs(versions) do 49 for version, repositories in pairs(versions) do
@@ -53,7 +63,7 @@ end
53--- Driver function for "search" command. 63--- Driver function for "search" command.
54-- @return boolean or (nil, string): True if build was successful; nil and an 64-- @return boolean or (nil, string): True if build was successful; nil and an
55-- error message otherwise. 65-- error message otherwise.
56function cmd_search.command(args) 66function cmd_search.command(args: Args): boolean, string
57 local name = args.name 67 local name = args.name
58 68
59 if args.all then 69 if args.all then
@@ -65,7 +75,7 @@ function cmd_search.command(args)
65 end 75 end
66 76
67 local query = queries.new(name, args.namespace, args.version, true) 77 local query = queries.new(name, args.namespace, args.version, true)
68 local result_tree, err = search.search_repos(query) 78 local result_tree = search.search_repos(query)
69 local porcelain = args.porcelain 79 local porcelain = args.porcelain
70 local full_name = util.format_rock_name(name, args.namespace, args.version) 80 local full_name = util.format_rock_name(name, args.namespace, args.version)
71 util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=") 81 util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=")
diff --git a/src/luarocks/cmd/show.tl b/src/luarocks/cmd/show.tl
index 88cbbada..4850b3af 100644
--- a/src/luarocks/cmd/show.tl
+++ b/src/luarocks/cmd/show.tl
@@ -1,6 +1,12 @@
1--- Module implementing the LuaRocks "show" command. 1--- Module implementing the LuaRocks "show" command.
2-- Shows information about an installed rock. 2-- Shows information about an installed rock.
3local show = {} 3local record show
4 record Return
5 name: string
6 file: string
7 lable: string
8 end
9end
4 10
5local queries = require("luarocks.queries") 11local queries = require("luarocks.queries")
6local search = require("luarocks.search") 12local search = require("luarocks.search")
@@ -13,7 +19,41 @@ local fetch = require("luarocks.fetch")
13local manif = require("luarocks.manif") 19local manif = require("luarocks.manif")
14local repos = require("luarocks.repos") 20local repos = require("luarocks.repos")
15 21
16function show.add_to_parser(parser) 22local type Return = show.Return
23
24local argparse = require("luarocks.vendor.argparse")
25local type Parser = argparse.Parser
26local type Option = argparse.Option
27
28local type a = require("luarocks.core.types.args")
29local type Args = a.Args
30
31local type bo = require("luarocks.core.types.bopts")
32local type BOpts = bo.BOpts
33
34local type i = require("luarocks.core.types.installs")
35local type IOpts = i.IOpts
36
37local type p = require("luarocks.core.types.persist")
38local type PersistableTable = p.PersistableTable
39
40local type res = require("luarocks.core.types.result")
41local type Result = res.Result
42
43local type t = require("luarocks.core.types.tree")
44local type Tree = t.Tree
45
46local type q = require("luarocks.core.types.query")
47local type Query = q.Query
48
49local type r = require("luarocks.core.types.rockspec")
50local type Rockspec = r.Rockspec
51local type Dependencies = r.Dependencies
52
53local type m = require("luarocks.core.types.manifest")
54local type Entry = m.Manifest.Entry
55
56function show.add_to_parser(parser: Parser)
17 local cmd = parser:command("show", [[ 57 local cmd = parser:command("show", [[
18Show information about an installed rock. 58Show information about an installed rock.
19 59
@@ -94,14 +134,14 @@ local porcelain_template = [[
94*ideps :indirect_dependency\t${name}\t${label} 134*ideps :indirect_dependency\t${name}\t${label}
95]] 135]]
96 136
97local function keys_as_string(t, sep) 137local function keys_as_string(t: {string: any}, sep: string): string
98 local keys = util.keys(t) 138 local keys = util.keys(t)
99 table.sort(keys) 139 table.sort(keys)
100 return table.concat(keys, sep or " ") 140 return table.concat(keys, sep or " ")
101end 141end
102 142
103local function word_wrap(line) 143local function word_wrap(line: string): string
104 local width = tonumber(os.getenv("COLUMNS")) or 80 144 local width = math.tointeger(os.getenv("COLUMNS")) or 80 --! tonumber to tointeger
105 if width > 80 then width = 80 end 145 if width > 80 then width = 80 end
106 if #line > width then 146 if #line > width then
107 local brk = width 147 local brk = width
@@ -115,7 +155,7 @@ local function word_wrap(line)
115 return line 155 return line
116end 156end
117 157
118local function format_text(text) 158local function format_text(text: string): string
119 text = text:gsub("^%s*",""):gsub("%s$", ""):gsub("\n[ \t]+","\n"):gsub("([^\n])\n([^\n])","%1 %2") 159 text = text:gsub("^%s*",""):gsub("%s$", ""):gsub("\n[ \t]+","\n"):gsub("([^\n])\n([^\n])","%1 %2")
120 local paragraphs = util.split_string(text, "\n\n") 160 local paragraphs = util.split_string(text, "\n\n")
121 for n, line in ipairs(paragraphs) do 161 for n, line in ipairs(paragraphs) do
@@ -124,8 +164,8 @@ local function format_text(text)
124 return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) 164 return (table.concat(paragraphs, "\n\n"):gsub("%s$", ""))
125end 165end
126 166
127local function installed_rock_label(dep, tree) 167local function installed_rock_label(dep: Query, tree: string | Tree): string
128 local installed, version 168 local installed, version: string, string
129 local rocks_provided = util.get_rocks_provided() 169 local rocks_provided = util.get_rocks_provided()
130 if rocks_provided[dep.name] then 170 if rocks_provided[dep.name] then
131 installed, version = true, rocks_provided[dep.name] 171 installed, version = true, rocks_provided[dep.name]
@@ -135,7 +175,7 @@ local function installed_rock_label(dep, tree)
135 return installed and "using "..version or "missing" 175 return installed and "using "..version or "missing"
136end 176end
137 177
138local function render(template, data) 178local function render(template: string, data: {string: string | {string}}): string
139 local out = {} 179 local out = {}
140 for cmd, var, line in template:gmatch("(.)([a-z]*)%s*:([^\n]*)\n") do 180 for cmd, var, line in template:gmatch("(.)([a-z]*)%s*:([^\n]*)\n") do
141 line = line:gsub("\\t", "\t") 181 line = line:gsub("\\t", "\t")
@@ -144,12 +184,12 @@ local function render(template, data)
144 table.insert(out, line) 184 table.insert(out, line)
145 elseif cmd == "?" or cmd == "*" or cmd == "!" then 185 elseif cmd == "?" or cmd == "*" or cmd == "!" then
146 if (cmd == "!" and d == nil) 186 if (cmd == "!" and d == nil)
147 or (cmd ~= "!" and (type(d) == "string" 187 or (cmd ~= "!" and (d is string
148 or (type(d) == "table" and next(d)))) then 188 or (d is {string} and next(d) ~= nil))) then
149 local n = cmd == "*" and #d or 1 189 local n = cmd == "*" and #d or 1
150 for i = 1, n do 190 for i = 1, n do
151 local tbl = cmd == "*" and d[i] or data 191 local tbl = cmd == "*" and d[i] or data
152 if type(tbl) == "string" then 192 if tbl is string then
153 tbl = tbl:gsub("%%", "%%%%") 193 tbl = tbl:gsub("%%", "%%%%")
154 end 194 end
155 table.insert(out, (line:gsub("${([a-z]+)}", tbl))) 195 table.insert(out, (line:gsub("${([a-z]+)}", tbl)))
@@ -160,7 +200,7 @@ local function render(template, data)
160 return table.concat(out, "\n") 200 return table.concat(out, "\n")
161end 201end
162 202
163local function adjust_path(name, version, basedir, pathname, suffix) 203local function adjust_path(name: string, version: string, basedir: string, pathname: string, suffix?: string): string
164 pathname = dir.path(basedir, pathname) 204 pathname = dir.path(basedir, pathname)
165 local vpathname = path.versioned_name(pathname, basedir, name, version) 205 local vpathname = path.versioned_name(pathname, basedir, name, version)
166 return (fs.exists(vpathname) 206 return (fs.exists(vpathname)
@@ -168,25 +208,25 @@ local function adjust_path(name, version, basedir, pathname, suffix)
168 or pathname) .. (suffix or "") 208 or pathname) .. (suffix or "")
169end 209end
170 210
171local function modules_to_list(name, version, repo) 211local function modules_to_list(name: string, version: string, repo: string | Tree): {Return}
172 local ret = {} 212 local ret: {Return} = {}
173 local rock_manifest = manif.load_rock_manifest(name, version, repo) 213 local rock_manifest = manif.load_rock_manifest(name, version, repo)
174 214
175 local lua_dir = path.deploy_lua_dir(repo) 215 local lua_dir = path.deploy_lua_dir(repo)
176 local lib_dir = path.deploy_lib_dir(repo) 216 local lib_dir = path.deploy_lib_dir(repo)
177 repos.recurse_rock_manifest_entry(rock_manifest.lua, function(pathname) 217 repos.recurse_rock_manifest_entry(rock_manifest.lua, function(pathname: string): boolean, string
178 table.insert(ret, { 218 table.insert(ret, {
179 name = path.path_to_module(pathname), 219 name = path.path_to_module(pathname),
180 file = adjust_path(name, version, lua_dir, pathname), 220 file = adjust_path(name, version, lua_dir, pathname),
181 }) 221 })
182 end) 222 end)
183 repos.recurse_rock_manifest_entry(rock_manifest.lib, function(pathname) 223 repos.recurse_rock_manifest_entry(rock_manifest.lib, function(pathname: string): boolean, string
184 table.insert(ret, { 224 table.insert(ret, {
185 name = path.path_to_module(pathname), 225 name = path.path_to_module(pathname),
186 file = adjust_path(name, version, lib_dir, pathname), 226 file = adjust_path(name, version, lib_dir, pathname),
187 }) 227 })
188 end) 228 end)
189 table.sort(ret, function(a, b) 229 table.sort(ret, function(a: Return, b: Return): boolean
190 if a.name == b.name then 230 if a.name == b.name then
191 return a.file < b.file 231 return a.file < b.file
192 end 232 end
@@ -195,18 +235,18 @@ local function modules_to_list(name, version, repo)
195 return ret 235 return ret
196end 236end
197 237
198local function commands_to_list(name, version, repo) 238local function commands_to_list(name: string, version: string, repo: string | Tree): {Return}
199 local ret = {} 239 local ret: {Return} = {}
200 local rock_manifest = manif.load_rock_manifest(name, version, repo) 240 local rock_manifest = manif.load_rock_manifest(name, version, repo)
201 241
202 local bin_dir = path.deploy_bin_dir(repo) 242 local bin_dir = path.deploy_bin_dir(repo)
203 repos.recurse_rock_manifest_entry(rock_manifest.bin, function(pathname) 243 repos.recurse_rock_manifest_entry(rock_manifest.bin, function(pathname: string): boolean, string
204 table.insert(ret, { 244 table.insert(ret, {
205 name = name, 245 name = name,
206 file = adjust_path(name, version, bin_dir, pathname, cfg.wrapper_suffix), 246 file = adjust_path(name, version, bin_dir, pathname, cfg.wrapper_suffix),
207 }) 247 })
208 end) 248 end)
209 table.sort(ret, function(a, b) 249 table.sort(ret, function(a: Return, b: Return): boolean
210 if a.name == b.name then 250 if a.name == b.name then
211 return a.file < b.file 251 return a.file < b.file
212 end 252 end
@@ -215,16 +255,16 @@ local function commands_to_list(name, version, repo)
215 return ret 255 return ret
216end 256end
217 257
218local function deps_to_list(dependencies, tree) 258local function deps_to_list(dependencies: Dependencies, tree: string | Tree): {Return}
219 local ret = {} 259 local ret: {Return} = {}
220 for _, dep in ipairs(dependencies or {}) do 260 for _, dep in ipairs(dependencies.queries or {}) do
221 table.insert(ret, { name = tostring(dep), label = installed_rock_label(dep, tree) }) 261 table.insert(ret, { name = tostring(dep), label = installed_rock_label(dep, tree) })
222 end 262 end
223 return ret 263 return ret
224end 264end
225 265
226local function indirect_deps(mdeps, rdeps, tree) 266local function indirect_deps(mdeps: {string: string}, rdeps: Dependencies, tree: string | Tree): {Return}
227 local ret = {} 267 local ret: {Return} = {}
228 local direct_deps = {} 268 local direct_deps = {}
229 for _, dep in ipairs(rdeps) do 269 for _, dep in ipairs(rdeps) do
230 direct_deps[dep] = true 270 direct_deps[dep] = true
@@ -237,7 +277,7 @@ local function indirect_deps(mdeps, rdeps, tree)
237 return ret 277 return ret
238end 278end
239 279
240local function show_rock(template, namespace, name, version, rockspec, repo, minfo, tree) 280local function show_rock(template: string, namespace: string, name: string, version: string, rockspec: Rockspec, repo: string | Tree, minfo: Entry, tree: string | Tree)
241 local desc = rockspec.description or {} 281 local desc = rockspec.description or {}
242 local data = { 282 local data = {
243 namespace = namespace, 283 namespace = namespace,
@@ -262,7 +302,7 @@ end
262 302
263--- Driver function for "show" command. 303--- Driver function for "show" command.
264-- @return boolean: True if succeeded, nil on errors. 304-- @return boolean: True if succeeded, nil on errors.
265function show.command(args) 305function show.command(args: Args): boolean, string
266 local query = queries.new(args.rock, args.namespace, args.version, true) 306 local query = queries.new(args.rock, args.namespace, args.version, true)
267 307
268 local name, version, repo, repo_url = search.pick_installed_rock(query, args.tree) 308 local name, version, repo, repo_url = search.pick_installed_rock(query, args.tree)
diff --git a/src/luarocks/cmd/test.tl b/src/luarocks/cmd/test.tl
index b353bd80..144cfdac 100644
--- a/src/luarocks/cmd/test.tl
+++ b/src/luarocks/cmd/test.tl
@@ -1,12 +1,19 @@
1 1
2--- Module implementing the LuaRocks "test" command. 2--- Module implementing the LuaRocks "test" command.
3-- Tests a rock, compiling its C parts if any. 3-- Tests a rock, compiling its C parts if any.
4local cmd_test = {} 4local record cmd_test
5end
5 6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local test = require("luarocks.test") 8local test = require("luarocks.test")
8 9
9function cmd_test.add_to_parser(parser) 10local argparse = require("luarocks.vendor.argparse")
11local type Parser = argparse.Parser
12
13local type a = require("luarocks.core.types.args")
14local type Args = a.Args
15
16function cmd_test.add_to_parser(parser: Parser)
10 local cmd = parser:command("test", [[ 17 local cmd = parser:command("test", [[
11Run the test suite for the Lua project in the current directory. 18Run the test suite for the Lua project in the current directory.
12 19
@@ -30,7 +37,7 @@ to separate LuaRocks arguments from test suite arguments.]],
30 :argname("<type>") 37 :argname("<type>")
31end 38end
32 39
33function cmd_test.command(args) 40function cmd_test.command(args: Args): boolean, string, string --!
34 if args.rockspec and args.rockspec:match("rockspec$") then 41 if args.rockspec and args.rockspec:match("rockspec$") then
35 return test.run_test_suite(args.rockspec, args.test_type, args.args, args.prepare) 42 return test.run_test_suite(args.rockspec, args.test_type, args.args, args.prepare)
36 end 43 end
diff --git a/src/luarocks/cmd/unpack.tl b/src/luarocks/cmd/unpack.tl
index a0ade4f3..07900039 100644
--- a/src/luarocks/cmd/unpack.tl
+++ b/src/luarocks/cmd/unpack.tl
@@ -1,7 +1,8 @@
1 1
2--- Module implementing the LuaRocks "unpack" command. 2--- Module implementing the LuaRocks "unpack" command.
3-- Unpack the contents of a rock. 3-- Unpack the contents of a rock.
4local unpack = {} 4local record unpack
5end
5 6
6local fetch = require("luarocks.fetch") 7local fetch = require("luarocks.fetch")
7local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
@@ -10,7 +11,16 @@ local build = require("luarocks.build")
10local dir = require("luarocks.dir") 11local dir = require("luarocks.dir")
11local search = require("luarocks.search") 12local search = require("luarocks.search")
12 13
13function unpack.add_to_parser(parser) 14local argparse = require("luarocks.vendor.argparse")
15local type Parser = argparse.Parser
16
17local type a = require("luarocks.core.types.args")
18local type Args = a.Args
19
20local type r = require("luarocks.core.types.rockspec")
21local type Rockspec = r.Rockspec
22
23function unpack.add_to_parser(parser: Parser)
14 local cmd = parser:command("unpack", [[ 24 local cmd = parser:command("unpack", [[
15Unpacks the contents of a rock in a newly created directory. 25Unpacks the contents of a rock in a newly created directory.
16Argument may be a rock file, or the name of a rock in a rocks server. 26Argument may be a rock file, or the name of a rock in a rocks server.
@@ -34,9 +44,7 @@ end
34-- @param dir_name string: The directory where to store and unpack files. 44-- @param dir_name string: The directory where to store and unpack files.
35-- @return table or (nil, string): the loaded rockspec table or 45-- @return table or (nil, string): the loaded rockspec table or
36-- nil and an error message. 46-- nil and an error message.
37local function unpack_rockspec(rockspec_file, dir_name) 47local function unpack_rockspec(rockspec_file: string, dir_name: string): Rockspec, string
38 assert(type(rockspec_file) == "string")
39 assert(type(dir_name) == "string")
40 48
41 local rockspec, err = fetch.load_rockspec(rockspec_file) 49 local rockspec, err = fetch.load_rockspec(rockspec_file)
42 if not rockspec then 50 if not rockspec then
@@ -44,8 +52,8 @@ local function unpack_rockspec(rockspec_file, dir_name)
44 end 52 end
45 local ok, err = fs.change_dir(dir_name) 53 local ok, err = fs.change_dir(dir_name)
46 if not ok then return nil, err end 54 if not ok then return nil, err end
47 local ok, sources_dir = fetch.fetch_sources(rockspec, true, ".") 55 local oks, sources_dir = fetch.fetch_sources(rockspec, true, ".")
48 if not ok then 56 if not oks then
49 return nil, sources_dir 57 return nil, sources_dir
50 end 58 end
51 ok, err = fs.change_dir(sources_dir) 59 ok, err = fs.change_dir(sources_dir)
@@ -63,16 +71,14 @@ end
63-- extension in the rock filename (eg. "src", "all", "linux-x86") 71-- extension in the rock filename (eg. "src", "all", "linux-x86")
64-- @return table or (nil, string): the loaded rockspec table or 72-- @return table or (nil, string): the loaded rockspec table or
65-- nil and an error message. 73-- nil and an error message.
66local function unpack_rock(rock_file, dir_name, kind) 74local function unpack_rock(rock_file: string, dir_name: string, kind: string): Rockspec, string, string
67 assert(type(rock_file) == "string")
68 assert(type(dir_name) == "string")
69 75
70 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name) 76 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name)
71 if not ok then 77 if not ok then
72 return nil, err, errcode 78 return nil, err, errcode
73 end 79 end
74 ok, err = fs.change_dir(dir_name) 80 local oks, errs = fs.change_dir(dir_name)
75 if not ok then return nil, err end 81 if not oks then return nil, errs end
76 local rockspec_file = dir_name..".rockspec" 82 local rockspec_file = dir_name..".rockspec"
77 local rockspec, err = fetch.load_rockspec(rockspec_file) 83 local rockspec, err = fetch.load_rockspec(rockspec_file)
78 if not rockspec then 84 if not rockspec then
@@ -80,13 +86,13 @@ local function unpack_rock(rock_file, dir_name, kind)
80 end 86 end
81 if kind == "src" then 87 if kind == "src" then
82 if rockspec.source.file then 88 if rockspec.source.file then
83 local ok, err = fs.unpack_archive(rockspec.source.file) 89 oks, err = fs.unpack_archive(rockspec.source.file)
84 if not ok then return nil, err end 90 if not ok then return nil, err end
85 ok, err = fetch.find_rockspec_source_dir(rockspec, ".") 91 oks, err = fetch.find_rockspec_source_dir(rockspec, ".")
86 if not ok then return nil, err end 92 if not ok then return nil, err end
87 ok, err = fs.change_dir(rockspec.source.dir) 93 oks, err = fs.change_dir(rockspec.source.dir)
88 if not ok then return nil, err end 94 if not ok then return nil, err end
89 ok, err = build.apply_patches(rockspec) 95 oks, err = build.apply_patches(rockspec)
90 fs.pop_dir() 96 fs.pop_dir()
91 if not ok then return nil, err end 97 if not ok then return nil, err end
92 end 98 end
@@ -100,8 +106,7 @@ end
100-- @param file string: A rockspec or .rock URL. 106-- @param file string: A rockspec or .rock URL.
101-- @return boolean or (nil, string): true if successful or nil followed 107-- @return boolean or (nil, string): true if successful or nil followed
102-- by an error message. 108-- by an error message.
103local function run_unpacker(file, force) 109local function run_unpacker(file: string, force: boolean): boolean, string
104 assert(type(file) == "string")
105 110
106 local base_name = dir.base_name(file) 111 local base_name = dir.base_name(file)
107 local dir_name, kind, extension = base_name:match("(.*)%.([^.]+)%.(rock)$") 112 local dir_name, kind, extension = base_name:match("(.*)%.([^.]+)%.(rock)$")
@@ -123,7 +128,7 @@ local function run_unpacker(file, force)
123 end 128 end
124 local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name)) 129 local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name))
125 130
126 local rockspec, err 131 local rockspec, err: Rockspec, string
127 if extension == "rock" then 132 if extension == "rock" then
128 rockspec, err = unpack_rock(file, dir_name, kind) 133 rockspec, err = unpack_rock(file, dir_name, kind)
129 elseif extension == "rockspec" then 134 elseif extension == "rockspec" then
@@ -152,8 +157,8 @@ end
152--- Driver function for the "unpack" command. 157--- Driver function for the "unpack" command.
153-- @return boolean or (nil, string): true if successful or nil followed 158-- @return boolean or (nil, string): true if successful or nil followed
154-- by an error message. 159-- by an error message.
155function unpack.command(args) 160function unpack.command(args: Args): boolean, string
156 local url, err 161 local url, err: string, string
157 if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then 162 if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then
158 url = args.rock 163 url = args.rock
159 else 164 else
diff --git a/src/luarocks/cmd/upload.tl b/src/luarocks/cmd/upload.tl
index 6b84e452..018d9f6e 100644
--- a/src/luarocks/cmd/upload.tl
+++ b/src/luarocks/cmd/upload.tl
@@ -1,5 +1,6 @@
1 1
2local upload = {} 2local record upload
3end
3 4
4local signing = require("luarocks.signing") 5local signing = require("luarocks.signing")
5local util = require("luarocks.util") 6local util = require("luarocks.util")
@@ -8,7 +9,39 @@ local pack = require("luarocks.pack")
8local cfg = require("luarocks.core.cfg") 9local cfg = require("luarocks.core.cfg")
9local Api = require("luarocks.upload.api") 10local Api = require("luarocks.upload.api")
10 11
11function upload.add_to_parser(parser) 12local argparse = require("luarocks.vendor.argparse")
13local type Parser = argparse.Parser
14local type Option = argparse.Option
15
16local type a = require("luarocks.core.types.args")
17local type Args = a.Args
18
19local type bo = require("luarocks.core.types.bopts")
20local type BOpts = bo.BOpts
21
22local type i = require("luarocks.core.types.installs")
23local type IOpts = i.IOpts
24
25local type p = require("luarocks.core.types.persist")
26local type PersistableTable = p.PersistableTable
27
28local type res = require("luarocks.core.types.result")
29local type Result = res.Result
30
31local type t = require("luarocks.core.types.tree")
32local type Tree = t.Tree
33
34local type q = require("luarocks.core.types.query")
35local type Query = q.Query
36
37local type r = require("luarocks.core.types.rockspec")
38local type Rockspec = r.Rockspec
39local type Dependencies = r.Dependencies
40
41local type m = require("luarocks.core.types.manifest")
42local type Entry = m.Manifest.Entry
43
44function upload.add_to_parser(parser: Parser)
12 local cmd = parser:command("upload", "Pack a source rock file (.src.rock extension) ".. 45 local cmd = parser:command("upload", "Pack a source rock file (.src.rock extension) "..
13 "and upload it and the rockspec to the public rocks repository.", util.see_also()) 46 "and upload it and the rockspec to the public rocks repository.", util.see_also())
14 :summary("Upload a rockspec to the public rocks repository.") 47 :summary("Upload a rockspec to the public rocks repository.")
@@ -31,12 +64,12 @@ function upload.add_to_parser(parser)
31 cmd:flag("--debug"):hidden(true) 64 cmd:flag("--debug"):hidden(true)
32end 65end
33 66
34local function is_dev_version(version) 67local function is_dev_version(version: string): string
35 return version:match("^dev") or version:match("^scm") 68 return version:match("^dev") or version:match("^scm")
36end 69end
37 70
38function upload.command(args) 71function upload.command(args: Args): boolean, string, string --!
39 local api, err = Api.new(args) 72 local api, err = Api.new(args as argparse.Args) --!
40 if not api then 73 if not api then
41 return nil, err 74 return nil, err
42 end 75 end
@@ -63,8 +96,8 @@ function upload.command(args)
63 return nil, "Revision "..rockspec.version.." already exists on the server. "..util.see_help("upload") 96 return nil, "Revision "..rockspec.version.." already exists on the server. "..util.see_help("upload")
64 end 97 end
65 98
66 local sigfname 99 local sigfname: string
67 local rock_sigfname 100 local rock_sigfname: string
68 101
69 if args.sign then 102 if args.sign then
70 sigfname, err = signing.sign_file(args.rockspec) 103 sigfname, err = signing.sign_file(args.rockspec)
@@ -74,7 +107,7 @@ function upload.command(args)
74 util.printout("Signed rockspec: "..sigfname) 107 util.printout("Signed rockspec: "..sigfname)
75 end 108 end
76 109
77 local rock_fname 110 local rock_fname: string
78 if args.src_rock then 111 if args.src_rock then
79 rock_fname = args.src_rock 112 rock_fname = args.src_rock
80 elseif not args.skip_pack and not is_dev_version(rockspec.version) then 113 elseif not args.skip_pack and not is_dev_version(rockspec.version) then
diff --git a/src/luarocks/cmd/which.tl b/src/luarocks/cmd/which.tl
index f50a43c3..7566e704 100644
--- a/src/luarocks/cmd/which.tl
+++ b/src/luarocks/cmd/which.tl
@@ -1,13 +1,20 @@
1 1
2--- @module luarocks.which_cmd 2--- @module luarocks.which_cmd
3-- Driver for the `luarocks which` command. 3-- Driver for the `luarocks which` command.
4local which_cmd = {} 4local record which_cmd
5end
5 6
6local loader = require("luarocks.loader") 7local loader = require("luarocks.loader") --!
7local cfg = require("luarocks.core.cfg") 8local cfg = require("luarocks.core.cfg")
8local util = require("luarocks.util") 9local util = require("luarocks.util")
9 10
10function which_cmd.add_to_parser(parser) 11local argparse = require("luarocks.vendor.argparse")
12local type Parser = argparse.Parser
13
14local type a = require("luarocks.core.types.args")
15local type Args = a.Args
16
17function which_cmd.add_to_parser(parser: Parser)
11 local cmd = parser:command("which", 'Given a module name like "foo.bar", '.. 18 local cmd = parser:command("which", 'Given a module name like "foo.bar", '..
12 "output which file would be loaded to resolve that module by ".. 19 "output which file would be loaded to resolve that module by "..
13 'luarocks.loader, like "/usr/local/lua/'..cfg.lua_version..'/foo/bar.lua".', 20 'luarocks.loader, like "/usr/local/lua/'..cfg.lua_version..'/foo/bar.lua".',
@@ -19,7 +26,7 @@ end
19 26
20--- Driver function for "which" command. 27--- Driver function for "which" command.
21-- @return boolean This function terminates the interpreter. 28-- @return boolean This function terminates the interpreter.
22function which_cmd.command(args) 29function which_cmd.command(args: Args): boolean, string
23 local pathname, rock_name, rock_version, where = loader.which(args.modname, "lp") 30 local pathname, rock_name, rock_version, where = loader.which(args.modname, "lp")
24 31
25 if pathname then 32 if pathname then
diff --git a/src/luarocks/cmd/write_rockspec.tl b/src/luarocks/cmd/write_rockspec.tl
index e8d65cba..ebd3b783 100644
--- a/src/luarocks/cmd/write_rockspec.tl
+++ b/src/luarocks/cmd/write_rockspec.tl
@@ -88,7 +88,7 @@ rockspec, and is not guaranteed to be complete or correct. ]], util.see_also())
88 cmd:argument("location", "URL or path to the rock sources.") 88 cmd:argument("location", "URL or path to the rock sources.")
89 :args("?") 89 :args("?")
90 90
91 write_rockspec.cmd_options(cmd) --! 91 write_rockspec.cmd_options(cmd as Parser)
92end 92end
93 93
94local function open_file(name: string): FILE, string, integer 94local function open_file(name: string): FILE, string, integer
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl
index 7dea5b32..03eedd6d 100644
--- a/src/luarocks/core/cfg.d.tl
+++ b/src/luarocks/core/cfg.d.tl
@@ -107,6 +107,9 @@ local record cfg
107 project_tree: string 107 project_tree: string
108 -- cmd make 108 -- cmd make
109 keep_other_versions: boolean 109 keep_other_versions: boolean
110 -- cmd path
111 package_paths: function(string | Tree): string, string, string
112 export_path_separator: string
110end 113end
111 114
112return cfg \ No newline at end of file 115return cfg \ No newline at end of file
diff --git a/src/luarocks/core/types/args.d.tl b/src/luarocks/core/types/args.d.tl
index a4f240cc..d2c49ea6 100644
--- a/src/luarocks/core/types/args.d.tl
+++ b/src/luarocks/core/types/args.d.tl
@@ -67,6 +67,36 @@ local record args
67 no_wrapper_scripts: boolean 67 no_wrapper_scripts: boolean
68 wrapper_dir: string 68 wrapper_dir: string
69 reset: boolean 69 reset: boolean
70 filter: string
71 outdated: boolean
72 new_version: string
73 dir: string
74 new_url: string
75 lr_path: string
76 lr_cpath: string
77 lr_bin: string
78 full: boolean
79 append: boolean
80 no_bin: boolean
81 old_versions: boolean
82 binary: boolean
83 rock_tree: boolean
84 rock_namespace: boolean
85 rock_dir: boolean
86 rock_license: boolean
87 issues: boolean
88 labels: boolean
89 modules: boolean
90 deps: boolean
91 build_deps: boolean
92 test_deps: boolean
93 mversion: boolean
94 test_type: string
95 args: {string}
96 prepare: boolean
97 src_rock: string
98 skip_pack: boolean
99 modname: string
70 end 100 end
71end 101end
72 102
diff --git a/src/luarocks/core/types/rockspec.tl b/src/luarocks/core/types/rockspec.tl
index f1e4895d..cfb35be2 100644
--- a/src/luarocks/core/types/rockspec.tl
+++ b/src/luarocks/core/types/rockspec.tl
@@ -12,7 +12,7 @@ local record rockspec
12 issues_url: string 12 issues_url: string
13 maintainer: string 13 maintainer: string
14 license: string 14 license: string
15 labels: any --! 15 labels: {string}
16 end 16 end
17 17
18 record Source 18 record Source
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl
index a0fca017..5d4fa79e 100644
--- a/src/luarocks/fs.d.tl
+++ b/src/luarocks/fs.d.tl
@@ -82,6 +82,7 @@ local record fs
82 quiet_stderr: function(string): string 82 quiet_stderr: function(string): string
83 -- cmd innit 83 -- cmd innit
84 wrap_script: function(string, string, string, ...:string): boolean, string 84 wrap_script: function(string, string, string, ...:string): boolean, string
85 export_cmd: function(string, string): string
85end 86end
86 87
87return fs 88return fs
diff --git a/src/luarocks/upload/multipart.tl b/src/luarocks/upload/multipart.tl
index 28787da2..c42a286c 100644
--- a/src/luarocks/upload/multipart.tl
+++ b/src/luarocks/upload/multipart.tl
@@ -104,7 +104,7 @@ function multipart.encode(params: Parameters): string, string --! Table map type
104 "\r\n", "--", boundary, "--", "\r\n" }), boundary 104 "\r\n", "--", boundary, "--", "\r\n" }), boundary
105end 105end
106 106
107function multipart.new_file(fname: string, mime: string): File 107function multipart.new_file(fname: string, mime?: string): File
108 local self: File = {} 108 local self: File = {}
109 109
110 setmetatable(self, { __index = File }) 110 setmetatable(self, { __index = File })
diff --git a/src/luarocks/util.tl b/src/luarocks/util.tl
index 53e363a5..c03751e6 100644
--- a/src/luarocks/util.tl
+++ b/src/luarocks/util.tl
@@ -13,7 +13,7 @@ local type SortBy = o.SortBy
13 13
14local record util 14local record util
15 cleanup_path: function(string, string, string, boolean): string 15 cleanup_path: function(string, string, string, boolean): string
16 split_string: function(string, string, number): {string} 16 split_string: function(string, string, ?number): {string}
17 sortedpairs: function<K, V>(tbl: {K: V}, sort_by?: SortBy): function(): K, V, Ordering<K> 17 sortedpairs: function<K, V>(tbl: {K: V}, sort_by?: SortBy): function(): K, V, Ordering<K>
18 deep_merge: function({any : any}, {any : any}) 18 deep_merge: function({any : any}, {any : any})
19 deep_merge_under: function({any : any}, {any : any}) 19 deep_merge_under: function({any : any}, {any : any})