diff options
-rwxr-xr-x | src/bin/luarocks | 1 | ||||
-rw-r--r-- | src/luarocks/cfg.lua | 30 | ||||
-rw-r--r-- | src/luarocks/config_cmd.lua | 58 | ||||
-rw-r--r-- | src/luarocks/fetch.lua | 3 | ||||
-rw-r--r-- | src/luarocks/help.lua | 12 | ||||
-rw-r--r-- | src/luarocks/util.lua | 6 | ||||
-rwxr-xr-x | test/testing.sh | 11 |
7 files changed, 102 insertions, 19 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks index d2f3c220..be6c2b81 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks | |||
@@ -27,6 +27,7 @@ commands = { | |||
27 | purge = "luarocks.purge", | 27 | purge = "luarocks.purge", |
28 | doc = "luarocks.doc", | 28 | doc = "luarocks.doc", |
29 | upload = "luarocks.upload", | 29 | upload = "luarocks.upload", |
30 | config = "luarocks.config_cmd", | ||
30 | } | 31 | } |
31 | 32 | ||
32 | command_line.run_command(...) | 33 | command_line.run_command(...) |
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index e864c9fd..7aaacc76 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
@@ -146,16 +146,17 @@ cfg.variables = {} | |||
146 | cfg.rocks_trees = {} | 146 | cfg.rocks_trees = {} |
147 | 147 | ||
148 | sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" | 148 | sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" |
149 | local err, errcode | 149 | do |
150 | sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, cfg) | 150 | local err, errcode |
151 | |||
152 | if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file | ||
153 | sys_config_file = sys_config_dir.."/config.lua" | ||
154 | sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, cfg) | 151 | sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, cfg) |
155 | end | 152 | if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file |
156 | if (not sys_config_ok) and errcode ~= "open" then -- either "load" or "run"; bad config file, bail out with error | 153 | sys_config_file = sys_config_dir.."/config.lua" |
157 | io.stderr:write(err.."\n") | 154 | sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, cfg) |
158 | os.exit(cfg.errorcodes.CONFIGFILE) | 155 | end |
156 | if (not sys_config_ok) and errcode ~= "open" then -- either "load" or "run"; bad config file, bail out with error | ||
157 | io.stderr:write(err.."\n") | ||
158 | os.exit(cfg.errorcodes.CONFIGFILE) | ||
159 | end | ||
159 | end | 160 | end |
160 | 161 | ||
161 | local env_for_config_file = { | 162 | local env_for_config_file = { |
@@ -590,7 +591,16 @@ function cfg.init_package_paths() | |||
590 | end | 591 | end |
591 | 592 | ||
592 | function cfg.which_config() | 593 | function cfg.which_config() |
593 | return sys_config_file, sys_config_ok, home_config_file, home_config_ok | 594 | return { |
595 | system = { | ||
596 | file = sys_config_file, | ||
597 | ok = sys_config_ok, | ||
598 | }, | ||
599 | user = { | ||
600 | file = home_config_file, | ||
601 | ok = home_config_ok, | ||
602 | } | ||
603 | } | ||
594 | end | 604 | end |
595 | 605 | ||
596 | cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch | 606 | cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch |
diff --git a/src/luarocks/config_cmd.lua b/src/luarocks/config_cmd.lua new file mode 100644 index 00000000..c066cfec --- /dev/null +++ b/src/luarocks/config_cmd.lua | |||
@@ -0,0 +1,58 @@ | |||
1 | --- Module implementing the LuaRocks "config" command. | ||
2 | -- Queries information about the LuaRocks configuration. | ||
3 | local config_cmd = {} | ||
4 | |||
5 | local cfg = require("luarocks.cfg") | ||
6 | local util = require("luarocks.util") | ||
7 | local dir = require("luarocks.dir") | ||
8 | |||
9 | local function config_file(conf) | ||
10 | print(dir.normalize(conf.file)) | ||
11 | if conf.ok then | ||
12 | return true | ||
13 | else | ||
14 | return nil, "file not found" | ||
15 | end | ||
16 | end | ||
17 | |||
18 | --- Driver function for "config" command. | ||
19 | -- @return boolean: True if succeeded, nil on errors. | ||
20 | function config_cmd.run(...) | ||
21 | local flags = util.parse_flags(...) | ||
22 | |||
23 | if flags["lua-incdir"] then | ||
24 | print(cfg.variables.LUA_INCDIR) | ||
25 | return true | ||
26 | end | ||
27 | if flags["lua-libdir"] then | ||
28 | print(cfg.variables.LUA_LIBDIR) | ||
29 | return true | ||
30 | end | ||
31 | if flags["lua-ver"] then | ||
32 | print(cfg.lua_version) | ||
33 | return true | ||
34 | end | ||
35 | local conf = cfg.which_config() | ||
36 | if flags["system-config"] then | ||
37 | return config_file(conf.system) | ||
38 | end | ||
39 | if flags["user-config"] then | ||
40 | return config_file(conf.user) | ||
41 | end | ||
42 | |||
43 | if flags["rock-trees"] then | ||
44 | for _, tree in ipairs(cfg.rocks_trees) do | ||
45 | if type(tree) == "string" then | ||
46 | util.printout(dir.normalize(tree)) | ||
47 | else | ||
48 | local name = tree.name and "\t"..tree.name or "" | ||
49 | util.printout(dir.normalize(tree.root)..name) | ||
50 | end | ||
51 | end | ||
52 | return true | ||
53 | end | ||
54 | |||
55 | return nil, "Please provide a flag for querying configuration values. "..util.see_help("config") | ||
56 | end | ||
57 | |||
58 | return config_cmd | ||
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 497ae84f..83c76c9c 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
@@ -193,9 +193,8 @@ function fetch.load_local_rockspec(filename, quick) | |||
193 | end | 193 | end |
194 | local globals = err | 194 | local globals = err |
195 | 195 | ||
196 | local ok, err = true, nil | ||
197 | if not quick then | 196 | if not quick then |
198 | ok, err = type_check.type_check_rockspec(rockspec, globals) | 197 | local ok, err = type_check.type_check_rockspec(rockspec, globals) |
199 | if not ok then | 198 | if not ok then |
200 | return nil, filename..": "..err | 199 | return nil, filename..": "..err |
201 | end | 200 | end |
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index e6c214ff..92458b2b 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
@@ -31,10 +31,8 @@ end | |||
31 | local function get_status(status) | 31 | local function get_status(status) |
32 | if status then | 32 | if status then |
33 | return "ok" | 33 | return "ok" |
34 | elseif status == false then | ||
35 | return "not found" | ||
36 | else | 34 | else |
37 | return "failed" | 35 | return "not found" |
38 | end | 36 | end |
39 | end | 37 | end |
40 | 38 | ||
@@ -47,7 +45,7 @@ function help.run(...) | |||
47 | local flags, command = util.parse_flags(...) | 45 | local flags, command = util.parse_flags(...) |
48 | 46 | ||
49 | if not command then | 47 | if not command then |
50 | local sys_file, sys_ok, home_file, home_ok = cfg.which_config() | 48 | local conf = cfg.which_config() |
51 | print_banner() | 49 | print_banner() |
52 | print_section("NAME") | 50 | print_section("NAME") |
53 | util.printout("\t"..program..[[ - ]]..program_description) | 51 | util.printout("\t"..program..[[ - ]]..program_description) |
@@ -83,9 +81,9 @@ function help.run(...) | |||
83 | print_section("CONFIGURATION") | 81 | print_section("CONFIGURATION") |
84 | util.printout("\tLua version: " .. cfg.lua_version) | 82 | util.printout("\tLua version: " .. cfg.lua_version) |
85 | util.printout("\tConfiguration files:") | 83 | util.printout("\tConfiguration files:") |
86 | util.printout("\t\tSystem: ".. dir.normalize(sys_file) .. " (" .. get_status(sys_ok) ..")") | 84 | util.printout("\t\tSystem: ".. dir.normalize(conf.system.file) .. " (" .. get_status(conf.system.ok) ..")") |
87 | if home_file then | 85 | if conf.user.file then |
88 | util.printout("\t\tUser : ".. dir.normalize(home_file) .. " (" .. get_status(home_ok) ..")\n") | 86 | util.printout("\t\tUser : ".. dir.normalize(conf.user.file) .. " (" .. get_status(conf.user.ok) ..")\n") |
89 | else | 87 | else |
90 | util.printout("\t\tUser : disabled in this LuaRocks installation.\n") | 88 | util.printout("\t\tUser : disabled in this LuaRocks installation.\n") |
91 | end | 89 | end |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 682c99e9..6a99b568 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
@@ -97,6 +97,9 @@ local supported_flags = { | |||
97 | ["lr-cpath"] = true, | 97 | ["lr-cpath"] = true, |
98 | ["lr-path"] = true, | 98 | ["lr-path"] = true, |
99 | ["lua-version"] = "<vers>", | 99 | ["lua-version"] = "<vers>", |
100 | ["lua-ver"] = true, | ||
101 | ["lua-incdir"] = true, | ||
102 | ["lua-libdir"] = true, | ||
100 | ["modules"] = true, | 103 | ["modules"] = true, |
101 | ["mversion"] = true, | 104 | ["mversion"] = true, |
102 | ["no-refresh"] = true, | 105 | ["no-refresh"] = true, |
@@ -114,15 +117,18 @@ local supported_flags = { | |||
114 | ["quick"] = true, | 117 | ["quick"] = true, |
115 | ["rock-dir"] = true, | 118 | ["rock-dir"] = true, |
116 | ["rock-tree"] = true, | 119 | ["rock-tree"] = true, |
120 | ["rock-trees"] = true, | ||
117 | ["rockspec"] = true, | 121 | ["rockspec"] = true, |
118 | ["server"] = "<server>", | 122 | ["server"] = "<server>", |
119 | ["skip-pack"] = true, | 123 | ["skip-pack"] = true, |
120 | ["source"] = true, | 124 | ["source"] = true, |
121 | ["summary"] = "\"<text>\"", | 125 | ["summary"] = "\"<text>\"", |
126 | ["system-config"] = true, | ||
122 | ["tag"] = "<tag>", | 127 | ["tag"] = "<tag>", |
123 | ["timeout"] = "<seconds>", | 128 | ["timeout"] = "<seconds>", |
124 | ["to"] = "<path>", | 129 | ["to"] = "<path>", |
125 | ["tree"] = "<path>", | 130 | ["tree"] = "<path>", |
131 | ["user-config"] = true, | ||
126 | ["verbose"] = true, | 132 | ["verbose"] = true, |
127 | ["version"] = true, | 133 | ["version"] = true, |
128 | } | 134 | } |
diff --git a/test/testing.sh b/test/testing.sh index 292c6389..8d972d4c 100755 --- a/test/testing.sh +++ b/test/testing.sh | |||
@@ -497,6 +497,17 @@ fail_write_rockspec_args_url() { $luarocks write_rockspec http://example.com/inv | |||
497 | test_write_rockspec_http() { $luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1; } | 497 | test_write_rockspec_http() { $luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1; } |
498 | test_write_rockspec_basedir() { $luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1; } | 498 | test_write_rockspec_basedir() { $luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1; } |
499 | 499 | ||
500 | fail_config_noflags() { $luarocks config; } | ||
501 | test_config_lua_incdir() { $luarocks config --lua-incdir; } | ||
502 | test_config_lua_libdir() { $luarocks config --lua-libdir; } | ||
503 | test_config_lua_ver() { $luarocks config --lua-ver; } | ||
504 | fail_config_system_config() { rm -f "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; } | ||
505 | test_config_system_config() { mkdir -p "$testing_lrprefix/etc/luarocks"; touch "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; err=$?; rm -f "$testing_lrprefix/etc/luarocks/config.lua"; return $err; } | ||
506 | fail_config_system_config_invalid() { mkdir -p "$testing_lrprefix/etc/luarocks"; echo "if if if" > "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; err=$?; rm -f "$testing_lrprefix/etc/luarocks/config.lua"; return $err; } | ||
507 | test_config_user_config() { $luarocks config --user-config; } | ||
508 | fail_config_user_config() { LUAROCKS_CONFIG="/missing_file.lua" $luarocks config --user-config; } | ||
509 | test_config_rock_trees() { $luarocks config --rock-trees; } | ||
510 | |||
500 | test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } | 511 | test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } |
501 | 512 | ||
502 | # Driver ######################################### | 513 | # Driver ######################################### |