diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2014-03-20 16:49:51 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-03-20 16:49:51 -0300 |
| commit | 397659cc5cb30569b33cc9c0ab220f85379bc97f (patch) | |
| tree | c5532f157f128460cd371ae455d73102d643bcac /src | |
| parent | 3aa7e7a08f0dd756e31ce34e4c9ae9bf0169d49a (diff) | |
| download | luarocks-397659cc5cb30569b33cc9c0ab220f85379bc97f.tar.gz luarocks-397659cc5cb30569b33cc9c0ab220f85379bc97f.tar.bz2 luarocks-397659cc5cb30569b33cc9c0ab220f85379bc97f.zip | |
Split luarocks.path the library and `luarocks path` the command.
As suggested in #232.
Diffstat (limited to 'src')
| -rwxr-xr-x | src/bin/luarocks | 3 | ||||
| -rw-r--r-- | src/luarocks/path.lua | 40 | ||||
| -rw-r--r-- | src/luarocks/path_cmd.lua | 50 |
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 | |||
| 3 | local loader = require("luarocks.loader") | 2 | local loader = require("luarocks.loader") |
| 4 | local command_line = require("luarocks.command_line") | 3 | local 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) | |||
| 7 | local dir = require("luarocks.dir") | 7 | local dir = require("luarocks.dir") |
| 8 | local cfg = require("luarocks.cfg") | 8 | local cfg = require("luarocks.cfg") |
| 9 | local util = require("luarocks.util") | 9 | local util = require("luarocks.util") |
| 10 | local deps = require("luarocks.deps") | ||
| 11 | 10 | ||
| 12 | help_summary = "Return the currently configured package path." | 11 | help_summary = "Return the currently configured package path." |
| 13 | help_arguments = "" | 12 | help_arguments = "" |
| @@ -390,42 +389,3 @@ function which(module_name, filename, name, version, tree, manifest) | |||
| 390 | assert(false) | 389 | assert(false) |
| 391 | end | 390 | end |
| 392 | 391 | ||
| 393 | --- Driver function for "path" command. | ||
| 394 | -- @return boolean This function always succeeds. | ||
| 395 | function 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 | ||
| 430 | end | ||
| 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. | ||
| 4 | local path_cmd = {} | ||
| 5 | |||
| 6 | local util = require("luarocks.util") | ||
| 7 | local deps = require("luarocks.deps") | ||
| 8 | local cfg = require("luarocks.cfg") | ||
| 9 | local path = require("luarocks.path") | ||
| 10 | |||
| 11 | --- Driver function for "path" command. | ||
| 12 | -- @return boolean This function always succeeds. | ||
| 13 | function 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 | ||
| 48 | end | ||
| 49 | |||
| 50 | return path_cmd | ||
