aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-06-19 00:00:23 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-06-28 17:28:40 -0300
commitc0f8505f54e9e8b7d2525c60dd338ebaf2f0826a (patch)
treeba4ee9de63a9a38734a9b1ce451130797bf5aae2 /src
parent27a71b74f5317185fb4ce82f48ce0f786bc3cd2c (diff)
downloadluarocks-c0f8505f54e9e8b7d2525c60dd338ebaf2f0826a.tar.gz
luarocks-c0f8505f54e9e8b7d2525c60dd338ebaf2f0826a.tar.bz2
luarocks-c0f8505f54e9e8b7d2525c60dd338ebaf2f0826a.zip
config: print out full config when given no arguments
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/cmd/config.lua75
1 files changed, 74 insertions, 1 deletions
diff --git a/src/luarocks/cmd/config.lua b/src/luarocks/cmd/config.lua
index e18ab0b8..577da1ad 100644
--- a/src/luarocks/cmd/config.lua
+++ b/src/luarocks/cmd/config.lua
@@ -5,6 +5,7 @@ local config_cmd = {}
5local cfg = require("luarocks.core.cfg") 5local cfg = require("luarocks.core.cfg")
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
8local fun = require("luarocks.fun")
8 9
9config_cmd.help_summary = "Query information about the LuaRocks configuration." 10config_cmd.help_summary = "Query information about the LuaRocks configuration."
10config_cmd.help_arguments = "<flag>" 11config_cmd.help_arguments = "<flag>"
@@ -35,6 +36,77 @@ local function config_file(conf)
35 end 36 end
36end 37end
37 38
39local function printf(fmt, ...)
40 print((fmt):format(...))
41end
42
43local cfg_maps = {
44 external_deps_patterns = true,
45 external_deps_subdirs = true,
46 rocks_provided = true,
47 rocks_provided_3_0 = true,
48 runtime_external_deps_patterns = true,
49 runtime_external_deps_subdirs = true,
50 upload = true,
51 variables = true,
52}
53
54local cfg_arrays = {
55 disabled_servers = true,
56 external_deps_dirs = true,
57 rocks_trees = true,
58 rocks_servers = true,
59}
60
61local function print_config(cfg)
62 for k, v in util.sortedpairs(cfg) do
63 if type(v) == "string" or type(v) == "boolean" or type(v) == "number" then
64 printf("%s = %q", k, v)
65 elseif type(v) == "function" then
66 -- skip
67 elseif cfg_maps[k] then
68 printf("%s = {", k)
69 for kk, vv in util.sortedpairs(v) do
70 local keyfmt = kk:match("^[a-zA-Z_][a-zA-Z0-9_]*$") and "%s" or "[%q]"
71 if type(vv) == "table" then
72 local qvs = fun.map(vv, function(e) return string.format("%q", e) end)
73 printf(" "..keyfmt.." = {%s},", kk, table.concat(qvs, ", "))
74 else
75 printf(" "..keyfmt.." = %q,", kk, vv)
76 end
77 end
78 printf("}")
79 elseif cfg_arrays[k] then
80 if #v == 0 then
81 printf("%s = {}", k)
82 else
83 printf("%s = {", k)
84 for _, vv in ipairs(v) do
85 if type(vv) == "string" then
86 printf(" %q,", vv)
87 elseif type(vv) == "table" then
88 printf(" {")
89 if next(vv) == 1 then
90 for _, v3 in ipairs(vv) do
91 printf(" %q,", v3)
92 end
93 else
94 for k3, v3 in util.sortedpairs(vv) do
95 local keyfmt = tostring(k3):match("^[a-zA-Z_][a-zA-Z0-9_]*$") and "%s" or "[%q]"
96 printf(" "..keyfmt.." = %q,", k3, v3)
97 end
98 end
99 printf(" },")
100 end
101 end
102 printf("}")
103 end
104 else
105 error(k)
106 end
107 end
108end
109
38--- Driver function for "config" command. 110--- Driver function for "config" command.
39-- @return boolean: True if succeeded, nil on errors. 111-- @return boolean: True if succeeded, nil on errors.
40function config_cmd.command(flags) 112function config_cmd.command(flags)
@@ -69,7 +141,8 @@ function config_cmd.command(flags)
69 return true 141 return true
70 end 142 end
71 143
72 return nil, "Please provide a flag for querying configuration values. "..util.see_help("config") 144 print_config(cfg)
145 return true
73end 146end
74 147
75return config_cmd 148return config_cmd