diff options
| author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:04 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
| commit | aa1c4422e919c67bd89faeefc855237e60393600 (patch) | |
| tree | 55c19827a463f326e8490009fffe80aa40b187b6 /src | |
| parent | aca7d0ad0bab3064fcb4598167e2fcd944242d76 (diff) | |
| download | luarocks-aa1c4422e919c67bd89faeefc855237e60393600.tar.gz luarocks-aa1c4422e919c67bd89faeefc855237e60393600.tar.bz2 luarocks-aa1c4422e919c67bd89faeefc855237e60393600.zip | |
Teal: convert luarocks.cmd.init
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd/init.tl (renamed from src/luarocks/cmd/init.lua) | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.tl index b5359c96..fcd49422 100644 --- a/src/luarocks/cmd/init.lua +++ b/src/luarocks/cmd/init.tl | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | 1 | ||
| 2 | local init = {} | 2 | local record init |
| 3 | needs_lock: function(Args): boolean | ||
| 4 | end | ||
| 3 | 5 | ||
| 4 | local cfg = require("luarocks.core.cfg") | 6 | local cfg = require("luarocks.core.cfg") |
| 5 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
| @@ -10,7 +12,16 @@ local util = require("luarocks.util") | |||
| 10 | local persist = require("luarocks.persist") | 12 | local persist = require("luarocks.persist") |
| 11 | local write_rockspec = require("luarocks.cmd.write_rockspec") | 13 | local write_rockspec = require("luarocks.cmd.write_rockspec") |
| 12 | 14 | ||
| 13 | function init.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 | |||
| 20 | local type PersistableTable = require("luarocks.core.types.persist").PersistableTable | ||
| 21 | |||
| 22 | local type Tree = require("luarocks.core.types.tree").Tree | ||
| 23 | |||
| 24 | function init.add_to_parser(parser: Parser) | ||
| 14 | local cmd = parser:command("init", "Initialize a directory for a Lua project using LuaRocks.", util.see_also()) | 25 | local cmd = parser:command("init", "Initialize a directory for a Lua project using LuaRocks.", util.see_also()) |
| 15 | 26 | ||
| 16 | cmd:argument("name", "The project name.") | 27 | cmd:argument("name", "The project name.") |
| @@ -23,10 +34,10 @@ function init.add_to_parser(parser) | |||
| 23 | cmd:flag("--no-wrapper-scripts", "Do not generate wrapper ./lua and ./luarocks launcher scripts.") | 34 | cmd:flag("--no-wrapper-scripts", "Do not generate wrapper ./lua and ./luarocks launcher scripts.") |
| 24 | cmd:flag("--no-gitignore", "Do not generate a .gitignore file.") | 35 | cmd:flag("--no-gitignore", "Do not generate a .gitignore file.") |
| 25 | 36 | ||
| 26 | cmd:group("Options for specifying rockspec data", write_rockspec.cmd_options(cmd)) | 37 | cmd:group("Options for specifying rockspec data", write_rockspec.cmd_options(cmd as Parser)) |
| 27 | end | 38 | end |
| 28 | 39 | ||
| 29 | local function gitignore_path(pwd, wrapper_dir, filename) | 40 | local function gitignore_path(pwd: string, wrapper_dir: string, filename: string): string |
| 30 | local norm_cur = fs.absolute_name(pwd) | 41 | local norm_cur = fs.absolute_name(pwd) |
| 31 | local norm_file = fs.absolute_name(dir.path(wrapper_dir, filename)) | 42 | local norm_file = fs.absolute_name(dir.path(wrapper_dir, filename)) |
| 32 | if norm_file:sub(1, #norm_cur) == norm_cur then | 43 | if norm_file:sub(1, #norm_cur) == norm_cur then |
| @@ -36,7 +47,7 @@ local function gitignore_path(pwd, wrapper_dir, filename) | |||
| 36 | end | 47 | end |
| 37 | end | 48 | end |
| 38 | 49 | ||
| 39 | local function write_gitignore(entries) | 50 | local function write_gitignore(entries: {string}) |
| 40 | local gitignore = "" | 51 | local gitignore = "" |
| 41 | local fd = io.open(".gitignore", "r") | 52 | local fd = io.open(".gitignore", "r") |
| 42 | if fd then | 53 | if fd then |
| @@ -57,23 +68,23 @@ local function write_gitignore(entries) | |||
| 57 | end | 68 | end |
| 58 | end | 69 | end |
| 59 | 70 | ||
| 60 | local function inject_tree(tree) | 71 | local function inject_tree(tree: string | Tree) |
| 61 | path.use_tree(tree) | 72 | path.use_tree(tree) |
| 62 | local tree_set = false | 73 | local tree_set = false |
| 63 | for _, t in ipairs(cfg.rocks_trees) do | 74 | for _, t in ipairs(cfg.rocks_trees) do |
| 64 | if type(t) == "table" then | 75 | if t is Tree then |
| 65 | if t.name == "project" then | 76 | if t.name == "project" then |
| 66 | t.root = tree | 77 | t.root = tree as string |
| 67 | tree_set = true | 78 | tree_set = true |
| 68 | end | 79 | end |
| 69 | end | 80 | end |
| 70 | end | 81 | end |
| 71 | if not tree_set then | 82 | if not tree_set then |
| 72 | table.insert(cfg.rocks_trees, 1, { name = "project", root = tree }) | 83 | table.insert(cfg.rocks_trees, 1, { name = "project", root = tree } as Tree) |
| 73 | end | 84 | end |
| 74 | end | 85 | end |
| 75 | 86 | ||
| 76 | local function write_wrapper_scripts(wrapper_dir, luarocks_wrapper, lua_wrapper) | 87 | local function write_wrapper_scripts(wrapper_dir: string, luarocks_wrapper: string, lua_wrapper: string) |
| 77 | local tree = dir.path(fs.current_dir(), "lua_modules") | 88 | local tree = dir.path(fs.current_dir(), "lua_modules") |
| 78 | 89 | ||
| 79 | fs.make_dir(wrapper_dir) | 90 | fs.make_dir(wrapper_dir) |
| @@ -111,7 +122,7 @@ end | |||
| 111 | 122 | ||
| 112 | --- Driver function for "init" command. | 123 | --- Driver function for "init" command. |
| 113 | -- @return boolean: True if succeeded, nil on errors. | 124 | -- @return boolean: True if succeeded, nil on errors. |
| 114 | function init.command(args) | 125 | function init.command(args: Args): boolean, string |
| 115 | local do_gitignore = not args.no_gitignore | 126 | local do_gitignore = not args.no_gitignore |
| 116 | local do_wrapper_scripts = not args.no_wrapper_scripts | 127 | local do_wrapper_scripts = not args.no_wrapper_scripts |
| 117 | local wrapper_dir = args.wrapper_dir or "." | 128 | local wrapper_dir = args.wrapper_dir or "." |
| @@ -185,8 +196,8 @@ function init.command(args) | |||
| 185 | } | 196 | } |
| 186 | for _, varname in ipairs(varnames) do | 197 | for _, varname in ipairs(varnames) do |
| 187 | if cfg.variables[varname] then | 198 | if cfg.variables[varname] then |
| 188 | config_tbl.variables = config_tbl.variables or {} | 199 | config_tbl.variables = config_tbl.variables as PersistableTable or {} |
| 189 | config_tbl.variables[varname] = cfg.variables[varname] | 200 | (config_tbl.variables as PersistableTable)[varname] = cfg.variables[varname] |
| 190 | end | 201 | end |
| 191 | end | 202 | end |
| 192 | local ok, err = persist.save_from_table(config_file, config_tbl) | 203 | local ok, err = persist.save_from_table(config_file, config_tbl) |
| @@ -214,6 +225,6 @@ function init.command(args) | |||
| 214 | return true | 225 | return true |
| 215 | end | 226 | end |
| 216 | 227 | ||
| 217 | init.needs_lock = function() return true end | 228 | init.needs_lock = function(): boolean return true end |
| 218 | 229 | ||
| 219 | return init | 230 | return init |
