Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds 'shell' command. #492

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.setup.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \
admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \
purge.lua path.lua path_cmd.lua write_rockspec.lua doc.lua upload.lua \
upload/api.lua upload/multipart.lua fetch/git_http.lua fetch/hg_http.lua \
fetch/hg_https.lua fetch/hg_ssh.lua fetch/git_https.lua fetch/git_ssh.lua
fetch/hg_https.lua fetch/hg_ssh.lua fetch/git_https.lua fetch/git_ssh.lua \
shell.lua

1 change: 1 addition & 0 deletions src/bin/luarocks
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ commands = {
doc = "luarocks.doc",
upload = "luarocks.upload",
config = "luarocks.config_cmd",
shell = "luarocks.shell"
}

command_line.run_command(...)
41 changes: 41 additions & 0 deletions src/luarocks/shell.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

--- @module luarocks.shell
-- Driver for the `luarocks shell` command.
local shell_cmd = {}

local util = require("luarocks.util")
local cfg = require("luarocks.cfg")
local fs = require("luarocks.fs")

shell_cmd.help_summary = "Starts a new shell with the variables from `luarocks path` correctly set."
shell_cmd.help_arguments = ""
shell_cmd.help = [[
Starts a new shell with the variables LUA_PATH and LUA_CPATH set as
configured by the LuaRocks installation.
]]

--- Driver function for "shell" command.
-- @return boolean This function always succeeds.
function shell_cmd.run(...)
local lr_path, lr_cpath, lr_bin = cfg.package_paths()
local path_sep = cfg.export_path_separator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused


lr_path = lr_path.. ";" .. package.path
lr_cpath = lr_cpath .. ";" .. package.cpath
lr_bin = lr_bin .. path_sep .. os.getenv("PATH")

lr_path = cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';'))
lr_cpath = cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';'))
lr_bin = cfg.export_path:format(util.remove_path_dupes(lr_bin, path_sep))

local shell, cmd = os.getenv("SHELL")
if shell then
cmd = ([[LUA_PATH="%s" LUA_CPATH="%s" PATH="%s" %s"]]):format(lr_path, lr_cpath, lr_bin, shell)
else
cmd = ([[cmd /k "%s && %s && %s"]]):format(lr_path, lr_cpath, lr_bin)
end
fs.execute(cmd)
return true
end

return shell_cmd