diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-19 10:54:12 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 15:51:13 -0300 |
commit | bf14d8cf45bab9a43b00672cd452d138a8726dfc (patch) | |
tree | 87f16d96eba399f797458e2dfe9d89d05bead95d /src | |
parent | a1d5c8ca857d455582efefe88037b82792734b9c (diff) | |
download | luarocks-bf14d8cf45bab9a43b00672cd452d138a8726dfc.tar.gz luarocks-bf14d8cf45bab9a43b00672cd452d138a8726dfc.tar.bz2 luarocks-bf14d8cf45bab9a43b00672cd452d138a8726dfc.zip |
cmd: move cfg.errorcodes to cmd.errorcodes
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cmd.lua | 16 | ||||
-rw-r--r-- | src/luarocks/cmd/build.lua | 3 | ||||
-rw-r--r-- | src/luarocks/cmd/install.lua | 3 | ||||
-rw-r--r-- | src/luarocks/cmd/make.lua | 3 | ||||
-rw-r--r-- | src/luarocks/cmd/purge.lua | 3 | ||||
-rw-r--r-- | src/luarocks/cmd/remove.lua | 3 | ||||
-rw-r--r-- | src/luarocks/core/cfg.lua | 21 |
7 files changed, 24 insertions, 28 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 3048d956..cedeed22 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
@@ -14,6 +14,14 @@ local fun = require("luarocks.fun") | |||
14 | 14 | ||
15 | local program = util.this_program("luarocks") | 15 | local program = util.this_program("luarocks") |
16 | 16 | ||
17 | cmd.errorcodes = { | ||
18 | OK = 0, | ||
19 | UNSPECIFIED = 1, | ||
20 | PERMISSIONDENIED = 2, | ||
21 | CONFIGFILE = 3, | ||
22 | CRASH = 99 | ||
23 | } | ||
24 | |||
17 | local function error_handler(err) | 25 | local function error_handler(err) |
18 | return debug.traceback("LuaRocks "..cfg.program_version.. | 26 | return debug.traceback("LuaRocks "..cfg.program_version.. |
19 | " bug (please report at https://github.com/luarocks/luarocks/issues).\n"..err, 2) | 27 | " bug (please report at https://github.com/luarocks/luarocks/issues).\n"..err, 2) |
@@ -29,10 +37,10 @@ local function die(message, exitcode) | |||
29 | local ok, err = xpcall(util.run_scheduled_functions, error_handler) | 37 | local ok, err = xpcall(util.run_scheduled_functions, error_handler) |
30 | if not ok then | 38 | if not ok then |
31 | util.printerr("\nError: "..err) | 39 | util.printerr("\nError: "..err) |
32 | exitcode = cfg.errorcodes.CRASH | 40 | exitcode = cmd.errorcodes.CRASH |
33 | end | 41 | end |
34 | 42 | ||
35 | os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) | 43 | os.exit(exitcode or cmd.errorcodes.UNSPECIFIED) |
36 | end | 44 | end |
37 | 45 | ||
38 | local function replace_tree(flags, tree) | 46 | local function replace_tree(flags, tree) |
@@ -125,7 +133,7 @@ function cmd.run_command(...) | |||
125 | util.printout(program.." "..cfg.program_version) | 133 | util.printout(program.." "..cfg.program_version) |
126 | util.printout(program_description) | 134 | util.printout(program_description) |
127 | util.printout() | 135 | util.printout() |
128 | os.exit(cfg.errorcodes.OK) | 136 | os.exit(cmd.errorcodes.OK) |
129 | elseif flags["help"] or #nonflags == 0 then | 137 | elseif flags["help"] or #nonflags == 0 then |
130 | command = "help" | 138 | command = "help" |
131 | else | 139 | else |
@@ -242,7 +250,7 @@ function cmd.run_command(...) | |||
242 | local cmd_mod = require(commands[command]) | 250 | local cmd_mod = require(commands[command]) |
243 | local call_ok, ok, err, exitcode = xpcall(function() return cmd_mod.command(flags, unpack(nonflags)) end, error_handler) | 251 | local call_ok, ok, err, exitcode = xpcall(function() return cmd_mod.command(flags, unpack(nonflags)) end, error_handler) |
244 | if not call_ok then | 252 | if not call_ok then |
245 | die(ok, cfg.errorcodes.CRASH) | 253 | die(ok, cmd.errorcodes.CRASH) |
246 | elseif not ok then | 254 | elseif not ok then |
247 | die(err, exitcode) | 255 | die(err, exitcode) |
248 | end | 256 | end |
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index 08a05296..daccd6cc 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua | |||
@@ -15,6 +15,7 @@ local build = require("luarocks.build") | |||
15 | local writer = require("luarocks.manif.writer") | 15 | local writer = require("luarocks.manif.writer") |
16 | local search = require("luarocks.search") | 16 | local search = require("luarocks.search") |
17 | local make = require("luarocks.cmd.make") | 17 | local make = require("luarocks.cmd.make") |
18 | local cmd = require("luarocks.cmd") | ||
18 | 19 | ||
19 | cmd_build.help_summary = "build/compile a rock." | 20 | cmd_build.help_summary = "build/compile a rock." |
20 | cmd_build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}" | 21 | cmd_build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}" |
@@ -148,7 +149,7 @@ function cmd_build.command(flags, name, version) | |||
148 | 149 | ||
149 | local ok, err = fs.check_command_permissions(flags) | 150 | local ok, err = fs.check_command_permissions(flags) |
150 | if not ok then | 151 | if not ok then |
151 | return nil, err, cfg.errorcodes.PERMISSIONDENIED | 152 | return nil, err, cmd.errorcodes.PERMISSIONDENIED |
152 | end | 153 | end |
153 | 154 | ||
154 | ok, err = do_build(name, version, opts) | 155 | ok, err = do_build(name, version, opts) |
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index c1d9ccc7..824ca248 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua | |||
@@ -13,6 +13,7 @@ local remove = require("luarocks.remove") | |||
13 | local search = require("luarocks.search") | 13 | local search = require("luarocks.search") |
14 | local queries = require("luarocks.queries") | 14 | local queries = require("luarocks.queries") |
15 | local cfg = require("luarocks.core.cfg") | 15 | local cfg = require("luarocks.core.cfg") |
16 | local cmd = require("luarocks.cmd") | ||
16 | 17 | ||
17 | install.help_summary = "Install a rock." | 18 | install.help_summary = "Install a rock." |
18 | 19 | ||
@@ -191,7 +192,7 @@ function install.command(flags, name, version) | |||
191 | name = util.adjust_name_and_namespace(name, flags) | 192 | name = util.adjust_name_and_namespace(name, flags) |
192 | 193 | ||
193 | local ok, err = fs.check_command_permissions(flags) | 194 | local ok, err = fs.check_command_permissions(flags) |
194 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end | 195 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end |
195 | 196 | ||
196 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then | 197 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then |
197 | local build = require("luarocks.cmd.build") | 198 | local build = require("luarocks.cmd.build") |
diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index caf64721..90d4f336 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua | |||
@@ -14,6 +14,7 @@ local pack = require("luarocks.pack") | |||
14 | local remove = require("luarocks.remove") | 14 | local remove = require("luarocks.remove") |
15 | local deps = require("luarocks.deps") | 15 | local deps = require("luarocks.deps") |
16 | local writer = require("luarocks.manif.writer") | 16 | local writer = require("luarocks.manif.writer") |
17 | local cmd = require("luarocks.cmd") | ||
17 | 18 | ||
18 | make.help_summary = "Compile package in current directory using a rockspec." | 19 | make.help_summary = "Compile package in current directory using a rockspec." |
19 | make.help_arguments = "[--pack-binary-rock] [<rockspec>]" | 20 | make.help_arguments = "[--pack-binary-rock] [<rockspec>]" |
@@ -89,7 +90,7 @@ function make.command(flags, rockspec_filename) | |||
89 | end) | 90 | end) |
90 | else | 91 | else |
91 | local ok, err = fs.check_command_permissions(flags) | 92 | local ok, err = fs.check_command_permissions(flags) |
92 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end | 93 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end |
93 | ok, err = build.build_rockspec(rockspec, opts) | 94 | ok, err = build.build_rockspec(rockspec, opts) |
94 | if not ok then return nil, err end | 95 | if not ok then return nil, err end |
95 | local name, version = ok, err | 96 | local name, version = ok, err |
diff --git a/src/luarocks/cmd/purge.lua b/src/luarocks/cmd/purge.lua index 5f868e60..98b76a0f 100644 --- a/src/luarocks/cmd/purge.lua +++ b/src/luarocks/cmd/purge.lua | |||
@@ -13,6 +13,7 @@ local writer = require("luarocks.manif.writer") | |||
13 | local cfg = require("luarocks.core.cfg") | 13 | local cfg = require("luarocks.core.cfg") |
14 | local remove = require("luarocks.remove") | 14 | local remove = require("luarocks.remove") |
15 | local queries = require("luarocks.queries") | 15 | local queries = require("luarocks.queries") |
16 | local cmd = require("luarocks.cmd") | ||
16 | 17 | ||
17 | purge.help_summary = "Remove all installed rocks from a tree." | 18 | purge.help_summary = "Remove all installed rocks from a tree." |
18 | purge.help_arguments = "--tree=<tree> [--old-versions]" | 19 | purge.help_arguments = "--tree=<tree> [--old-versions]" |
@@ -43,7 +44,7 @@ function purge.command(flags) | |||
43 | end | 44 | end |
44 | 45 | ||
45 | local ok, err = fs.check_command_permissions(flags) | 46 | local ok, err = fs.check_command_permissions(flags) |
46 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end | 47 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end |
47 | 48 | ||
48 | search.local_manifest_search(results, path.rocks_dir(tree), queries.all()) | 49 | search.local_manifest_search(results, path.rocks_dir(tree), queries.all()) |
49 | 50 | ||
diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua index 4af036aa..5ddf7477 100644 --- a/src/luarocks/cmd/remove.lua +++ b/src/luarocks/cmd/remove.lua | |||
@@ -12,6 +12,7 @@ local path = require("luarocks.path") | |||
12 | local deps = require("luarocks.deps") | 12 | local deps = require("luarocks.deps") |
13 | local writer = require("luarocks.manif.writer") | 13 | local writer = require("luarocks.manif.writer") |
14 | local queries = require("luarocks.queries") | 14 | local queries = require("luarocks.queries") |
15 | local cmd = require("luarocks.cmd") | ||
15 | 16 | ||
16 | cmd_remove.help_summary = "Uninstall a rock." | 17 | cmd_remove.help_summary = "Uninstall a rock." |
17 | cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]" | 18 | cmd_remove.help_arguments = "[--force|--force-fast] <name> [<version>]" |
@@ -42,7 +43,7 @@ function cmd_remove.command(flags, name, version) | |||
42 | local deps_mode = flags["deps-mode"] or cfg.deps_mode | 43 | local deps_mode = flags["deps-mode"] or cfg.deps_mode |
43 | 44 | ||
44 | local ok, err = fs.check_command_permissions(flags) | 45 | local ok, err = fs.check_command_permissions(flags) |
45 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end | 46 | if not ok then return nil, err, cmd.errorcodes.PERMISSIONDENIED end |
46 | 47 | ||
47 | local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") | 48 | local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") |
48 | local filename = name | 49 | local filename = name |
diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index 00efeaf3..7c29e2dc 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua | |||
@@ -37,23 +37,6 @@ cfg.variables = {} | |||
37 | cfg.rocks_trees = {} | 37 | cfg.rocks_trees = {} |
38 | cfg.platforms = {} | 38 | cfg.platforms = {} |
39 | 39 | ||
40 | cfg.errorcodes = setmetatable({ | ||
41 | OK = 0, | ||
42 | UNSPECIFIED = 1, | ||
43 | PERMISSIONDENIED = 2, | ||
44 | CONFIGFILE = 3, | ||
45 | CRASH = 99 | ||
46 | },{ | ||
47 | __index = function(t, key) | ||
48 | local val = rawget(t, key) | ||
49 | if not val then | ||
50 | error("'"..tostring(key).."' is not a valid errorcode", 2) | ||
51 | end | ||
52 | return val | ||
53 | end | ||
54 | }) | ||
55 | |||
56 | |||
57 | local popen_ok, popen_result = pcall(io.popen, "") | 40 | local popen_ok, popen_result = pcall(io.popen, "") |
58 | if popen_ok then | 41 | if popen_ok then |
59 | if popen_result then | 42 | if popen_result then |
@@ -62,7 +45,7 @@ if popen_ok then | |||
62 | else | 45 | else |
63 | io.stderr:write("Your version of Lua does not support io.popen,\n") | 46 | io.stderr:write("Your version of Lua does not support io.popen,\n") |
64 | io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") | 47 | io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") |
65 | os.exit(cfg.errorcodes.UNSPECIFIED) | 48 | os.exit(1) -- FIXME |
66 | end | 49 | end |
67 | 50 | ||
68 | -- System detection: | 51 | -- System detection: |
@@ -207,7 +190,7 @@ local load_config_file = function(filepath) | |||
207 | if (not result) and errcode ~= "open" then | 190 | if (not result) and errcode ~= "open" then |
208 | -- errcode is either "load" or "run"; bad config file, so error out | 191 | -- errcode is either "load" or "run"; bad config file, so error out |
209 | io.stderr:write(err.."\n") | 192 | io.stderr:write(err.."\n") |
210 | os.exit(cfg.errorcodes.CONFIGFILE) | 193 | os.exit(3) -- FIXME |
211 | end | 194 | end |
212 | if result then | 195 | if result then |
213 | -- success in loading and running, merge contents and exit | 196 | -- success in loading and running, merge contents and exit |