aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2010-09-10 10:11:52 -0300
committerHisham Muhammad <hisham@gobolinux.org>2010-09-10 10:11:52 -0300
commit6d83783e43061b6231f47dfb14eb6b5937555558 (patch)
treecdc27779a6ad0a2dd8f703882aef77926c27ec82
parent5dcc8b797dad3a4a9b44e3101b06ee1306c81196 (diff)
parent569ab48390725c2d87f9a89cdeb47bae3fc2cd46 (diff)
downloadluarocks-6d83783e43061b6231f47dfb14eb6b5937555558.tar.gz
luarocks-6d83783e43061b6231f47dfb14eb6b5937555558.tar.bz2
luarocks-6d83783e43061b6231f47dfb14eb6b5937555558.zip
Merge branch 'master' of github.com:keplerproject/luarocks
-rwxr-xr-xsrc/bin/luarocks1
-rw-r--r--src/luarocks/build.lua14
-rw-r--r--src/luarocks/cfg.lua4
-rw-r--r--src/luarocks/command_line.lua72
-rw-r--r--src/luarocks/fs/lua.lua48
-rw-r--r--src/luarocks/fs/unix.lua1
-rw-r--r--src/luarocks/fs/unix/tools.lua9
-rw-r--r--src/luarocks/fs/win32.lua8
-rw-r--r--src/luarocks/help.lua1
-rw-r--r--src/luarocks/install.lua13
-rw-r--r--src/luarocks/make.lua6
-rw-r--r--src/luarocks/remove.lua7
-rw-r--r--src/luarocks/rep.lua6
-rw-r--r--src/luarocks/search.lua3
-rw-r--r--src/luarocks/show.lua136
-rw-r--r--src/luarocks/util.lua27
16 files changed, 271 insertions, 85 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks
index fd0c1d9c..5da4bc25 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -17,5 +17,6 @@ commands.remove = require("luarocks.remove")
17commands.make = require("luarocks.make") 17commands.make = require("luarocks.make")
18commands.download = require("luarocks.download") 18commands.download = require("luarocks.download")
19commands.path = require("luarocks.path") 19commands.path = require("luarocks.path")
20commands.show = require("luarocks.show")
20 21
21command_line.run_command(...) 22command_line.run_command(...)
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 62ac3808..b7386688 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -11,6 +11,7 @@ local fs = require("luarocks.fs")
11local dir = require("luarocks.dir") 11local dir = require("luarocks.dir")
12local deps = require("luarocks.deps") 12local deps = require("luarocks.deps")
13local manif = require("luarocks.manif") 13local manif = require("luarocks.manif")
14local cfg = require("luarocks.cfg")
14 15
15help_summary = "Build/compile a rock." 16help_summary = "Build/compile a rock."
16help_arguments = "{<rockspec>|<rock>|<name> [<version>]}" 17help_arguments = "{<rockspec>|<rock>|<name> [<version>]}"
@@ -229,6 +230,14 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode)
229 ok, err = manif.update_manifest(name, version) 230 ok, err = manif.update_manifest(name, version)
230 if err then return nil, err end 231 if err then return nil, err end
231 232
233 local license = ""
234 if rockspec.description.license then
235 license = ("(license: "..rockspec.description.license..")")
236 end
237
238 print()
239 print(name.." "..version.." is now built and installed in "..cfg.root_dir.." "..license)
240
232 util.remove_scheduled_function(rollback) 241 util.remove_scheduled_function(rollback)
233 return true 242 return true
234end 243end
@@ -269,6 +278,11 @@ function run(...)
269 end 278 end
270 assert(type(version) == "string" or not version) 279 assert(type(version) == "string" or not version)
271 280
281 if not flags["local"] and not fs.is_writable(cfg.root_dir) then
282 return nil, "Your user does not have write permissions in " .. cfg.root_dir ..
283 " \n-- you may want to run as a privileged user or use your local tree with --local."
284 end
285
272 if name:match("%.rockspec$") then 286 if name:match("%.rockspec$") then
273 return build_rockspec(name, true) 287 return build_rockspec(name, true)
274 elseif name:match("%.src%.rock$") then 288 elseif name:match("%.src%.rock$") then
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 261411b7..45c73bf6 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -63,9 +63,11 @@ end
63if system == "FreeBSD" then 63if system == "FreeBSD" then
64 detected.unix = true 64 detected.unix = true
65 detected.freebsd = true 65 detected.freebsd = true
66 detected.bsd = true
66elseif system == "Darwin" then 67elseif system == "Darwin" then
67 detected.unix = true 68 detected.unix = true
68 detected.macosx = true 69 detected.macosx = true
70 detected.bsd = true
69elseif system == "Linux" then 71elseif system == "Linux" then
70 detected.unix = true 72 detected.unix = true
71 detected.linux = true 73 detected.linux = true
@@ -83,7 +85,7 @@ end
83 85
84-- Path configuration: 86-- Path configuration:
85 87
86local sys_config_file, home_config_file, home_tree 88local sys_config_file, home_config_file
87if detected.windows or detected.mingw32 then 89if detected.windows or detected.mingw32 then
88 home = os.getenv("APPDATA") or "c:" 90 home = os.getenv("APPDATA") or "c:"
89 sys_config_file = "c:/luarocks/config.lua" 91 sys_config_file = "c:/luarocks/config.lua"
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index d501d121..71ded87d 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -33,6 +33,14 @@ local function is_writable(tree)
33 end 33 end
34end 34end
35 35
36local function use_tree(tree)
37 cfg.root_dir = tree
38 cfg.rocks_dir = path.rocks_dir(tree)
39 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
40 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
41 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
42end
43
36--- Main command-line processor. 44--- Main command-line processor.
37-- Parses input arguments and calls the appropriate driver function 45-- Parses input arguments and calls the appropriate driver function
38-- to execute the action requested on the command-line, forwarding 46-- to execute the action requested on the command-line, forwarding
@@ -58,30 +66,39 @@ function run_command(...)
58 local nonflags = { util.parse_flags(unpack(args)) } 66 local nonflags = { util.parse_flags(unpack(args)) }
59 local flags = table.remove(nonflags, 1) 67 local flags = table.remove(nonflags, 1)
60 cfg.flags = flags 68 cfg.flags = flags
69
70 local command
71
72 if flags["version"] then
73 print(program_name.." "..cfg.program_version)
74 print(program_description)
75 print()
76 os.exit(0)
77 elseif flags["help"] or #nonflags == 0 then
78 command = "help"
79 args = nonflags
80 else
81 command = nonflags[1]
82 for i, arg in ipairs(args) do
83 if arg == command then
84 table.remove(args, i)
85 break
86 end
87 end
88 end
89 command = command:gsub("-", "_")
61 90
62 if flags["to"] then 91 if flags["to"] then
63 if flags["to"] == true then 92 if flags["to"] == true then
64 die("Argument error: use --to=<path>") 93 die("Argument error: use --to=<path>")
65 end 94 end
66 local root_dir = fs.absolute_name(flags["to"]) 95 local root_dir = fs.absolute_name(flags["to"])
67 cfg.root_dir = root_dir 96 use_tree(root_dir)
68 cfg.rocks_dir = path.rocks_dir(root_dir) 97 elseif flags["local"] then
69 cfg.deploy_bin_dir = path.deploy_bin_dir(root_dir) 98 use_tree(cfg.home_tree)
70 cfg.deploy_lua_dir = path.deploy_lua_dir(root_dir)
71 cfg.deploy_lib_dir = path.deploy_lib_dir(root_dir)
72 else 99 else
73 local trees = cfg.rocks_trees 100 local trees = cfg.rocks_trees
74 for i = #trees, 1, -1 do 101 use_tree(trees[#trees])
75 local tree = trees[i]
76 if is_writable(tree) then
77 cfg.root_dir = tree
78 cfg.rocks_dir = path.rocks_dir(tree)
79 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
80 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
81 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
82 break
83 end
84 end
85 end 102 end
86 103
87 if type(cfg.root_dir) == "string" then 104 if type(cfg.root_dir) == "string" then
@@ -111,34 +128,13 @@ function run_command(...)
111 end 128 end
112 cfg.rocks_servers = { flags["only-from"] } 129 cfg.rocks_servers = { flags["only-from"] }
113 end 130 end
114 131
115 local command
116
117 if flags["version"] then
118 print(program_name.." "..cfg.program_version)
119 print(program_description)
120 print()
121 os.exit(0)
122 elseif flags["help"] or #nonflags == 0 then
123 command = "help"
124 args = nonflags
125 else
126 command = nonflags[1]
127 for i, arg in ipairs(args) do
128 if arg == command then
129 table.remove(args, i)
130 break
131 end
132 end
133 end
134
135 if command ~= "help" then 132 if command ~= "help" then
136 for k, v in pairs(cmdline_vars) do 133 for k, v in pairs(cmdline_vars) do
137 cfg.variables[k] = v 134 cfg.variables[k] = v
138 end 135 end
139 end 136 end
140 137
141 command = command:gsub("-", "_")
142 if commands[command] then 138 if commands[command] then
143 local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) 139 local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err)
144 die(debug.traceback("LuaRocks "..cfg.program_version 140 die(debug.traceback("LuaRocks "..cfg.program_version
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index f3d75b44..70df65be 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -14,7 +14,6 @@ local _, ftp = pcall(require, "socket.ftp")
14local zip_ok, lrzip = pcall(require, "luarocks.tools.zip") 14local zip_ok, lrzip = pcall(require, "luarocks.tools.zip")
15local unzip_ok, luazip = pcall(require, "zip"); _G.zip = nil 15local unzip_ok, luazip = pcall(require, "zip"); _G.zip = nil
16local lfs_ok, lfs = pcall(require, "lfs") 16local lfs_ok, lfs = pcall(require, "lfs")
17--local curl_ok, curl = pcall(require, "luacurl")
18local md5_ok, md5 = pcall(require, "md5") 17local md5_ok, md5 = pcall(require, "md5")
19local posix_ok, posix = pcall(require, "posix") 18local posix_ok, posix = pcall(require, "posix")
20 19
@@ -231,6 +230,7 @@ function copy(src, dest)
231 if destmode == "directory" then 230 if destmode == "directory" then
232 dest = dir.path(dest, dir.base_name(src)) 231 dest = dir.path(dest, dir.base_name(src))
233 end 232 end
233 local perms = fs.get_permissions(src)
234 local src_h, err = io.open(src, "rb") 234 local src_h, err = io.open(src, "rb")
235 if not src_h then return nil, err end 235 if not src_h then return nil, err end
236 local dest_h, err = io.open(dest, "wb+") 236 local dest_h, err = io.open(dest, "wb+")
@@ -242,6 +242,7 @@ function copy(src, dest)
242 end 242 end
243 src_h:close() 243 src_h:close()
244 dest_h:close() 244 dest_h:close()
245 fs.chmod(dest, perms)
245 return true 246 return true
246end 247end
247 248
@@ -450,47 +451,6 @@ end
450end 451end
451 452
452--------------------------------------------------------------------- 453---------------------------------------------------------------------
453-- LuaCurl functions
454---------------------------------------------------------------------
455
456if curl_ok then
457
458--- Download a remote file.
459-- @param url string: URL to be fetched.
460-- @param filename string or nil: this function attempts to detect the
461-- resulting local filename of the remote file as the basename of the URL;
462-- if that is not correct (due to a redirection, for example), the local
463-- filename can be given explicitly as this second argument.
464-- @return boolean: true on success, false on failure.
465function download(url, filename)
466 assert(type(url) == "string")
467 assert(type(filename) == "string" or not filename)
468
469 filename = dir.path(fs.current_dir(), filename or dir.base_name(url))
470
471 local c = curl.new()
472 if not c then return false end
473 local file = io.open(filename, "wb")
474 if not file then return false end
475 local ok = c:setopt(curl.OPT_WRITEFUNCTION, function (stream, buffer)
476 stream:write(buffer)
477 return string.len(buffer)
478 end)
479 ok = ok and c:setopt(curl.OPT_WRITEDATA, file)
480 ok = ok and c:setopt(curl.OPT_BUFFERSIZE, 5000)
481 ok = ok and c:setopt(curl.OPT_HTTPHEADER, "Connection: Keep-Alive")
482 ok = ok and c:setopt(curl.OPT_URL, url)
483 ok = ok and c:setopt(curl.OPT_CONNECTTIMEOUT, 15)
484 ok = ok and c:setopt(curl.OPT_USERAGENT, cfg.user_agent)
485 ok = ok and c:perform()
486 ok = ok and c:close()
487 file:close()
488 return ok
489end
490
491end
492
493---------------------------------------------------------------------
494-- LuaSocket functions 454-- LuaSocket functions
495--------------------------------------------------------------------- 455---------------------------------------------------------------------
496 456
@@ -613,6 +573,10 @@ function chmod(file, mode)
613 return err == 0 573 return err == 0
614end 574end
615 575
576function get_permissions(file)
577 return posix.stat(file, "mode")
578end
579
616end 580end
617 581
618--------------------------------------------------------------------- 582---------------------------------------------------------------------
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua
index 94a3ad4e..f2290412 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -122,4 +122,3 @@ end
122function copy_binary(filename, dest) 122function copy_binary(filename, dest)
123 return fs.copy(filename, dest) 123 return fs.copy(filename, dest)
124end 124end
125
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 33dbc489..2bfa7c3e 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -343,3 +343,12 @@ function unpack_archive(archive)
343 end 343 end
344 return true 344 return true
345end 345end
346
347function get_permissions(filename)
348 local ret
349 local flag = cfg.is_platform("bsd") and "-f '%A'" or "-c '%a'"
350 local pipe = io.popen("stat "..flag.." "..fs.Q(filename))
351 ret = pipe:read("*l")
352 pipe:close()
353 return ret
354end
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index d87ad90d..44740850 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -95,3 +95,11 @@ function copy_binary(filename, dest)
95 end 95 end
96 return true 96 return true
97end 97end
98
99function chmod(filename, mode)
100 return true
101end
102
103function get_permissions(filename)
104 return ""
105end
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua
index 04fea7ce..5162b917 100644
--- a/src/luarocks/help.lua
+++ b/src/luarocks/help.lua
@@ -40,6 +40,7 @@ can be overriden with VAR=VALUE assignments.
40--only-from=<server> Fetch rocks/rockspecs from this server only 40--only-from=<server> Fetch rocks/rockspecs from this server only
41 (overrides any entries in the config file) 41 (overrides any entries in the config file)
42--to=<tree> Which tree to operate on. 42--to=<tree> Which tree to operate on.
43--local Use the tree in the user's home directory.
43 44
44Supported commands: 45Supported commands:
45]]) 46]])
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index 260c7751..4bb073dc 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -79,6 +79,14 @@ function install_binary_rock(rock_file)
79 ok, err = manif.update_manifest(name, version) 79 ok, err = manif.update_manifest(name, version)
80 if err then return nil, err end 80 if err then return nil, err end
81 81
82 local license = ""
83 if rockspec.description.license then
84 license = ("(license: "..rockspec.description.license..")")
85 end
86
87 print()
88 print(name.." "..version.." is now installed in "..cfg.root_dir.." "..license)
89
82 util.remove_scheduled_function(rollback) 90 util.remove_scheduled_function(rollback)
83 return true 91 return true
84end 92end
@@ -99,6 +107,11 @@ function run(...)
99 return nil, "Argument missing, see help." 107 return nil, "Argument missing, see help."
100 end 108 end
101 109
110 if not flags["local"] and not fs.is_writable(cfg.root_dir) then
111 return nil, "Your user does not have write permissions in " .. cfg.root_dir ..
112 " \n-- you may want to run as a privileged user or use your local tree with --local."
113 end
114
102 if name:match("%.rockspec$") or name:match("%.src%.rock$") then 115 if name:match("%.rockspec$") or name:match("%.src%.rock$") then
103 local build = require("luarocks.build") 116 local build = require("luarocks.build")
104 return build.run(name) 117 return build.run(name)
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua
index cb2ba374..ec3772ac 100644
--- a/src/luarocks/make.lua
+++ b/src/luarocks/make.lua
@@ -8,6 +8,7 @@ module("luarocks.make", package.seeall)
8local build = require("luarocks.build") 8local build = require("luarocks.build")
9local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
10local util = require("luarocks.util") 10local util = require("luarocks.util")
11local cfg = require("luarocks.cfg")
11 12
12help_summary = "Compile package in current directory using a rockspec." 13help_summary = "Compile package in current directory using a rockspec."
13help_arguments = "[<rockspec>]" 14help_arguments = "[<rockspec>]"
@@ -30,6 +31,11 @@ To install rocks, you'll normally want to use the "install" and
30function run(...) 31function run(...)
31 local flags, rockspec = util.parse_flags(...) 32 local flags, rockspec = util.parse_flags(...)
32 assert(type(rockspec) == "string" or not rockspec) 33 assert(type(rockspec) == "string" or not rockspec)
34
35 if not flags["local"] and not fs.is_writable(cfg.root_dir) then
36 return nil, "Your user does not have write permissions in " .. cfg.root_dir ..
37 " \n-- you may want to run as a privileged user or use your local tree with --local."
38 end
33 39
34 if not rockspec then 40 if not rockspec then
35 local files = fs.list_dir(fs.current_dir()) 41 local files = fs.list_dir(fs.current_dir())
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index afd299ae..d77f28fa 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -11,6 +11,7 @@ local path = require("luarocks.path")
11local util = require("luarocks.util") 11local util = require("luarocks.util")
12local cfg = require("luarocks.cfg") 12local cfg = require("luarocks.cfg")
13local manif = require("luarocks.manif") 13local manif = require("luarocks.manif")
14local fs = require("luarocks.fs")
14 15
15help_summary = "Uninstall a rock." 16help_summary = "Uninstall a rock."
16help_arguments = "[--force] <name> [<version>]" 17help_arguments = "[--force] <name> [<version>]"
@@ -81,6 +82,12 @@ function run(...)
81 if type(name) ~= "string" then 82 if type(name) ~= "string" then
82 return nil, "Argument missing, see help." 83 return nil, "Argument missing, see help."
83 end 84 end
85
86 if not flags["local"] and not fs.is_writable(cfg.rocks_dir) then
87 return nil, "Your user does not have write permissions in " .. cfg.rocks_dir ..
88 " \n-- you may want to run as a privileged user or use your local tree with --local."
89 end
90
84 local results = {} 91 local results = {}
85 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) 92 search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version))
86 93
diff --git a/src/luarocks/rep.lua b/src/luarocks/rep.lua
index 5da5953f..322ab166 100644
--- a/src/luarocks/rep.lua
+++ b/src/luarocks/rep.lua
@@ -252,10 +252,11 @@ function delete_version(name, version)
252 local target = dir.path(deploy_dir, parent_path, file) 252 local target = dir.path(deploy_dir, parent_path, file)
253 local versioned = path.versioned_name(target, deploy_dir, name, version) 253 local versioned = path.versioned_name(target, deploy_dir, name, version)
254 if fs.exists(versioned) then 254 if fs.exists(versioned) then
255 fs.delete(versioned) 255 local ok = fs.delete(versioned)
256 fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) 256 fs.remove_dir_tree_if_empty(dir.dir_name(versioned))
257 if not ok then return nil, "Failed deleting "..versioned end
257 else 258 else
258 fs.delete(target) 259 local ok = fs.delete(target)
259 local next_name, next_version = manif.find_next_provider(target) 260 local next_name, next_version = manif.find_next_provider(target)
260 if next_name then 261 if next_name then
261 local versioned = path.versioned_name(target, deploy_dir, next_name, next_version) 262 local versioned = path.versioned_name(target, deploy_dir, next_name, next_version)
@@ -263,6 +264,7 @@ function delete_version(name, version)
263 fs.remove_dir_tree_if_empty(dir.dir_name(versioned)) 264 fs.remove_dir_tree_if_empty(dir.dir_name(versioned))
264 end 265 end
265 fs.remove_dir_tree_if_empty(dir.dir_name(target)) 266 fs.remove_dir_tree_if_empty(dir.dir_name(target))
267 if not ok then return nil, "Failed deleting "..target end
266 end 268 end
267 return true 269 return true
268 end 270 end
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 6303eb8c..97b86a45 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -283,8 +283,9 @@ end
283-- @param results table: A table where keys are package names and versions 283-- @param results table: A table where keys are package names and versions
284-- are tables matching version strings to an array of rocks servers. 284-- are tables matching version strings to an array of rocks servers.
285-- @param show_repo boolean or nil: Whether to show repository 285-- @param show_repo boolean or nil: Whether to show repository
286-- @param long boolean or nil: Whether to show module files
286-- information or not. Default is true. 287-- information or not. Default is true.
287function print_results(results, show_repo) 288function print_results(results, show_repo, long)
288 assert(type(results) == "table") 289 assert(type(results) == "table")
289 assert(type(show_repo) == "boolean" or not show_repo) 290 assert(type(show_repo) == "boolean" or not show_repo)
290 -- Force display of repo location for the time being 291 -- Force display of repo location for the time being
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua
new file mode 100644
index 00000000..fcdffb9c
--- /dev/null
+++ b/src/luarocks/show.lua
@@ -0,0 +1,136 @@
1
2--- Module implementing the LuaRocks "show" command.
3-- Shows information about an installed rock.
4module("luarocks.show", package.seeall)
5
6local search = require("luarocks.search")
7local cfg = require("luarocks.cfg")
8local util = require("luarocks.util")
9local path = require("luarocks.path")
10local dir = require("luarocks.dir")
11local deps = require("luarocks.deps")
12local fetch = require("luarocks.fetch")
13local manif = require("luarocks.manif")
14help_summary = "Shows information about an installed rock."
15
16help = [[
17<argument> is an existing package name.
18Without any flags, show all module information.
19With these flags, return only the desired information:
20
21--home home page of project
22--modules all modules provided by this package as used by require()
23--deps packages this package depends on
24--rockspec the full path of the rockspec file
25--mversion the package version
26--tree local tree where rock is installed
27--rock-dir data directory of the installed rock
28]]
29
30local function keys_as_string(t, sep)
31 return table.concat(util.keys(t), sep or " ")
32end
33
34local function word_wrap(line)
35 local width = tonumber(os.getenv("COLUMNS")) or 80
36 if width > 80 then width = 80 end
37 if #line > width then
38 local brk = width
39 while brk > 0 and line:sub(brk, brk) ~= " " do
40 brk = brk - 1
41 end
42 if brk > 0 then
43 return line:sub(1, brk-1) .. "\n" .. word_wrap(line:sub(brk+1))
44 end
45 end
46 return line
47end
48
49local function format_text(text)
50 text = text:gsub("^%s*",""):gsub("%s$", ""):gsub("\n[ \t]+","\n"):gsub("([^\n])\n([^\n])","%1 %2")
51 local paragraphs = util.split_string(text, "\n\n")
52 for n, line in ipairs(paragraphs) do
53 paragraphs[n] = word_wrap(line)
54 end
55 return (table.concat(paragraphs, "\n\n"):gsub("%s$", ""))
56end
57
58--- Driver function for "show" command.
59-- @param name or nil: an existing package name.
60-- @param version string or nil: a version may also be passed.
61-- @return boolean: True if succeeded, nil on errors.
62function run(...)
63 local flags, name, version = util.parse_flags(...)
64 if not name then
65 return nil, "Argument missing, see help."
66 end
67 local results = {}
68 local query = search.make_query(name, version)
69 query.exact_name = true
70 local tree_map = {}
71 for _, tree in ipairs(cfg.rocks_trees) do
72 local rocks_dir = path.rocks_dir(tree)
73 tree_map[rocks_dir] = tree
74 search.manifest_search(results, rocks_dir, query)
75 end
76
77 if not next(results) then --
78 return nil,"cannot find package "..name.."\nUse 'list' to find installed rocks"
79 end
80
81 local version,repo_url
82 local package, versions = util.sortedpairs(results)()
83 --question: what do we do about multiple versions? This should
84 --give us the latest version on the last repo (which is usually the global one)
85 for vs, repos in util.sortedpairs(versions, deps.compare_versions) do
86 version = vs
87 for _, rp in ipairs(repos) do repo_url = rp.repo end
88 end
89
90
91 local repo = tree_map[repo_url]
92 local directory = path.install_dir(name,version,repo)
93 local rockspec_file = path.rockspec_file(name, version, repo)
94 local rockspec, err = fetch.load_local_rockspec(rockspec_file)
95 if not rockspec then return nil,err end
96
97 local descript = rockspec.description
98 local manifest, err = manif.load_manifest(repo_url)
99 if not manifest then return nil,err end
100 local minfo = manifest.repository[name][version][1]
101
102 if flags["tree"] then print(repo)
103 elseif flags["rock-dir"] then print(directory)
104 elseif flags["home"] then print(descript.homepage)
105 elseif flags["modules"] then print(keys_as_string(minfo.modules))
106 elseif flags["deps"] then print(keys_as_string(minfo.dependencies))
107 elseif flags["rockspec"] then print(rockspec_file)
108 elseif flags["mversion"] then print(version)
109 else
110 print()
111 print(rockspec.package.." "..rockspec.version.." - "..descript.summary)
112 print()
113 print(format_text(descript.detailed))
114 print()
115 if descript.license then
116 print("License: ", descript.license)
117 end
118 if descript.homepage then
119 print("Homepage: ", descript.homepage)
120 end
121 print("Installed in: ", repo)
122 if next(minfo.modules) then
123 print()
124 print("Modules:")
125 print("\t"..keys_as_string(minfo.modules, "\n\t"))
126 end
127 if next(minfo.dependencies) then
128 print()
129 print("Depends on:")
130 print("\t"..keys_as_string(minfo.dependencies, "\n\t"))
131 end
132 print()
133 end
134 return true
135end
136
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 164dd260..ed70b2ba 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -243,6 +243,33 @@ function starts_with(s, prefix)
243 return s:sub(1,#prefix) == prefix 243 return s:sub(1,#prefix) == prefix
244end 244end
245 245
246-- from http://lua-users.org/wiki/SplitJoin
247-- by PhilippeLhoste
248function split_string(str, delim, maxNb)
249 -- Eliminate bad cases...
250 if string.find(str, delim) == nil then
251 return { str }
252 end
253 if maxNb == nil or maxNb < 1 then
254 maxNb = 0 -- No limit
255 end
256 local result = {}
257 local pat = "(.-)" .. delim .. "()"
258 local nb = 0
259 local lastPos
260 for part, pos in string.gfind(str, pat) do
261 nb = nb + 1
262 result[nb] = part
263 lastPos = pos
264 if nb == maxNb then break end
265 end
266 -- Handle the last field
267 if nb ~= maxNb then
268 result[nb + 1] = string.sub(str, lastPos)
269 end
270 return result
271end
272
246--[[ 273--[[
247Author: Julio Manuel Fernandez-Diaz 274Author: Julio Manuel Fernandez-Diaz
248Date: January 12, 2007 275Date: January 12, 2007