diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:01 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | 5498380268820f17167a0f1aa0c4795d05afe59b (patch) | |
| tree | f9464139dd629cc3b4106e895369eeb47c76fa91 /src | |
| parent | 46c2b559e9eff1a3a553844bbf450e5214d6f5a6 (diff) | |
| download | luarocks-5498380268820f17167a0f1aa0c4795d05afe59b.tar.gz luarocks-5498380268820f17167a0f1aa0c4795d05afe59b.tar.bz2 luarocks-5498380268820f17167a0f1aa0c4795d05afe59b.zip | |
Teal: convert luarocks.cmd.doc
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/doc.tl (renamed from src/luarocks/cmd/doc.lua) | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/luarocks/cmd/doc.lua b/src/luarocks/cmd/doc.tl index a3117007..37eb2518 100644 --- a/src/luarocks/cmd/doc.lua +++ b/src/luarocks/cmd/doc.tl | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | 1 | ||
| 2 | --- Module implementing the LuaRocks "doc" command. | 2 | --- Module implementing the LuaRocks "doc" command. |
| 3 | -- Shows documentation for an installed rock. | 3 | -- Shows documentation for an installed rock. |
| 4 | local doc = {} | 4 | local record doc |
| 5 | end | ||
| 5 | 6 | ||
| 6 | local util = require("luarocks.util") | 7 | local util = require("luarocks.util") |
| 7 | local queries = require("luarocks.queries") | 8 | local queries = require("luarocks.queries") |
| @@ -12,7 +13,11 @@ local fetch = require("luarocks.fetch") | |||
| 12 | local fs = require("luarocks.fs") | 13 | local fs = require("luarocks.fs") |
| 13 | local download = require("luarocks.download") | 14 | local download = require("luarocks.download") |
| 14 | 15 | ||
| 15 | function doc.add_to_parser(parser) | 16 | local type Parser = require("luarocks.vendor.argparse").Parser |
| 17 | |||
| 18 | local type Args = require("luarocks.core.types.args").Args | ||
| 19 | |||
| 20 | function doc.add_to_parser(parser: Parser) | ||
| 16 | local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n".. | 21 | local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n".. |
| 17 | "Without any flags, tries to load the documentation using a series of heuristics.\n".. | 22 | "Without any flags, tries to load the documentation using a series of heuristics.\n".. |
| 18 | "With flags, return only the desired information.", util.see_also([[ | 23 | "With flags, return only the desired information.", util.see_also([[ |
| @@ -30,7 +35,7 @@ function doc.add_to_parser(parser) | |||
| 30 | cmd:flag("--porcelain", "Produce machine-friendly output.") | 35 | cmd:flag("--porcelain", "Produce machine-friendly output.") |
| 31 | end | 36 | end |
| 32 | 37 | ||
| 33 | local function show_homepage(homepage, name, namespace, version) | 38 | local function show_homepage(homepage: string, name: string, namespace: string, version: string): boolean, string |
| 34 | if not homepage then | 39 | if not homepage then |
| 35 | return nil, "No 'homepage' field in rockspec for "..util.format_rock_name(name, namespace, version) | 40 | return nil, "No 'homepage' field in rockspec for "..util.format_rock_name(name, namespace, version) |
| 36 | end | 41 | end |
| @@ -39,7 +44,7 @@ local function show_homepage(homepage, name, namespace, version) | |||
| 39 | return true | 44 | return true |
| 40 | end | 45 | end |
| 41 | 46 | ||
| 42 | local function try_to_open_homepage(name, namespace, version) | 47 | local function try_to_open_homepage(name: string, namespace: string, version: string): boolean, string |
| 43 | local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or "")) | 48 | local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or "")) |
| 44 | if not temp_dir then | 49 | if not temp_dir then |
| 45 | return nil, "Failed creating temporary directory: "..err | 50 | return nil, "Failed creating temporary directory: "..err |
| @@ -47,7 +52,7 @@ local function try_to_open_homepage(name, namespace, version) | |||
| 47 | util.schedule_function(fs.delete, temp_dir) | 52 | util.schedule_function(fs.delete, temp_dir) |
| 48 | local ok, err = fs.change_dir(temp_dir) | 53 | local ok, err = fs.change_dir(temp_dir) |
| 49 | if not ok then return nil, err end | 54 | if not ok then return nil, err end |
| 50 | local filename, err = download.download("rockspec", name, namespace, version) | 55 | local filename, err = download.download_file("rockspec", name, namespace, version) |
| 51 | if not filename then return nil, err end | 56 | if not filename then return nil, err end |
| 52 | local rockspec, err = fetch.load_local_rockspec(filename) | 57 | local rockspec, err = fetch.load_local_rockspec(filename) |
| 53 | if not rockspec then return nil, err end | 58 | if not rockspec then return nil, err end |
| @@ -58,7 +63,7 @@ end | |||
| 58 | 63 | ||
| 59 | --- Driver function for "doc" command. | 64 | --- Driver function for "doc" command. |
| 60 | -- @return boolean: True if succeeded, nil on errors. | 65 | -- @return boolean: True if succeeded, nil on errors. |
| 61 | function doc.command(args) | 66 | function doc.command(args: Args): boolean, string |
| 62 | local query = queries.new(args.rock, args.namespace, args.version) | 67 | local query = queries.new(args.rock, args.namespace, args.version) |
| 63 | local iname, iversion, repo = search.pick_installed_rock(query, args.tree) | 68 | local iname, iversion, repo = search.pick_installed_rock(query, args.tree) |
| 64 | if not iname then | 69 | if not iname then |
| @@ -78,7 +83,7 @@ function doc.command(args) | |||
| 78 | 83 | ||
| 79 | local directory = path.install_dir(name, version, repo) | 84 | local directory = path.install_dir(name, version, repo) |
| 80 | 85 | ||
| 81 | local docdir | 86 | local docdir: string |
| 82 | local directories = { "doc", "docs" } | 87 | local directories = { "doc", "docs" } |
| 83 | for _, d in ipairs(directories) do | 88 | for _, d in ipairs(directories) do |
| 84 | local dirname = dir.path(directory, d) | 89 | local dirname = dir.path(directory, d) |
| @@ -124,7 +129,7 @@ function doc.command(args) | |||
| 124 | for _, extension in ipairs(extensions) do | 129 | for _, extension in ipairs(extensions) do |
| 125 | for _, basename in ipairs(basenames) do | 130 | for _, basename in ipairs(basenames) do |
| 126 | local filename = basename..extension | 131 | local filename = basename..extension |
| 127 | local found | 132 | local found: string |
| 128 | for _, file in ipairs(files) do | 133 | for _, file in ipairs(files) do |
| 129 | if file:lower():match(filename) and ((not found) or #file < #found) then | 134 | if file:lower():match(filename) and ((not found) or #file < #found) then |
| 130 | found = file | 135 | found = file |
