diff options
Diffstat (limited to 'src/luarocks/command_line.lua')
-rw-r--r-- | src/luarocks/command_line.lua | 11 |
1 files changed, 6 insertions, 5 deletions
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. |
15 | local function die(message) | 15 | -- @param exitcode number: the exitcode to use |
16 | local 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) |
24 | end | 25 | end |
25 | 26 | ||
26 | local function replace_tree(flags, args, tree) | 27 | local 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) |