diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:08 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | 352a9c50ccb8c6e190031d5f9db47e028d408cfd (patch) | |
| tree | 2987245180d613f2fc6a0a96507aeb8b1b2e611d /src | |
| parent | 7e45dee34c7683cbe7f7bc7e940aec29c513ed33 (diff) | |
| download | luarocks-352a9c50ccb8c6e190031d5f9db47e028d408cfd.tar.gz luarocks-352a9c50ccb8c6e190031d5f9db47e028d408cfd.tar.bz2 luarocks-352a9c50ccb8c6e190031d5f9db47e028d408cfd.zip | |
Teal: convert luarocks.admin.cmd.add
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/admin/cmd/add.tl (renamed from src/luarocks/admin/cmd/add.lua) | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/luarocks/admin/cmd/add.lua b/src/luarocks/admin/cmd/add.tl index aa444c50..e544be96 100644 --- a/src/luarocks/admin/cmd/add.lua +++ b/src/luarocks/admin/cmd/add.tl | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | 1 | ||
| 2 | --- Module implementing the luarocks-admin "add" command. | 2 | --- Module implementing the luarocks-admin "add" command. |
| 3 | -- Adds a rock or rockspec to a rocks server. | 3 | -- Adds a rock or rockspec to a rocks server. |
| 4 | local add = {} | 4 | local record add |
| 5 | end | ||
| 5 | 6 | ||
| 6 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
| 7 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| @@ -11,10 +12,14 @@ local fs = require("luarocks.fs") | |||
| 11 | local cache = require("luarocks.admin.cache") | 12 | local cache = require("luarocks.admin.cache") |
| 12 | local index = require("luarocks.admin.index") | 13 | local index = require("luarocks.admin.index") |
| 13 | 14 | ||
| 14 | function add.add_to_parser(parser) | 15 | local type Parser = require("luarocks.vendor.argparse").Parser |
| 16 | |||
| 17 | local type Args = require("luarocks.core.types.args").Args | ||
| 18 | |||
| 19 | function add.add_to_parser(parser: Parser) | ||
| 15 | local cmd = parser:command("add", "Add a rock or rockspec to a rocks server.", util.see_also()) | 20 | local cmd = parser:command("add", "Add a rock or rockspec to a rocks server.", util.see_also()) |
| 16 | 21 | ||
| 17 | cmd:argument("rock", "A local rockspec or rock file.") | 22 | cmd:argument("rocks", "A local rockspec or rock file.") |
| 18 | :args("+") | 23 | :args("+") |
| 19 | 24 | ||
| 20 | cmd:option("--server", "The server to use. If not given, the default server ".. | 25 | cmd:option("--server", "The server to use. If not given, the default server ".. |
| @@ -35,11 +40,7 @@ local function zip_manifests() | |||
| 35 | end | 40 | end |
| 36 | end | 41 | end |
| 37 | 42 | ||
| 38 | local function add_files_to_server(refresh, rockfiles, server, upload_server, do_index) | 43 | local function add_files_to_server(refresh: boolean, rockfiles: {string}, server: string, upload_server: {string: string}, do_index: boolean): boolean, string, string |
| 39 | assert(type(refresh) == "boolean" or not refresh) | ||
| 40 | assert(type(rockfiles) == "table") | ||
| 41 | assert(type(server) == "string") | ||
| 42 | assert(type(upload_server) == "table" or not upload_server) | ||
| 43 | 44 | ||
| 44 | local download_url, login_url = cache.get_server_urls(server, upload_server) | 45 | local download_url, login_url = cache.get_server_urls(server, upload_server) |
| 45 | local at = fs.current_dir() | 46 | local at = fs.current_dir() |
| @@ -107,7 +108,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server, do | |||
| 107 | 108 | ||
| 108 | -- TODO abstract away explicit 'curl' call | 109 | -- TODO abstract away explicit 'curl' call |
| 109 | 110 | ||
| 110 | local cmd | 111 | local cmd: string |
| 111 | if protocol == "rsync" then | 112 | if protocol == "rsync" then |
| 112 | local srv, path = server_path:match("([^/]+)(/.+)") | 113 | local srv, path = server_path:match("([^/]+)(/.+)") |
| 113 | cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" | 114 | cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" |
| @@ -124,10 +125,10 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server, do | |||
| 124 | return fs.execute(cmd) | 125 | return fs.execute(cmd) |
| 125 | end | 126 | end |
| 126 | 127 | ||
| 127 | function add.command(args) | 128 | function add.command(args: Args): boolean, string, string --! |
| 128 | local server, server_table = cache.get_upload_server(args.add_server or args.server) | 129 | local server, server_table, err = cache.get_upload_server(args.add_server or args.server) |
| 129 | if not server then return nil, server_table end | 130 | if not server then return nil, err end |
| 130 | return add_files_to_server(not args.no_refresh, args.rock, server, server_table, args.index) | 131 | return add_files_to_server(not args.no_refresh, args.rocks, server, server_table, args.index) |
| 131 | end | 132 | end |
| 132 | 133 | ||
| 133 | 134 | ||
