aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-29 17:48:59 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-29 17:48:59 +0000
commitd80d4e366703ed35b87c30e554781058b296095b (patch)
tree54ce9f895213f2ce9572f487c0706702aff87e60
parent6c9457f6d281b67d25443e430ad4a4512f43e98b (diff)
downloadrspamd-d80d4e366703ed35b87c30e554781058b296095b.tar.gz
rspamd-d80d4e366703ed35b87c30e554781058b296095b.zip
Add sorting for configuration helper
-rw-r--r--src/rspamadm/confighelp.lua53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/rspamadm/confighelp.lua b/src/rspamadm/confighelp.lua
index 28c0e2897..223de294a 100644
--- a/src/rspamadm/confighelp.lua
+++ b/src/rspamadm/confighelp.lua
@@ -18,6 +18,46 @@ local function maybe_print_color(key)
end
end
+local function sort_values(tbl, opts)
+ local res = {}
+ for k, v in pairs(tbl) do
+ table.insert(res, { key = k, value = v })
+ end
+
+ -- Sort order
+ local order = {
+ options = 1,
+ dns = 2,
+ upstream = 3,
+ logging = 4,
+ metric = 5,
+ composite = 6,
+ classifier = 7,
+ modules = 8,
+ lua = 9,
+ worker = 10,
+ workers = 11,
+ }
+
+ table.sort(res, function(a, b)
+ local oa = order[a['key']]
+ local ob = order[b['key']]
+
+ if oa and ob then
+ return oa < ob
+ elseif oa then
+ return -1 < 0
+ elseif ob then
+ return 1 < 0
+ else
+ return a['key'] < b['key']
+ end
+
+ end)
+
+ return res
+end
+
local function print_help(key, value, tabs)
print(string.format('%sConfiguration element: %s', tabs, maybe_print_color(key)))
@@ -34,10 +74,11 @@ local function print_help(key, value, tabs)
end
end
- for k, v in pairs(value) do
- if not known_attrs[k] then
+ local sorted = sort_values(value)
+ for i, v in ipairs(sorted) do
+ if not known_attrs[v['key']] then
-- We need to go deeper
- print_help(k, v, tabs .. '\t')
+ print_help(v['key'], v['value'], tabs .. '\t')
end
end
end
@@ -45,8 +86,10 @@ end
return function(args, res)
opts = getopt(args, '')
- for k,v in pairs(res) do
- print_help(k, v, '')
+ local sorted = sort_values(res)
+
+ for i,v in ipairs(sorted) do
+ print_help(v['key'], v['value'], '')
print('')
end
end