From 55e67af4ef25d83432a8ccdb40baea10137f9e59 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Thu, 22 Aug 2024 17:49:00 -0300 Subject: Teal: convert luarocks.cmd.which --- src/luarocks/cmd/which.lua | 40 ---------------------------------------- src/luarocks/cmd/which.tl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 40 deletions(-) delete mode 100644 src/luarocks/cmd/which.lua create mode 100644 src/luarocks/cmd/which.tl diff --git a/src/luarocks/cmd/which.lua b/src/luarocks/cmd/which.lua deleted file mode 100644 index f50a43c3..00000000 --- a/src/luarocks/cmd/which.lua +++ /dev/null @@ -1,40 +0,0 @@ - ---- @module luarocks.which_cmd --- Driver for the `luarocks which` command. -local which_cmd = {} - -local loader = require("luarocks.loader") -local cfg = require("luarocks.core.cfg") -local util = require("luarocks.util") - -function which_cmd.add_to_parser(parser) - local cmd = parser:command("which", 'Given a module name like "foo.bar", '.. - "output which file would be loaded to resolve that module by ".. - 'luarocks.loader, like "/usr/local/lua/'..cfg.lua_version..'/foo/bar.lua".', - util.see_also()) - :summary("Tell which file corresponds to a given module name.") - - cmd:argument("modname", "Module name.") -end - ---- Driver function for "which" command. --- @return boolean This function terminates the interpreter. -function which_cmd.command(args) - local pathname, rock_name, rock_version, where = loader.which(args.modname, "lp") - - if pathname then - util.printout(pathname) - if where == "l" then - util.printout("(provided by " .. tostring(rock_name) .. " " .. tostring(rock_version) .. ")") - else - local key = rock_name - util.printout("(found directly via package." .. key.. " -- not installed as a rock?)") - end - return true - end - - return nil, "Module '" .. args.modname .. "' not found." -end - -return which_cmd - diff --git a/src/luarocks/cmd/which.tl b/src/luarocks/cmd/which.tl new file mode 100644 index 00000000..85a798ac --- /dev/null +++ b/src/luarocks/cmd/which.tl @@ -0,0 +1,45 @@ + +--- @module luarocks.which_cmd +-- Driver for the `luarocks which` command. +local record which_cmd +end + +local loader = require("luarocks.loader") +local cfg = require("luarocks.core.cfg") +local util = require("luarocks.util") + +local type Parser = require("luarocks.vendor.argparse").Parser + +local type Args = require("luarocks.core.types.args").Args + +function which_cmd.add_to_parser(parser: Parser) + local cmd = parser:command("which", 'Given a module name like "foo.bar", '.. + "output which file would be loaded to resolve that module by ".. + 'luarocks.loader, like "/usr/local/lua/'..cfg.lua_version..'/foo/bar.lua".', + util.see_also()) + :summary("Tell which file corresponds to a given module name.") + + cmd:argument("modname", "Module name.") +end + +--- Driver function for "which" command. +-- @return boolean This function terminates the interpreter. +function which_cmd.command(args: Args): boolean, string + local pathname, rock_name, rock_version, where = loader.which(args.modname, "lp") + + if pathname then + util.printout(pathname) + if where == "l" then + util.printout("(provided by " .. tostring(rock_name) .. " " .. tostring(rock_version) .. ")") + else + local key = rock_name + util.printout("(found directly via package." .. key.. " -- not installed as a rock?)") + end + return true + end + + return nil, "Module '" .. args.modname .. "' not found." +end + +return which_cmd + -- cgit v1.2.3-55-g6feb