aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-06-19 11:14:56 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-07-01 15:51:13 -0300
commit1eee434b7e6313e721f8ff638f7b78cfb21960db (patch)
treeca1d6b61c815d51bedfb57e408fe8b18307d3e09
parente0af9ea7a7d7ba2aba76f975bf0d1c9965649ab8 (diff)
downloadluarocks-1eee434b7e6313e721f8ff638f7b78cfb21960db.tar.gz
luarocks-1eee434b7e6313e721f8ff638f7b78cfb21960db.tar.bz2
luarocks-1eee434b7e6313e721f8ff638f7b78cfb21960db.zip
cmd: move local functions inside
-rw-r--r--src/luarocks/cmd.lua43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua
index 1b069d59..51d22154 100644
--- a/src/luarocks/cmd.lua
+++ b/src/luarocks/cmd.lua
@@ -22,27 +22,6 @@ cmd.errorcodes = {
22 CRASH = 99 22 CRASH = 99
23} 23}
24 24
25local function error_handler(err)
26 return debug.traceback("LuaRocks "..cfg.program_version..
27 " bug (please report at https://github.com/luarocks/luarocks/issues).\n"..err, 2)
28end
29
30--- Display an error message and exit.
31-- @param message string: The error message.
32-- @param exitcode number: the exitcode to use
33local function die(message, exitcode)
34 assert(type(message) == "string", "bad error, expected string, got: " .. type(message))
35 util.printerr("\nError: "..message)
36
37 local ok, err = xpcall(util.run_scheduled_functions, error_handler)
38 if not ok then
39 util.printerr("\nError: "..err)
40 exitcode = cmd.errorcodes.CRASH
41 end
42
43 os.exit(exitcode or cmd.errorcodes.UNSPECIFIED)
44end
45
46local function replace_tree(flags, tree) 25local function replace_tree(flags, tree)
47 tree = dir.normalize(tree) 26 tree = dir.normalize(tree)
48 flags["tree"] = tree 27 flags["tree"] = tree
@@ -81,6 +60,28 @@ end
81-- the loaded modules representing commands. 60-- the loaded modules representing commands.
82-- @param ... string: Arguments given on the command-line. 61-- @param ... string: Arguments given on the command-line.
83function cmd.run_command(description, commands, ...) 62function cmd.run_command(description, commands, ...)
63
64 local function error_handler(err)
65 return debug.traceback("LuaRocks "..cfg.program_version..
66 " bug (please report at https://github.com/luarocks/luarocks/issues).\n"..err, 2)
67 end
68
69 --- Display an error message and exit.
70 -- @param message string: The error message.
71 -- @param exitcode number: the exitcode to use
72 local function die(message, exitcode)
73 assert(type(message) == "string", "bad error, expected string, got: " .. type(message))
74 util.printerr("\nError: "..message)
75
76 local ok, err = xpcall(util.run_scheduled_functions, error_handler)
77 if not ok then
78 util.printerr("\nError: "..err)
79 exitcode = cmd.errorcodes.CRASH
80 end
81
82 os.exit(exitcode or cmd.errorcodes.UNSPECIFIED)
83 end
84
84 local args = {...} 85 local args = {...}
85 local cmdline_vars = {} 86 local cmdline_vars = {}
86 for i = #args, 1, -1 do 87 for i = #args, 1, -1 do