diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-17 01:32:49 +0300 |
|---|---|---|
| committer | V1K1NGbg <victor@ilchev.com> | 2024-08-17 01:32:49 +0300 |
| commit | 463a73f6f150275d1df10e7d1e466504e911bd30 (patch) | |
| tree | 1ddbe88f2c68e929a033857023308bd8e6469ccf /src | |
| parent | 16bfc8919d06595c63103760a63a57df950a42eb (diff) | |
| download | luarocks-463a73f6f150275d1df10e7d1e466504e911bd30.tar.gz luarocks-463a73f6f150275d1df10e7d1e466504e911bd30.tar.bz2 luarocks-463a73f6f150275d1df10e7d1e466504e911bd30.zip | |
cmd
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd.tl | 164 | ||||
| -rw-r--r-- | src/luarocks/core/cfg.d.tl | 19 | ||||
| -rw-r--r-- | src/luarocks/core/types/args.d.tl | 27 | ||||
| -rw-r--r-- | src/luarocks/deps.tl | 6 | ||||
| -rw-r--r-- | src/luarocks/fs.d.tl | 6 | ||||
| -rw-r--r-- | src/luarocks/fun.tl | 23 | ||||
| -rw-r--r-- | src/luarocks/util.tl | 6 | ||||
| -rw-r--r-- | src/luarocks/vendor/argparse.d.tl | 18 |
8 files changed, 169 insertions, 100 deletions
diff --git a/src/luarocks/cmd.tl b/src/luarocks/cmd.tl index 93fa85dc..b9490e66 100644 --- a/src/luarocks/cmd.tl +++ b/src/luarocks/cmd.tl | |||
| @@ -1,17 +1,15 @@ | |||
| 1 | 1 | ||
| 2 | --- Functions for command-line scripts. | 2 | --- Functions for command-line scripts. |
| 3 | local record cmd | 3 | local record cmd |
| 4 | record Args | ||
| 5 | tree: string | ||
| 6 | global: boolean | ||
| 7 | deps_mode: string | ||
| 8 | ["local"]: boolean --! | ||
| 9 | project_tree: string | ||
| 10 | server: string | ||
| 11 | dev: boolean | ||
| 12 | only_server: string --! | ||
| 13 | end | ||
| 14 | errorcodes: {string: integer} | 4 | errorcodes: {string: integer} |
| 5 | |||
| 6 | record Module | ||
| 7 | add_to_parser: function(Parser) | ||
| 8 | command: function(Args): boolean, string | ||
| 9 | needs_lock: function(Args): boolean | ||
| 10 | help: string | ||
| 11 | help_summary: string | ||
| 12 | end | ||
| 15 | end | 13 | end |
| 16 | 14 | ||
| 17 | local manif = require("luarocks.manif") | 15 | local manif = require("luarocks.manif") |
| @@ -27,7 +25,17 @@ local argparse = require("luarocks.vendor.argparse") | |||
| 27 | local type t = require("luarocks.core.types.tree") | 25 | local type t = require("luarocks.core.types.tree") |
| 28 | local type Tree = t.Tree | 26 | local type Tree = t.Tree |
| 29 | 27 | ||
| 30 | local type Args = cmd.Args | 28 | local type Parser = argparse.Parser |
| 29 | |||
| 30 | local type a = require("luarocks.core.types.args") | ||
| 31 | local type Args = a.Args | ||
| 32 | |||
| 33 | local type Module = cmd.Module | ||
| 34 | |||
| 35 | local type p = require("luarocks.core.types.persist") | ||
| 36 | local type PersistableTable = p.PersistableTable | ||
| 37 | |||
| 38 | local type Config = cfg | ||
| 31 | 39 | ||
| 32 | -- local pack = table.pack or function(...) return { n = select("#", ...), ... } end | 40 | -- local pack = table.pack or function(...) return { n = select("#", ...), ... } end |
| 33 | 41 | ||
| @@ -202,7 +210,7 @@ end | |||
| 202 | --- Display an error message and exit. | 210 | --- Display an error message and exit. |
| 203 | -- @param message string: The error message. | 211 | -- @param message string: The error message. |
| 204 | -- @param exitcode number: the exitcode to use | 212 | -- @param exitcode number: the exitcode to use |
| 205 | local function die(message: string, exitcode: number) | 213 | local function die(message: string, exitcode?: integer) |
| 206 | assert(type(message) == "string", "bad error, expected string, got: " .. type(message)) --! | 214 | assert(type(message) == "string", "bad error, expected string, got: " .. type(message)) --! |
| 207 | assert(exitcode == nil or type(exitcode) == "number", "bad error, expected number, got: " .. type(exitcode) .. " - " .. tostring(exitcode)) | 215 | assert(exitcode == nil or type(exitcode) == "number", "bad error, expected number, got: " .. type(exitcode) .. " - " .. tostring(exitcode)) |
| 208 | util.printerr("\nError: "..message) | 216 | util.printerr("\nError: "..message) |
| @@ -216,7 +224,7 @@ local function die(message: string, exitcode: number) | |||
| 216 | os.exit(exitcode or cmd.errorcodes.UNSPECIFIED) | 224 | os.exit(exitcode or cmd.errorcodes.UNSPECIFIED) |
| 217 | end | 225 | end |
| 218 | 226 | ||
| 219 | local function search_lua(lua_version, verbose, search_at) | 227 | local function search_lua(lua_version: string, verbose?: string, search_at?: string): {string : string}, string |
| 220 | if search_at then | 228 | if search_at then |
| 221 | return util.find_lua(search_at, lua_version, verbose) | 229 | return util.find_lua(search_at, lua_version, verbose) |
| 222 | end | 230 | end |
| @@ -238,11 +246,11 @@ local function search_lua(lua_version, verbose, search_at) | |||
| 238 | (verbose and " Tried:\n" .. table.concat(all_tried, "\n") or "") | 246 | (verbose and " Tried:\n" .. table.concat(all_tried, "\n") or "") |
| 239 | end | 247 | end |
| 240 | 248 | ||
| 241 | local init_config | 249 | local init_config: function(Args): boolean, string |
| 242 | do | 250 | do |
| 243 | local detect_config_via_args | 251 | local detect_config_via_args: function(Args): {string : string} |
| 244 | do | 252 | do |
| 245 | local function find_project_dir(project_tree) | 253 | local function find_project_dir(project_tree: string): string, boolean |
| 246 | if project_tree then | 254 | if project_tree then |
| 247 | return project_tree:gsub("[/\\][^/\\]+$", ""), true | 255 | return project_tree:gsub("[/\\][^/\\]+$", ""), true |
| 248 | else | 256 | else |
| @@ -259,12 +267,12 @@ do | |||
| 259 | return nil | 267 | return nil |
| 260 | end | 268 | end |
| 261 | 269 | ||
| 262 | local function find_default_lua_version(args, project_dir) | 270 | local function find_default_lua_version(args: Args, project_dir: string): string |
| 263 | if hardcoded.FORCE_CONFIG then | 271 | if hardcoded.FORCE_CONFIG then |
| 264 | return nil | 272 | return nil |
| 265 | end | 273 | end |
| 266 | 274 | ||
| 267 | local dirs = {} | 275 | local dirs: {string} = {} |
| 268 | if project_dir then | 276 | if project_dir then |
| 269 | table.insert(dirs, dir.path(project_dir, ".luarocks")) | 277 | table.insert(dirs, dir.path(project_dir, ".luarocks")) |
| 270 | end | 278 | end |
| @@ -274,10 +282,10 @@ do | |||
| 274 | table.insert(dirs, cfg.sysconfdir) | 282 | table.insert(dirs, cfg.sysconfdir) |
| 275 | for _, d in ipairs(dirs) do | 283 | for _, d in ipairs(dirs) do |
| 276 | local f = dir.path(d, "default-lua-version.lua") | 284 | local f = dir.path(d, "default-lua-version.lua") |
| 277 | local mod, err = loadfile(f, "t") | 285 | local mod, _ = loadfile(f, "t") |
| 278 | if mod then | 286 | if mod then |
| 279 | local pok, ver = pcall(mod) | 287 | local pok, ver = pcall(mod) |
| 280 | if pok and type(ver) == "string" and ver:match("%d+.%d+") then | 288 | if pok and ver is string and ver:match("%d+.%d+") then |
| 281 | if args.verbose then | 289 | if args.verbose then |
| 282 | util.printout("Defaulting to Lua " .. ver .. " based on " .. f .. " ...") | 290 | util.printout("Defaulting to Lua " .. ver .. " based on " .. f .. " ...") |
| 283 | end | 291 | end |
| @@ -288,15 +296,15 @@ do | |||
| 288 | return nil | 296 | return nil |
| 289 | end | 297 | end |
| 290 | 298 | ||
| 291 | local function find_version_from_config(dirname) | 299 | local function find_version_from_config(dirname: string): string |
| 292 | return fun.find(util.lua_versions("descending"), function(v) | 300 | return fun.find(util.lua_versions("descending"), function(v: string): string |
| 293 | if util.exists(dir.path(dirname, ".luarocks", "config-"..v..".lua")) then | 301 | if util.exists(dir.path(dirname, ".luarocks", "config-"..v..".lua")) then |
| 294 | return v | 302 | return v |
| 295 | end | 303 | end |
| 296 | end) | 304 | end) |
| 297 | end | 305 | end |
| 298 | 306 | ||
| 299 | local function detect_lua_via_args(args, project_dir) | 307 | local function detect_lua_via_args(args: Args, project_dir: string): {string : string} |
| 300 | local lua_version = args.lua_version | 308 | local lua_version = args.lua_version |
| 301 | or find_default_lua_version(args, project_dir) | 309 | or find_default_lua_version(args, project_dir) |
| 302 | or (project_dir and find_version_from_config(project_dir)) | 310 | or (project_dir and find_version_from_config(project_dir)) |
| @@ -325,8 +333,8 @@ do | |||
| 325 | return {} | 333 | return {} |
| 326 | end | 334 | end |
| 327 | 335 | ||
| 328 | detect_config_via_args = function(args) | 336 | detect_config_via_args = function(args: Args): {string : string} |
| 329 | local project_dir, given | 337 | local project_dir, given: string, boolean |
| 330 | if not args.no_project then | 338 | if not args.no_project then |
| 331 | project_dir, given = find_project_dir(args.project_tree) | 339 | project_dir, given = find_project_dir(args.project_tree) |
| 332 | end | 340 | end |
| @@ -346,7 +354,7 @@ do | |||
| 346 | end | 354 | end |
| 347 | end | 355 | end |
| 348 | 356 | ||
| 349 | init_config = function(args) | 357 | init_config = function(args: Args): boolean, string |
| 350 | local detected = detect_config_via_args(args) | 358 | local detected = detect_config_via_args(args) |
| 351 | 359 | ||
| 352 | local ok, err = cfg.init(detected, util.warning) | 360 | local ok, err = cfg.init(detected, util.warning) |
| @@ -369,11 +377,11 @@ local lua_example = package.config:sub(1, 1) == "\\" | |||
| 369 | and "<d:\\path\\lua.exe>" | 377 | and "<d:\\path\\lua.exe>" |
| 370 | or "</path/lua>" | 378 | or "</path/lua>" |
| 371 | 379 | ||
| 372 | local function show_status(file, status, err) | 380 | local function show_status(file: string, status: boolean, err?: string): string |
| 373 | return (file and file .. " " or "") .. (status and "(ok)" or ("(" .. (err or "not found") ..")")) | 381 | return (file and file .. " " or "") .. (status and "(ok)" or ("(" .. (err or "not found") ..")")) |
| 374 | end | 382 | end |
| 375 | 383 | ||
| 376 | local function use_to_fix_location(key, what) | 384 | local function use_to_fix_location(key: string, what?: string): string |
| 377 | local buf = " ****************************************\n" | 385 | local buf = " ****************************************\n" |
| 378 | buf = buf .. " Use the command\n\n" | 386 | buf = buf .. " Use the command\n\n" |
| 379 | buf = buf .. " luarocks config " .. key .. " " .. (what or "<dir>") .. "\n\n" | 387 | buf = buf .. " luarocks config " .. key .. " " .. (what or "<dir>") .. "\n\n" |
| @@ -382,7 +390,7 @@ local function use_to_fix_location(key, what) | |||
| 382 | return buf | 390 | return buf |
| 383 | end | 391 | end |
| 384 | 392 | ||
| 385 | local function get_config_text(cfg) -- luacheck: ignore 431 | 393 | local function get_config_text(cfg: Config): string -- luacheck: ignore 431 |
| 386 | local deps = require("luarocks.deps") | 394 | local deps = require("luarocks.deps") |
| 387 | 395 | ||
| 388 | local libdir_ok = deps.check_lua_libdir(cfg.variables) | 396 | local libdir_ok = deps.check_lua_libdir(cfg.variables) |
| @@ -421,7 +429,7 @@ local function get_config_text(cfg) -- luacheck: ignore 431 | |||
| 421 | end | 429 | end |
| 422 | buf = buf.."\n Rocks trees in use: \n" | 430 | buf = buf.."\n Rocks trees in use: \n" |
| 423 | for _, tree in ipairs(cfg.rocks_trees) do | 431 | for _, tree in ipairs(cfg.rocks_trees) do |
| 424 | if type(tree) == "string" then | 432 | if tree is string then |
| 425 | buf = buf.." "..fs.absolute_name(tree) | 433 | buf = buf.." "..fs.absolute_name(tree) |
| 426 | else | 434 | else |
| 427 | local name = tree.name and " (\""..tree.name.."\")" or "" | 435 | local name = tree.name and " (\""..tree.name.."\")" or "" |
| @@ -433,7 +441,7 @@ local function get_config_text(cfg) -- luacheck: ignore 431 | |||
| 433 | return buf | 441 | return buf |
| 434 | end | 442 | end |
| 435 | 443 | ||
| 436 | local function get_parser(description, cmd_modules) | 444 | local function get_parser(description: string, cmd_modules: {string: Module}): Parser |
| 437 | local basename = dir.base_name(program) | 445 | local basename = dir.base_name(program) |
| 438 | local parser = argparse( | 446 | local parser = argparse( |
| 439 | basename, "LuaRocks "..cfg.program_version..", the Lua package manager\n\n".. | 447 | basename, "LuaRocks "..cfg.program_version..", the Lua package manager\n\n".. |
| @@ -500,7 +508,7 @@ Enabling completion for Fish: | |||
| 500 | :argname("<prefix>") | 508 | :argname("<prefix>") |
| 501 | parser:option("--lua-version", "Which Lua version to use.") | 509 | parser:option("--lua-version", "Which Lua version to use.") |
| 502 | :argname("<ver>") | 510 | :argname("<ver>") |
| 503 | :convert(function(s) return (s:match("^%d+%.%d+$")) end) | 511 | :convert(function(s: string): string return (s:match("^%d+%.%d+$")) end) |
| 504 | parser:option("--tree", "Which tree to operate on.") | 512 | parser:option("--tree", "Which tree to operate on.") |
| 505 | :hidden_name("--to") | 513 | :hidden_name("--to") |
| 506 | parser:flag("--local", "Use the tree in the user's home directory.\n".. | 514 | parser:flag("--local", "Use the tree in the user's home directory.\n".. |
| @@ -526,7 +534,7 @@ Enabling completion for Fish: | |||
| 526 | return parser | 534 | return parser |
| 527 | end | 535 | end |
| 528 | 536 | ||
| 529 | local function get_first_arg() | 537 | local function get_first_arg(): string |
| 530 | if not arg then | 538 | if not arg then |
| 531 | return | 539 | return |
| 532 | end | 540 | end |
| @@ -547,7 +555,7 @@ end | |||
| 547 | -- @param commands table: contains the loaded modules representing commands. | 555 | -- @param commands table: contains the loaded modules representing commands. |
| 548 | -- @param external_namespace string: where to look for external commands. | 556 | -- @param external_namespace string: where to look for external commands. |
| 549 | -- @param ... string: Arguments given on the command-line. | 557 | -- @param ... string: Arguments given on the command-line. |
| 550 | function cmd.run_command(description, commands, external_namespace, ...) | 558 | function cmd.run_command(description: string, commands: {string: string}, external_namespace: string, ...: string) |
| 551 | 559 | ||
| 552 | check_popen() | 560 | check_popen() |
| 553 | 561 | ||
| @@ -562,14 +570,14 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 562 | end | 570 | end |
| 563 | end | 571 | end |
| 564 | 572 | ||
| 565 | local cmd_modules = {} | 573 | local cmd_modules: {string: Module} = {} |
| 566 | for name, module in pairs(commands) do | 574 | for name, module in pairs(commands) do |
| 567 | local pok, mod = pcall(require, module) | 575 | local pok, mod = pcall(require, module) as (boolean, Module) |
| 568 | if pok and type(mod) == "table" then | 576 | if pok and mod is Module then |
| 569 | local original_command = mod.command | 577 | local original_command = mod.command |
| 570 | if original_command then | 578 | if original_command then |
| 571 | if not mod.add_to_parser then | 579 | if not mod.add_to_parser then |
| 572 | mod.add_to_parser = function(parser) | 580 | mod.add_to_parser = function(parser: Parser) |
| 573 | parser:command(name, mod.help, util.see_also()) | 581 | parser:command(name, mod.help, util.see_also()) |
| 574 | :summary(mod.help_summary) | 582 | :summary(mod.help_summary) |
| 575 | :handle_options(false) | 583 | :handle_options(false) |
| @@ -577,8 +585,8 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 577 | :args("*") | 585 | :args("*") |
| 578 | end | 586 | end |
| 579 | 587 | ||
| 580 | mod.command = function(args) | 588 | mod.command = function(args: Args): boolean, string |
| 581 | return original_command(args, unpack(args.input)) | 589 | return original_command(args, table.unpack(args.input)) |
| 582 | end | 590 | end |
| 583 | end | 591 | end |
| 584 | cmd_modules[name] = mod | 592 | cmd_modules[name] = mod |
| @@ -590,9 +598,9 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 590 | end | 598 | end |
| 591 | end | 599 | end |
| 592 | 600 | ||
| 593 | local function process_cmdline_vars(...) | 601 | local function process_cmdline_vars(...: string): table.PackTable<string>, {string : string} |
| 594 | local args = pack(...) | 602 | local args = table.pack(...) |
| 595 | local cmdline_vars = {} | 603 | local cmdline_vars: {string: string} = {} |
| 596 | local last = args.n | 604 | local last = args.n |
| 597 | for i = 1, args.n do | 605 | for i = 1, args.n do |
| 598 | if args[i] == "--" then | 606 | if args[i] == "--" then |
| @@ -618,27 +626,27 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 618 | 626 | ||
| 619 | local args, cmdline_vars = process_cmdline_vars(...) | 627 | local args, cmdline_vars = process_cmdline_vars(...) |
| 620 | local parser = get_parser(description, cmd_modules) | 628 | local parser = get_parser(description, cmd_modules) |
| 621 | args = parser:parse(args) | 629 | local argsp: Args = parser:parse(args) as Args --! |
| 622 | 630 | ||
| 623 | -- Compatibility for old flag | 631 | -- Compatibility for old flag |
| 624 | if args.nodeps then | 632 | if argsp.nodeps then |
| 625 | args.deps_mode = "none" | 633 | argsp.deps_mode = "none" |
| 626 | end | 634 | end |
| 627 | 635 | ||
| 628 | if args.timeout then -- setting it in the config file will kick-in earlier in the process | 636 | if argsp.timeout then -- setting it in the config file will kick-in earlier in the process |
| 629 | cfg.connection_timeout = args.timeout | 637 | cfg.connection_timeout = argsp.timeout |
| 630 | end | 638 | end |
| 631 | 639 | ||
| 632 | if args.command == "config" then | 640 | if argsp.command == "config" then |
| 633 | if args.key == "lua_version" and args.value then | 641 | if argsp.key == "lua_version" and argsp.value then |
| 634 | args.lua_version = args.value | 642 | argsp.lua_version = argsp.value |
| 635 | elseif args.key == "lua_dir" and args.value then | 643 | elseif argsp.key == "lua_dir" and argsp.value then |
| 636 | args.lua_dir = args.value | 644 | argsp.lua_dir = argsp.value |
| 637 | end | 645 | end |
| 638 | end | 646 | end |
| 639 | 647 | ||
| 640 | ----------------------------------------------------------------------------- | 648 | ----------------------------------------------------------------------------- |
| 641 | local lua_found, err = init_config(args) | 649 | local lua_found, err = init_config(argsp) |
| 642 | if err then | 650 | if err then |
| 643 | die(err) | 651 | die(err) |
| 644 | end | 652 | end |
| @@ -650,16 +658,16 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 650 | 658 | ||
| 651 | -- if the Lua interpreter wasn't explicitly found before cfg.init, | 659 | -- if the Lua interpreter wasn't explicitly found before cfg.init, |
| 652 | -- try again now. | 660 | -- try again now. |
| 653 | local tried | 661 | local tried: string |
| 654 | if not lua_found then | 662 | if not lua_found then |
| 655 | local detected | 663 | local detected: {string : string} |
| 656 | detected, tried = search_lua(cfg.lua_version, args.verbose, cfg.variables.LUA_DIR) | 664 | detected, tried = search_lua(cfg.lua_version, argsp.verbose, cfg.variables.LUA_DIR) |
| 657 | if detected then | 665 | if detected then |
| 658 | lua_found = true | 666 | lua_found = true |
| 659 | cfg.variables.LUA = detected.lua | 667 | cfg.variables.LUA = detected.lua |
| 660 | cfg.variables.LUA_DIR = detected.lua_dir | 668 | cfg.variables.LUA_DIR = detected.lua_dir |
| 661 | cfg.variables.LUA_BINDIR = detected.lua_bindir | 669 | cfg.variables.LUA_BINDIR = detected.lua_bindir |
| 662 | if args.lua_dir then | 670 | if argsp.lua_dir then |
| 663 | cfg.variables.LUA_INCDIR = nil | 671 | cfg.variables.LUA_INCDIR = nil |
| 664 | cfg.variables.LUA_LIBDIR = nil | 672 | cfg.variables.LUA_LIBDIR = nil |
| 665 | end | 673 | end |
| @@ -701,12 +709,12 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 701 | cfg.project_dir = fs.absolute_name(cfg.project_dir) | 709 | cfg.project_dir = fs.absolute_name(cfg.project_dir) |
| 702 | end | 710 | end |
| 703 | 711 | ||
| 704 | if args.verbose then | 712 | if argsp.verbose then |
| 705 | cfg.verbose = true | 713 | cfg.verbose = true |
| 706 | print(("-"):rep(79)) | 714 | print(("-"):rep(79)) |
| 707 | print("Current configuration:") | 715 | print("Current configuration:") |
| 708 | print(("-"):rep(79)) | 716 | print(("-"):rep(79)) |
| 709 | print(config.to_string(cfg)) | 717 | print(config.to_string(cfg as PersistableTable)) |
| 710 | print(("-"):rep(79)) | 718 | print(("-"):rep(79)) |
| 711 | fs.verbose() | 719 | fs.verbose() |
| 712 | end | 720 | end |
| @@ -715,18 +723,18 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 715 | die("Current directory does not exist. Please run LuaRocks from an existing directory.") | 723 | die("Current directory does not exist. Please run LuaRocks from an existing directory.") |
| 716 | end | 724 | end |
| 717 | 725 | ||
| 718 | local ok, err = process_tree_args(args, cfg.project_dir) | 726 | local ok, err = process_tree_args(argsp, cfg.project_dir) |
| 719 | if not ok then | 727 | if not ok then |
| 720 | die(err) | 728 | die(err) |
| 721 | end | 729 | end |
| 722 | 730 | ||
| 723 | ok, err = process_server_args(args) | 731 | ok, err = process_server_args(argsp) |
| 724 | if not ok then | 732 | if not ok then |
| 725 | die(err) | 733 | die(err) |
| 726 | end | 734 | end |
| 727 | 735 | ||
| 728 | if args.only_sources then | 736 | if argsp.only_sources then |
| 729 | cfg.only_sources_from = args.only_sources | 737 | cfg.only_sources_from = argsp.only_sources |
| 730 | end | 738 | end |
| 731 | 739 | ||
| 732 | for k, v in pairs(cmdline_vars) do | 740 | for k, v in pairs(cmdline_vars) do |
| @@ -738,11 +746,11 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 738 | cfg.local_cache = dir.path(fs.system_cache_dir(), "luarocks") | 746 | cfg.local_cache = dir.path(fs.system_cache_dir(), "luarocks") |
| 739 | end | 747 | end |
| 740 | 748 | ||
| 741 | if args.no_manifest then | 749 | if argsp.no_manifest then |
| 742 | cfg.no_manifest = true | 750 | cfg.no_manifest = true |
| 743 | end | 751 | end |
| 744 | 752 | ||
| 745 | if not args.command then | 753 | if not argsp.command then |
| 746 | parser:epilog(variables_help..get_config_text(cfg)) | 754 | parser:epilog(variables_help..get_config_text(cfg)) |
| 747 | util.printout() | 755 | util.printout() |
| 748 | util.printout(parser:get_help()) | 756 | util.printout(parser:get_help()) |
| @@ -750,43 +758,43 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 750 | os.exit(cmd.errorcodes.OK) | 758 | os.exit(cmd.errorcodes.OK) |
| 751 | end | 759 | end |
| 752 | 760 | ||
| 753 | if not cfg.variables["LUA"] and args.command ~= "config" and args.command ~= "help" then | 761 | if not cfg.variables["LUA"] and argsp.command ~= "config" and argsp.command ~= "help" then |
| 754 | local flag = (not cfg.project_tree) | 762 | local flag = (not cfg.project_tree) |
| 755 | and "--local " | 763 | and "--local " |
| 756 | or "" | 764 | or "" |
| 757 | if args.lua_version then | 765 | if argsp.lua_version then |
| 758 | flag = "--lua-version=" .. args.lua_version .. " " .. flag | 766 | flag = "--lua-version=" .. argsp.lua_version .. " " .. flag |
| 759 | end | 767 | end |
| 760 | die((tried or "Lua interpreter not found.") .. | 768 | die((tried or "Lua interpreter not found.") .. |
| 761 | "\nPlease set your Lua interpreter with:\n\n" .. | 769 | "\nPlease set your Lua interpreter with:\n\n" .. |
| 762 | " luarocks " .. flag.. "config variables.LUA " .. lua_example .. "\n") | 770 | " luarocks " .. flag.. "config variables.LUA " .. lua_example .. "\n") |
| 763 | end | 771 | end |
| 764 | 772 | ||
| 765 | local cmd_mod = cmd_modules[args.command] | 773 | local cmd_mod = cmd_modules[argsp.command] |
| 766 | 774 | ||
| 767 | local lock | 775 | local lock: fs.Lock |
| 768 | if cmd_mod.needs_lock and cmd_mod.needs_lock(args) then | 776 | if cmd_mod.needs_lock and cmd_mod.needs_lock(argsp) then |
| 769 | local ok, err = fs.check_command_permissions(args) | 777 | local ok, err = fs.check_command_permissions(argsp) |
| 770 | if not ok then | 778 | if not ok then |
| 771 | die(err, cmd.errorcodes.PERMISSIONDENIED) | 779 | die(err, cmd.errorcodes.PERMISSIONDENIED) |
| 772 | end | 780 | end |
| 773 | 781 | ||
| 774 | lock, err = fs.lock_access(path.root_dir(cfg.root_dir), args.force_lock) | 782 | lock, err = fs.lock_access(path.root_dir(cfg.root_dir), argsp.force_lock) |
| 775 | if not lock then | 783 | if not lock then |
| 776 | err = args.force_lock | 784 | err = argsp.force_lock |
| 777 | and ("failed to force the lock" .. (err and ": " .. err or "")) | 785 | and ("failed to force the lock" .. (err and ": " .. err or "")) |
| 778 | or (err and err ~= "File exists") | 786 | or (err and err ~= "File exists") |
| 779 | and err | 787 | and err |
| 780 | or "try --force-lock to overwrite the lock" | 788 | or "try --force-lock to overwrite the lock" |
| 781 | 789 | ||
| 782 | die("command '" .. args.command .. "' " .. | 790 | die("command '" .. argsp.command .. "' " .. |
| 783 | "requires exclusive write access to " .. path.root_dir(cfg.root_dir) .. " - " .. | 791 | "requires exclusive write access to " .. path.root_dir(cfg.root_dir) .. " - " .. |
| 784 | err, cmd.errorcodes.LOCK) | 792 | err, cmd.errorcodes.LOCK) |
| 785 | end | 793 | end |
| 786 | end | 794 | end |
| 787 | 795 | ||
| 788 | local call_ok, ok, err, exitcode = xpcall(function() | 796 | local call_ok, ok, err, exitcode = xpcall(function(): boolean, string |
| 789 | return cmd_mod.command(args) | 797 | return cmd_mod.command(argsp) |
| 790 | end, error_handler) | 798 | end, error_handler) |
| 791 | 799 | ||
| 792 | if lock then | 800 | if lock then |
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl index 5903a49f..cbe53663 100644 --- a/src/luarocks/core/cfg.d.tl +++ b/src/luarocks/core/cfg.d.tl | |||
| @@ -39,8 +39,17 @@ local record cfg | |||
| 39 | arch: string | 39 | arch: string |
| 40 | -- api | 40 | -- api |
| 41 | record config_files | 41 | record config_files |
| 42 | record system | ||
| 43 | file: string | ||
| 44 | found: boolean | ||
| 45 | end | ||
| 42 | record user | 46 | record user |
| 43 | file: string | 47 | file: string |
| 48 | found: boolean | ||
| 49 | end | ||
| 50 | record project | ||
| 51 | file: string | ||
| 52 | found: boolean | ||
| 44 | end | 53 | end |
| 45 | end | 54 | end |
| 46 | -- type_check | 55 | -- type_check |
| @@ -55,8 +64,7 @@ local record cfg | |||
| 55 | api_version: string | 64 | api_version: string |
| 56 | end | 65 | end |
| 57 | -- loader | 66 | -- loader |
| 58 | init: function(): boolean, string, string | 67 | init: function(?{string : string}, ?function(string)): boolean, string, string |
| 59 | init_package_paths: function | ||
| 60 | -- rockspecs | 68 | -- rockspecs |
| 61 | each_platform: function(?string): (function():string) | 69 | each_platform: function(?string): (function():string) |
| 62 | -- fetch | 70 | -- fetch |
| @@ -94,6 +102,13 @@ local record cfg | |||
| 94 | fs_use_modules: boolean | 102 | fs_use_modules: boolean |
| 95 | is_binary: boolean | 103 | is_binary: boolean |
| 96 | program_version: string | 104 | program_version: string |
| 105 | homeconfdir: string | ||
| 106 | sysconfdir: string | ||
| 107 | luajit_version: string | ||
| 108 | lua_found: boolean | ||
| 109 | project_dir: string | ||
| 110 | verbose: boolean | ||
| 111 | project_tree: string | ||
| 97 | end | 112 | end |
| 98 | 113 | ||
| 99 | return cfg \ No newline at end of file | 114 | return 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 new file mode 100644 index 00000000..45bcd5e9 --- /dev/null +++ b/src/luarocks/core/types/args.d.tl | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | local record args | ||
| 2 | record Args | ||
| 3 | tree: string | ||
| 4 | global: boolean | ||
| 5 | deps_mode: string | ||
| 6 | ["local"]: boolean --! | ||
| 7 | project_tree: string | ||
| 8 | server: string | ||
| 9 | dev: boolean | ||
| 10 | only_server: string --! | ||
| 11 | verbose: string | ||
| 12 | lua_version: string | ||
| 13 | lua_dir: string | ||
| 14 | no_project: boolean | ||
| 15 | input: {string} | ||
| 16 | nodeps: boolean | ||
| 17 | timeout: number --! | ||
| 18 | command: string | ||
| 19 | key: string | ||
| 20 | value: string | ||
| 21 | only_sources: string | ||
| 22 | no_manifest: boolean | ||
| 23 | force_lock: string | ||
| 24 | end | ||
| 25 | end | ||
| 26 | |||
| 27 | return args \ No newline at end of file | ||
diff --git a/src/luarocks/deps.tl b/src/luarocks/deps.tl index 30ff8e53..69c739ca 100644 --- a/src/luarocks/deps.tl +++ b/src/luarocks/deps.tl | |||
| @@ -713,7 +713,7 @@ function deps.scan_deps(results: {string: string}, mdeps: {string: {string: {Que | |||
| 713 | end | 713 | end |
| 714 | end | 714 | end |
| 715 | 715 | ||
| 716 | local function lua_h_exists(d: string, luaver: string): string, string, string, integer | 716 | local function lua_h_exists(d: string, luaver: string): boolean, string, string, integer |
| 717 | local major, minor = luaver:match("(%d+)%.(%d+)") | 717 | local major, minor = luaver:match("(%d+)%.(%d+)") |
| 718 | local luanum = ("%s%02d"):format(major, tonumber(minor)) | 718 | local luanum = ("%s%02d"):format(major, tonumber(minor)) |
| 719 | 719 | ||
| @@ -723,7 +723,7 @@ local function lua_h_exists(d: string, luaver: string): string, string, string, | |||
| 723 | local data = fd:read("*a") | 723 | local data = fd:read("*a") |
| 724 | fd:close() | 724 | fd:close() |
| 725 | if data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then | 725 | if data:match("LUA_VERSION_NUM%s*" .. tostring(luanum)) then |
| 726 | return d | 726 | return d ~= nil |
| 727 | end | 727 | end |
| 728 | return nil, "Lua header lua.h found at " .. d .. " does not match Lua version " .. luaver .. ". You can use `luarocks config variables.LUA_INCDIR <path>` to set the correct location.", "dependency", 2 | 728 | return nil, "Lua header lua.h found at " .. d .. " does not match Lua version " .. luaver .. ". You can use `luarocks config variables.LUA_INCDIR <path>` to set the correct location.", "dependency", 2 |
| 729 | end | 729 | end |
| @@ -760,7 +760,7 @@ local function find_lua_incdir(prefix: string, luaver: string, luajitver: string | |||
| 760 | return nil, mainerr | 760 | return nil, mainerr |
| 761 | end | 761 | end |
| 762 | 762 | ||
| 763 | function deps.check_lua_incdir(vars: {string: string}): boolean | string, string, string | 763 | function deps.check_lua_incdir(vars: {string: string}): boolean, string, string |
| 764 | if vars.LUA_INCDIR_OK == "ok" | 764 | if vars.LUA_INCDIR_OK == "ok" |
| 765 | then return true | 765 | then return true |
| 766 | end | 766 | end |
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl index 93555b08..f3ff6eb2 100644 --- a/src/luarocks/fs.d.tl +++ b/src/luarocks/fs.d.tl | |||
| @@ -1,3 +1,6 @@ | |||
| 1 | local type a = require("luarocks.core.types.args") | ||
| 2 | local type Args = a.Args | ||
| 3 | |||
| 1 | local record fs | 4 | local record fs |
| 2 | verbose: function(): FILE | boolean, string, integer | 5 | verbose: function(): FILE | boolean, string, integer |
| 3 | load_fns: function(fs_table: FsTable, inits: {any:any}): function | 6 | load_fns: function(fs_table: FsTable, inits: {any:any}): function |
| @@ -69,6 +72,9 @@ local record fs | |||
| 69 | zip: function(string, ...:string): boolean, string | 72 | zip: function(string, ...:string): boolean, string |
| 70 | -- cmd | 73 | -- cmd |
| 71 | is_superuser: function(): boolean | 74 | is_superuser: function(): boolean |
| 75 | modules: function(string): {string} | ||
| 76 | system_cache_dir: function(): string | ||
| 77 | check_command_permissions: function(Args): boolean, string | ||
| 72 | end | 78 | end |
| 73 | 79 | ||
| 74 | return fs | 80 | return fs |
diff --git a/src/luarocks/fun.tl b/src/luarocks/fun.tl index 5d581af5..984b028a 100644 --- a/src/luarocks/fun.tl +++ b/src/luarocks/fun.tl | |||
| @@ -65,24 +65,25 @@ function fun.flip<K, V, S>(f: function(K, V): S): function(V, K): S | |||
| 65 | end | 65 | end |
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | function fun.find(xs: function | {any}, f: function): any | 68 | function fun.find<X, R>(xs: function():(X) | {X} , f: function(X):(R) ): R |
| 69 | if xs is function then | 69 | if xs is {X} then |
| 70 | for v in xs do | 70 | for _, x in ipairs(xs) do |
| 71 | local x = f(v) | 71 | local r = f(x) |
| 72 | if x then | 72 | if r then |
| 73 | return x | 73 | return r |
| 74 | end | 74 | end |
| 75 | end | 75 | end |
| 76 | elseif xs is {any} then | 76 | else |
| 77 | for _, v in ipairs(xs) do | 77 | for x in xs do |
| 78 | local x = f(v) | 78 | local r = f(x) |
| 79 | if x then | 79 | if r then |
| 80 | return x | 80 | return r |
| 81 | end | 81 | end |
| 82 | end | 82 | end |
| 83 | end | 83 | end |
| 84 | end | 84 | end |
| 85 | 85 | ||
| 86 | |||
| 86 | function fun.partial<K>(f: (function(...: any): K), ...: any): (function(...: any): K) | 87 | function fun.partial<K>(f: (function(...: any): K), ...: any): (function(...: any): K) |
| 87 | local n = select("#", ...) | 88 | local n = select("#", ...) |
| 88 | if n == 1 then | 89 | if n == 1 then |
diff --git a/src/luarocks/util.tl b/src/luarocks/util.tl index 5e22e840..27a9c117 100644 --- a/src/luarocks/util.tl +++ b/src/luarocks/util.tl | |||
| @@ -89,7 +89,7 @@ end | |||
| 89 | -- corresponding cleanup functions. Calling this function will run | 89 | -- corresponding cleanup functions. Calling this function will run |
| 90 | -- these function, erasing temporaries. | 90 | -- these function, erasing temporaries. |
| 91 | -- Functions are executed in the inverse order they were scheduled. | 91 | -- Functions are executed in the inverse order they were scheduled. |
| 92 | function util.run_scheduled_functions() | 92 | function util.run_scheduled_functions(): string --! a hack for xpcall |
| 93 | local fs = require("luarocks.fs") | 93 | local fs = require("luarocks.fs") |
| 94 | if fs.change_dir_to_root then | 94 | if fs.change_dir_to_root then |
| 95 | fs.change_dir_to_root() | 95 | fs.change_dir_to_root() |
| @@ -262,7 +262,7 @@ function util.see_help(command: string, program: string): string | |||
| 262 | return "See '"..util.this_program(program or "luarocks")..' help'..(command and " "..command or "").."'." | 262 | return "See '"..util.this_program(program or "luarocks")..' help'..(command and " "..command or "").."'." |
| 263 | end | 263 | end |
| 264 | 264 | ||
| 265 | function util.see_also(text: string): string | 265 | function util.see_also(text?: string): string |
| 266 | local see_also = "See also:\n" | 266 | local see_also = "See also:\n" |
| 267 | if text then | 267 | if text then |
| 268 | see_also = see_also..text.."\n" | 268 | see_also = see_also..text.."\n" |
| @@ -536,7 +536,7 @@ do | |||
| 536 | end | 536 | end |
| 537 | end | 537 | end |
| 538 | 538 | ||
| 539 | function util.find_lua(prefix: string, luaver: string, verbose: string): {string: string}, string | 539 | function util.find_lua(prefix: string, luaver: string, verbose?: string): {string: string}, string |
| 540 | local lua, bindir: string, string | 540 | local lua, bindir: string, string |
| 541 | lua, bindir, luaver = find_lua_bindir(prefix, luaver, verbose) | 541 | lua, bindir, luaver = find_lua_bindir(prefix, luaver, verbose) |
| 542 | if not lua then | 542 | if not lua then |
diff --git a/src/luarocks/vendor/argparse.d.tl b/src/luarocks/vendor/argparse.d.tl index 1d125176..42e35787 100644 --- a/src/luarocks/vendor/argparse.d.tl +++ b/src/luarocks/vendor/argparse.d.tl | |||
| @@ -20,8 +20,8 @@ local record argparse | |||
| 20 | get_usage: function(self: Parser): string | 20 | get_usage: function(self: Parser): string |
| 21 | get_help: function(self: Parser): string | 21 | get_help: function(self: Parser): string |
| 22 | 22 | ||
| 23 | option: function(self: Parser, name: string, description: string, default: string, convert: function | {function}, args: {string}, count: integer | string): Option | 23 | option: function(self: Parser, name: string, description?: string, default?: string, convert?: function | {function}, args?: {string}, count?: integer | string): Option |
| 24 | option: function(self: Parser, name: string, description: string, default: string, convert: {string:string}, args: {string}, count: integer | string): Option | 24 | option: function(self: Parser, name: string, description?: string, default?: string, convert?: {string:string}, args?: {string}, count?: integer | string): Option |
| 25 | 25 | ||
| 26 | require_command: function(self: Parser, require_command: boolean): Parser | 26 | require_command: function(self: Parser, require_command: boolean): Parser |
| 27 | command_target: function(self: Parser, command_target: string): Parser | 27 | command_target: function(self: Parser, command_target: string): Parser |
| @@ -30,6 +30,10 @@ local record argparse | |||
| 30 | 30 | ||
| 31 | add_help: function(self: Parser, boolean) | 31 | add_help: function(self: Parser, boolean) |
| 32 | 32 | ||
| 33 | help_max_width: function(self: Parser, number): Parser | ||
| 34 | add_help_command: function(self: Parser, ?string | {string: any}): Parser | ||
| 35 | add_complete_command: function(self: Parser, ?string | {string: any}): Parser | ||
| 36 | |||
| 33 | -- TODO: should be Argument | Option | 37 | -- TODO: should be Argument | Option |
| 34 | mutex: function(self: Parser, ...: any) | 38 | mutex: function(self: Parser, ...: any) |
| 35 | 39 | ||
| @@ -74,17 +78,25 @@ local record argparse | |||
| 74 | args: function(self: Option, args: string|integer): Option | 78 | args: function(self: Option, args: string|integer): Option |
| 75 | 79 | ||
| 76 | action: function(self: Option, cb: ActionCallback) | 80 | action: function(self: Option, cb: ActionCallback) |
| 81 | |||
| 82 | hidden_name: function(self: Option, string) | ||
| 83 | |||
| 84 | hidden: function(self: Option, boolean) | ||
| 85 | |||
| 86 | convert: function(self: Option, function) | ||
| 77 | end | 87 | end |
| 78 | 88 | ||
| 79 | record Command | 89 | record Command |
| 80 | summary: function(self: Command, summary: string): Command | 90 | summary: function(self: Command, summary: string): Command |
| 81 | description: function(self: Command, description: string): Command | 91 | description: function(self: Command, description: string): Command |
| 82 | 92 | ||
| 83 | argument: function(self: Command, name: string, description: string): Argument | 93 | argument: function(self: Command, name: string, description?: string): Argument |
| 84 | 94 | ||
| 85 | option: function(self: Command, name: string, description: string): Option | 95 | option: function(self: Command, name: string, description: string): Option |
| 86 | 96 | ||
| 87 | flag: function(self: Command, string, string): Option | 97 | flag: function(self: Command, string, string): Option |
| 98 | |||
| 99 | handle_options: function(self: Command, boolean): Command | ||
| 88 | end | 100 | end |
| 89 | 101 | ||
| 90 | metamethod __call: function(self: argparse, name: string, description: string, epilog: string): Parser | 102 | metamethod __call: function(self: argparse, name: string, description: string, epilog: string): Parser |
