aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2012-09-19 20:46:02 -0300
committerHisham Muhammad <hisham@gobolinux.org>2012-09-19 20:46:02 -0300
commitf88902378e94729c67231a018ec0d9163b02b549 (patch)
tree68987d47480fd5efc85292dd1c006b7e50936ef4
parentd0ef504fb22131a4717e31f7f22416f60f8efaf4 (diff)
downloadluarocks-f88902378e94729c67231a018ec0d9163b02b549.tar.gz
luarocks-f88902378e94729c67231a018ec0d9163b02b549.tar.bz2
luarocks-f88902378e94729c67231a018ec0d9163b02b549.zip
Add --bin flag for `luarocks path`, and provide cleaner variable output. Closes #76.
-rw-r--r--src/luarocks/cfg.lua4
-rw-r--r--src/luarocks/path.lua8
-rw-r--r--src/luarocks/util.lua16
3 files changed, 26 insertions, 2 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index a8475bfe..f68380f1 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -274,6 +274,8 @@ if detected.windows then
274 lib = { "?.dll", "lib?.dll" }, 274 lib = { "?.dll", "lib?.dll" },
275 include = { "?.h" } 275 include = { "?.h" }
276 } 276 }
277 defaults.export_path = "SET PATH=%s;%s"
278 defaults.export_path_separator = ";"
277 defaults.export_lua_path = "SET LUA_PATH=%s" 279 defaults.export_lua_path = "SET LUA_PATH=%s"
278 defaults.export_lua_cpath = "SET LUA_CPATH=%s" 280 defaults.export_lua_cpath = "SET LUA_CPATH=%s"
279 defaults.local_cache = home.."/cache/luarocks" 281 defaults.local_cache = home.."/cache/luarocks"
@@ -317,6 +319,8 @@ if detected.unix then
317 lib = { "lib?.so", "lib?.so.*" }, 319 lib = { "lib?.so", "lib?.so.*" },
318 include = { "?.h" } 320 include = { "?.h" }
319 } 321 }
322 defaults.export_path = "export PATH='%s:%s'"
323 defaults.export_path_separator = ":"
320 defaults.export_lua_path = "export LUA_PATH='%s'" 324 defaults.export_lua_path = "export LUA_PATH='%s'"
321 defaults.export_lua_cpath = "export LUA_CPATH='%s'" 325 defaults.export_lua_cpath = "export LUA_CPATH='%s'"
322 defaults.local_cache = home.."/.cache/luarocks" 326 defaults.local_cache = home.."/.cache/luarocks"
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index 03ed1b90..1c94b639 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -308,8 +308,12 @@ end
308--- Driver function for "path" command. 308--- Driver function for "path" command.
309-- @return boolean This function always succeeds. 309-- @return boolean This function always succeeds.
310function run(...) 310function run(...)
311 util.printout(cfg.export_lua_path:format(package.path)) 311 local flags = util.parse_flags(...)
312 util.printout(cfg.export_lua_cpath:format(package.cpath)) 312 util.printout(cfg.export_lua_path:format(util.remove_path_dupes(package.path, ';')))
313 util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(package.cpath, ';')))
314 if flags["bin"] then
315 util.printout(cfg.export_path:format(util.remove_path_dupes(os.getenv("PATH"), cfg.export_path_separator), cfg.deploy_bin_dir))
316 end
313 return true 317 return true
314end 318end
315 319
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 2955be50..1a1cccf9 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -326,6 +326,22 @@ function split_string(str, delim, maxNb)
326 return result 326 return result
327end 327end
328 328
329--- Remove repeated entries from a path-style string.
330-- Example: given ("a;b;c;a;b;d", ";"), returns "a;b;c;d".
331-- @param list string: A path string (from $PATH or package.path)
332-- @param sep string: The separator
333function remove_path_dupes(list, sep)
334 local parts = split_string(list, sep)
335 local final, entries = {}, {}
336 for _, part in ipairs(parts) do
337 if not entries[part] then
338 table.insert(final, part)
339 entries[part] = true
340 end
341 end
342 return table.concat(final, sep)
343end
344
329--[[ 345--[[
330Author: Julio Manuel Fernandez-Diaz 346Author: Julio Manuel Fernandez-Diaz
331Date: January 12, 2007 347Date: January 12, 2007