diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-19 00:00:23 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-28 17:28:40 -0300 |
commit | c0f8505f54e9e8b7d2525c60dd338ebaf2f0826a (patch) | |
tree | ba4ee9de63a9a38734a9b1ce451130797bf5aae2 /src | |
parent | 27a71b74f5317185fb4ce82f48ce0f786bc3cd2c (diff) | |
download | luarocks-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.lua | 75 |
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 = {} | |||
5 | local cfg = require("luarocks.core.cfg") | 5 | local cfg = require("luarocks.core.cfg") |
6 | local util = require("luarocks.util") | 6 | local util = require("luarocks.util") |
7 | local dir = require("luarocks.dir") | 7 | local dir = require("luarocks.dir") |
8 | local fun = require("luarocks.fun") | ||
8 | 9 | ||
9 | config_cmd.help_summary = "Query information about the LuaRocks configuration." | 10 | config_cmd.help_summary = "Query information about the LuaRocks configuration." |
10 | config_cmd.help_arguments = "<flag>" | 11 | config_cmd.help_arguments = "<flag>" |
@@ -35,6 +36,77 @@ local function config_file(conf) | |||
35 | end | 36 | end |
36 | end | 37 | end |
37 | 38 | ||
39 | local function printf(fmt, ...) | ||
40 | print((fmt):format(...)) | ||
41 | end | ||
42 | |||
43 | local 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 | |||
54 | local cfg_arrays = { | ||
55 | disabled_servers = true, | ||
56 | external_deps_dirs = true, | ||
57 | rocks_trees = true, | ||
58 | rocks_servers = true, | ||
59 | } | ||
60 | |||
61 | local 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 | ||
108 | end | ||
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. |
40 | function config_cmd.command(flags) | 112 | function 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 | ||
73 | end | 146 | end |
74 | 147 | ||
75 | return config_cmd | 148 | return config_cmd |