From 397659cc5cb30569b33cc9c0ab220f85379bc97f Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 20 Mar 2014 16:49:51 -0300 Subject: Split luarocks.path the library and `luarocks path` the command. As suggested in #232. --- src/bin/luarocks | 3 +-- src/luarocks/path.lua | 40 ------------------------------------- src/luarocks/path_cmd.lua | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 src/luarocks/path_cmd.lua (limited to 'src') 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 @@ #!/usr/bin/env lua - local loader = require("luarocks.loader") local command_line = require("luarocks.command_line") @@ -16,7 +15,7 @@ commands = { remove = "luarocks.remove", make = "luarocks.make", download = "luarocks.download", - path = "luarocks.path", + path = "luarocks.path_cmd", show = "luarocks.show", new_version = "luarocks.new_version", 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) local dir = require("luarocks.dir") local cfg = require("luarocks.cfg") local util = require("luarocks.util") -local deps = require("luarocks.deps") help_summary = "Return the currently configured package path." help_arguments = "" @@ -390,42 +389,3 @@ function which(module_name, filename, name, version, tree, manifest) assert(false) end ---- Driver function for "path" command. --- @return boolean This function always succeeds. -function run(...) - local flags = util.parse_flags(...) - local deps_mode = deps.get_deps_mode(flags) - - local lr_path, lr_cpath = cfg.package_paths() - local bin_dirs = map_trees(deps_mode, deploy_bin_dir) - - if flags["lr-path"] then - util.printout(util.remove_path_dupes(lr_path, ';')) - return true - elseif flags["lr-cpath"] then - util.printout(util.remove_path_dupes(lr_cpath, ';')) - return true - elseif flags["lr-bin"] then - local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) - util.printout(util.remove_path_dupes(lr_bin, ';')) - return true - end - - if flags["append"] then - lr_path = package.path .. ";" .. lr_path - lr_cpath = package.cpath .. ";" .. lr_cpath - else - lr_path = lr_path.. ";" .. package.path - lr_cpath = lr_cpath .. ";" .. package.cpath - end - - util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';'))) - util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';'))) - if flags["bin"] then - table.insert(bin_dirs, 1, os.getenv("PATH")) - local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) - util.printout(cfg.export_path:format(lr_bin)) - end - return true -end - 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 @@ + +--- @module luarocks.path_cmd +-- Driver for the `luarocks path` command. +local path_cmd = {} + +local util = require("luarocks.util") +local deps = require("luarocks.deps") +local cfg = require("luarocks.cfg") +local path = require("luarocks.path") + +--- Driver function for "path" command. +-- @return boolean This function always succeeds. +function path_cmd.run(...) + local flags = util.parse_flags(...) + local deps_mode = deps.get_deps_mode(flags) + + local lr_path, lr_cpath = cfg.package_paths() + local bin_dirs = path.map_trees(deps_mode, path.deploy_bin_dir) + + if flags["lr-path"] then + util.printout(util.remove_path_dupes(lr_path, ';')) + return true + elseif flags["lr-cpath"] then + util.printout(util.remove_path_dupes(lr_cpath, ';')) + return true + elseif flags["lr-bin"] then + local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) + util.printout(util.remove_path_dupes(lr_bin, ';')) + return true + end + + if flags["append"] then + lr_path = package.path .. ";" .. lr_path + lr_cpath = package.cpath .. ";" .. lr_cpath + else + lr_path = lr_path.. ";" .. package.path + lr_cpath = lr_cpath .. ";" .. package.cpath + end + + util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';'))) + util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';'))) + if flags["bin"] then + table.insert(bin_dirs, 1, os.getenv("PATH")) + local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) + util.printout(cfg.export_path:format(lr_bin)) + end + return true +end + +return path_cmd -- cgit v1.2.3-55-g6feb