aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/bin/luarocks3
-rw-r--r--src/luarocks/path.lua40
-rw-r--r--src/luarocks/path_cmd.lua50
3 files changed, 51 insertions, 42 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks
index e9cfc349..1d81ed1e 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -1,5 +1,4 @@
1#!/usr/bin/env lua 1#!/usr/bin/env lua
2
3local loader = require("luarocks.loader") 2local loader = require("luarocks.loader")
4local command_line = require("luarocks.command_line") 3local command_line = require("luarocks.command_line")
5 4
@@ -16,7 +15,7 @@ commands = {
16 remove = "luarocks.remove", 15 remove = "luarocks.remove",
17 make = "luarocks.make", 16 make = "luarocks.make",
18 download = "luarocks.download", 17 download = "luarocks.download",
19 path = "luarocks.path", 18 path = "luarocks.path_cmd",
20 show = "luarocks.show", 19 show = "luarocks.show",
21 new_version = "luarocks.new_version", 20 new_version = "luarocks.new_version",
22 lint = "luarocks.lint", 21 lint = "luarocks.lint",
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index d7273095..200829d0 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -7,7 +7,6 @@ module("luarocks.path", package.seeall)
7local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
8local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
9local util = require("luarocks.util") 9local util = require("luarocks.util")
10local deps = require("luarocks.deps")
11 10
12help_summary = "Return the currently configured package path." 11help_summary = "Return the currently configured package path."
13help_arguments = "" 12help_arguments = ""
@@ -390,42 +389,3 @@ function which(module_name, filename, name, version, tree, manifest)
390 assert(false) 389 assert(false)
391end 390end
392 391
393--- Driver function for "path" command.
394-- @return boolean This function always succeeds.
395function run(...)
396 local flags = util.parse_flags(...)
397 local deps_mode = deps.get_deps_mode(flags)
398
399 local lr_path, lr_cpath = cfg.package_paths()
400 local bin_dirs = map_trees(deps_mode, deploy_bin_dir)
401
402 if flags["lr-path"] then
403 util.printout(util.remove_path_dupes(lr_path, ';'))
404 return true
405 elseif flags["lr-cpath"] then
406 util.printout(util.remove_path_dupes(lr_cpath, ';'))
407 return true
408 elseif flags["lr-bin"] then
409 local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator)
410 util.printout(util.remove_path_dupes(lr_bin, ';'))
411 return true
412 end
413
414 if flags["append"] then
415 lr_path = package.path .. ";" .. lr_path
416 lr_cpath = package.cpath .. ";" .. lr_cpath
417 else
418 lr_path = lr_path.. ";" .. package.path
419 lr_cpath = lr_cpath .. ";" .. package.cpath
420 end
421
422 util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';')))
423 util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';')))
424 if flags["bin"] then
425 table.insert(bin_dirs, 1, os.getenv("PATH"))
426 local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator)
427 util.printout(cfg.export_path:format(lr_bin))
428 end
429 return true
430end
431
diff --git a/src/luarocks/path_cmd.lua b/src/luarocks/path_cmd.lua
new file mode 100644
index 00000000..4df51e2d
--- /dev/null
+++ b/src/luarocks/path_cmd.lua
@@ -0,0 +1,50 @@
1
2--- @module luarocks.path_cmd
3-- Driver for the `luarocks path` command.
4local path_cmd = {}
5
6local util = require("luarocks.util")
7local deps = require("luarocks.deps")
8local cfg = require("luarocks.cfg")
9local path = require("luarocks.path")
10
11--- Driver function for "path" command.
12-- @return boolean This function always succeeds.
13function path_cmd.run(...)
14 local flags = util.parse_flags(...)
15 local deps_mode = deps.get_deps_mode(flags)
16
17 local lr_path, lr_cpath = cfg.package_paths()
18 local bin_dirs = path.map_trees(deps_mode, path.deploy_bin_dir)
19
20 if flags["lr-path"] then
21 util.printout(util.remove_path_dupes(lr_path, ';'))
22 return true
23 elseif flags["lr-cpath"] then
24 util.printout(util.remove_path_dupes(lr_cpath, ';'))
25 return true
26 elseif flags["lr-bin"] then
27 local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator)
28 util.printout(util.remove_path_dupes(lr_bin, ';'))
29 return true
30 end
31
32 if flags["append"] then
33 lr_path = package.path .. ";" .. lr_path
34 lr_cpath = package.cpath .. ";" .. lr_cpath
35 else
36 lr_path = lr_path.. ";" .. package.path
37 lr_cpath = lr_cpath .. ";" .. package.cpath
38 end
39
40 util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';')))
41 util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';')))
42 if flags["bin"] then
43 table.insert(bin_dirs, 1, os.getenv("PATH"))
44 local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator)
45 util.printout(cfg.export_path:format(lr_bin))
46 end
47 return true
48end
49
50return path_cmd