aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-05-18 14:35:19 -0300
committerHisham Muhammad <hisham@gobolinux.org>2015-05-18 14:35:19 -0300
commit4462ca51ee10363916c29c071942c15f424913e6 (patch)
tree8b7617b3be89e413ab92208dea0ae33132153617 /src
parentb80244b566780c8095a75b06fe7669b1b0bcd7c0 (diff)
downloadluarocks-4462ca51ee10363916c29c071942c15f424913e6.tar.gz
luarocks-4462ca51ee10363916c29c071942c15f424913e6.tar.bz2
luarocks-4462ca51ee10363916c29c071942c15f424913e6.zip
Add `luarocks config` command for querying LuaRocks settings.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/bin/luarocks1
-rw-r--r--src/luarocks/cfg.lua30
-rw-r--r--src/luarocks/config_cmd.lua58
-rw-r--r--src/luarocks/fetch.lua3
-rw-r--r--src/luarocks/help.lua12
-rw-r--r--src/luarocks/util.lua6
6 files changed, 91 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
32command_line.run_command(...) 33command_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 = {}
146cfg.rocks_trees = {} 146cfg.rocks_trees = {}
147 147
148sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" 148sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua"
149local err, errcode 149do
150sys_config_ok, err, errcode = persist.load_into_table(sys_config_file, cfg) 150 local err, errcode
151
152if (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)
155end 152 if (not sys_config_ok) and errcode == "open" then -- file not found, so try alternate file
156if (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
159end 160end
160 161
161local env_for_config_file = { 162local env_for_config_file = {
@@ -590,7 +591,16 @@ function cfg.init_package_paths()
590end 591end
591 592
592function cfg.which_config() 593function 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 }
594end 604end
595 605
596cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch 606cfg.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.
3local config_cmd = {}
4
5local cfg = require("luarocks.cfg")
6local util = require("luarocks.util")
7local dir = require("luarocks.dir")
8
9local 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
16end
17
18--- Driver function for "config" command.
19-- @return boolean: True if succeeded, nil on errors.
20function 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")
56end
57
58return 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
31local function get_status(status) 31local 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
39end 37end
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}