aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/build.lua2
-rw-r--r--src/luarocks/cfg.lua17
-rw-r--r--src/luarocks/command_line.lua11
-rw-r--r--src/luarocks/install.lua2
-rw-r--r--src/luarocks/make.lua2
-rw-r--r--src/luarocks/remove.lua2
6 files changed, 26 insertions, 10 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 5555d94a..cee65781 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -364,7 +364,7 @@ function run(...)
364 return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags)) 364 return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags))
365 else 365 else
366 local ok, err = fs.check_command_permissions(flags) 366 local ok, err = fs.check_command_permissions(flags)
367 if not ok then return nil, err end 367 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
368 ok, err = do_build(name, version, deps.get_deps_mode(flags)) 368 ok, err = do_build(name, version, deps.get_deps_mode(flags))
369 if not ok then return nil, err end 369 if not ok then return nil, err end
370 local name, version = ok, err 370 local name, version = ok, err
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 2904146b..87777b86 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -35,6 +35,21 @@ major_version = program_version:match("([^.]%.[^.])")
35 35
36local persist = require("luarocks.persist") 36local persist = require("luarocks.persist")
37 37
38_M.errorcodes = setmetatable({
39 OK = 0,
40 UNSPECIFIED = 1,
41 PERMISSIONDENIED = 2,
42},{
43 __index = function(t, key)
44 local val = rawget(t, key)
45 if not val then
46 error("'"..tostring(key).."' is not a valid errorcode", 2)
47 end
48 return val
49 end
50})
51
52
38local popen_ok, popen_result = pcall(io.popen, "") 53local popen_ok, popen_result = pcall(io.popen, "")
39if popen_ok then 54if popen_ok then
40 if popen_result then 55 if popen_result then
@@ -43,7 +58,7 @@ if popen_ok then
43else 58else
44 io.stderr:write("Your version of Lua does not support io.popen,\n") 59 io.stderr:write("Your version of Lua does not support io.popen,\n")
45 io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") 60 io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n")
46 os.exit(1) 61 os.exit(_M.errorcodes.UNSPECIFIED)
47end 62end
48 63
49-- System detection: 64-- System detection:
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index b98084e0..e79b1442 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -12,7 +12,8 @@ local program = util.this_program("luarocks")
12 12
13--- Display an error message and exit. 13--- Display an error message and exit.
14-- @param message string: The error message. 14-- @param message string: The error message.
15local function die(message) 15-- @param exitcode number: the exitcode to use
16local function die(message, exitcode)
16 assert(type(message) == "string") 17 assert(type(message) == "string")
17 18
18 local ok, err = pcall(util.run_scheduled_functions) 19 local ok, err = pcall(util.run_scheduled_functions)
@@ -20,7 +21,7 @@ local function die(message)
20 util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at luarocks-developers@lists.sourceforge.net):\n"..err) 21 util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at luarocks-developers@lists.sourceforge.net):\n"..err)
21 end 22 end
22 util.printerr("\nError: "..message) 23 util.printerr("\nError: "..message)
23 os.exit(1) 24 os.exit(exitcode or cfg.errorcodes.UNSPECIFIED)
24end 25end
25 26
26local function replace_tree(flags, args, tree) 27local function replace_tree(flags, args, tree)
@@ -83,7 +84,7 @@ function run_command(...)
83 util.printout(program.." "..cfg.program_version) 84 util.printout(program.." "..cfg.program_version)
84 util.printout(program_description) 85 util.printout(program_description)
85 util.printout() 86 util.printout()
86 os.exit(0) 87 os.exit(cfg.errorcodes.OK)
87 elseif flags["help"] or #nonflags == 0 then 88 elseif flags["help"] or #nonflags == 0 then
88 command = "help" 89 command = "help"
89 args = nonflags 90 args = nonflags
@@ -184,13 +185,13 @@ function run_command(...)
184 -- I'm not changing this now to avoid messing with the run() 185 -- I'm not changing this now to avoid messing with the run()
185 -- interface, which I know some people use (even though 186 -- interface, which I know some people use (even though
186 -- I never published it as a public API...) 187 -- I never published it as a public API...)
187 local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) 188 local xp, ok, err, exitcode = xpcall(function() return commands[command].run(unpack(args)) end, function(err)
188 die(debug.traceback("LuaRocks "..cfg.program_version 189 die(debug.traceback("LuaRocks "..cfg.program_version
189 .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" 190 .." bug (please report at luarocks-developers@lists.sourceforge.net).\n"
190 ..err, 2)) 191 ..err, 2))
191 end) 192 end)
192 if xp and (not ok) then 193 if xp and (not ok) then
193 die(err) 194 die(err, exitcode)
194 end 195 end
195 else 196 else
196 die("Unknown command: "..command) 197 die("Unknown command: "..command)
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index c181d612..041d8ca2 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -129,7 +129,7 @@ function run(...)
129 end 129 end
130 130
131 local ok, err = fs.check_command_permissions(flags) 131 local ok, err = fs.check_command_permissions(flags)
132 if not ok then return nil, err end 132 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
133 133
134 if name:match("%.rockspec$") or name:match("%.src%.rock$") then 134 if name:match("%.rockspec$") or name:match("%.src%.rock$") then
135 util.printout("Using "..name.."... switching to 'build' mode") 135 util.printout("Using "..name.."... switching to 'build' mode")
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua
index eef49d0c..aff4f93c 100644
--- a/src/luarocks/make.lua
+++ b/src/luarocks/make.lua
@@ -73,7 +73,7 @@ function run(...)
73 return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.get_deps_mode(flags)) 73 return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.get_deps_mode(flags))
74 else 74 else
75 local ok, err = fs.check_command_permissions(flags) 75 local ok, err = fs.check_command_permissions(flags)
76 if not ok then return nil, err end 76 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
77 ok, err = build.build_rockspec(rockspec, false, true, deps.get_deps_mode(flags)) 77 ok, err = build.build_rockspec(rockspec, false, true, deps.get_deps_mode(flags))
78 if not ok then return nil, err end 78 if not ok then return nil, err end
79 local name, version = ok, err 79 local name, version = ok, err
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index 5a6e4dc5..9ab6d11f 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -144,7 +144,7 @@ function run(...)
144 local deps_mode = flags["deps-mode"] or cfg.deps_mode 144 local deps_mode = flags["deps-mode"] or cfg.deps_mode
145 145
146 local ok, err = fs.check_command_permissions(flags) 146 local ok, err = fs.check_command_permissions(flags)
147 if not ok then return nil, err end 147 if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end
148 148
149 local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") 149 local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$")
150 local filename = name 150 local filename = name