From 3a9c57a3bbf9db4c668b79bd83198f7372dbb310 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 7 Sep 2018 01:10:48 +0300 Subject: init: add --reset option This allows for easier switching between Lua versions in a project directory. --- src/luarocks/cmd/init.lua | 18 +++++++++++++++++- src/luarocks/util.lua | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua index 8f76d06c..e2dddc09 100644 --- a/src/luarocks/cmd/init.lua +++ b/src/luarocks/cmd/init.lua @@ -15,6 +15,11 @@ init.help = [[ is the project name. is an optional project version. +--reset Regenerate .luarocks/config-5.x.lua and ./lua wrapper + if those already exist. + +Options for specifying rockspec data: + --license="" A license string, such as "MIT/X11" or "GNU GPL v3". --summary="" A short one-line description summary. --detailed="" A longer description string. @@ -127,8 +132,19 @@ function init.command(flags, name, version) end local lua_wrapper = "./lua" .. ext + + if flags["reset"] then + fs.delete(lua_wrapper) + for v in util.lua_versions() do + if v ~= cfg.lua_version then + local config_file = dir.path(".luarocks", "config-"..v..".lua") + fs.move(config_file, config_file .. "~") + end + end + end + if not fs.exists(lua_wrapper) then - util.printout("Preparing " .. lua_wrapper .. " ...") + util.printout("Preparing " .. lua_wrapper .. " for version " .. cfg.lua_version .. "...") path.use_tree(tree) fs.wrap_script(nil, "lua", "all") else diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 4be7d71e..3d8f9738 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -139,6 +139,7 @@ local supported_flags = { ["porcelain"] = true, ["project-tree"] = "", ["quick"] = true, + ["reset"] = true, ["rock-dir"] = true, ["rock-license"] = true, ["rock-namespace"] = true, -- cgit v1.2.3-55-g6feb