@@ -1,50 +0,0 @@ | |||
local function insert_option(tab, name, value) | |||
if tab[name] then | |||
if type(tab[name]) == 'table' then | |||
table.insert(tab[name], value) | |||
else | |||
local old_val = tab[name] | |||
tab[name] = { | |||
old_val, | |||
value | |||
} | |||
end | |||
else | |||
tab[name] = value | |||
end | |||
end | |||
local function getopt(arg, options) | |||
local tab = {} | |||
for k, v in ipairs(arg) do | |||
if string.sub(v, 1, 2) == "--" then | |||
local x = string.find(v, "=", 1, true) | |||
if x then insert_option(tab, string.sub(v, 3, x - 1), string.sub(v, x + 1)) | |||
else tab[string.sub(v, 3)] = true | |||
end | |||
elseif string.sub(v, 1, 1) == "-" then | |||
local y = 2 | |||
local l = string.len(v) | |||
local jopt | |||
while (y <= l) do | |||
jopt = string.sub(v, y, y) | |||
if string.find(options, jopt, 1, true) then | |||
if y < l then | |||
insert_option(tab, jopt, string.sub(v, y + 1)) | |||
y = l | |||
else | |||
insert_option(tab, jopt, arg[k + 1]) | |||
end | |||
else | |||
tab[jopt] = true | |||
end | |||
y = y + 1 | |||
end | |||
end | |||
end | |||
return tab | |||
end | |||
return { | |||
getopt = getopt | |||
} |
@@ -1,4 +1,4 @@ | |||
local opts = {} | |||
local opts | |||
local known_attrs = { | |||
data = 1, | |||
example = 1, | |||
@@ -6,10 +6,20 @@ local known_attrs = { | |||
required = 1, | |||
default = 1, | |||
} | |||
local getopt = require "getopt" | |||
local argparse = require "argparse" | |||
local ansicolors = require "ansicolors" | |||
local parser = argparse() | |||
:name "rspamadm confighelp" | |||
:description "Shows help for the specified configuration options" | |||
:help_description_margin(32) | |||
parser:flag "--no-color" | |||
:description "Disable coloured output" | |||
parser:flag "--short" | |||
:description "Show only option names" | |||
parser:flag "--no-examples" | |||
:description "Do not show examples (impied by --short)" | |||
local function maybe_print_color(key) | |||
if not opts['no-color'] then | |||
return ansicolors.white .. key .. ansicolors.reset | |||
@@ -100,7 +110,7 @@ local function print_help(key, value, tabs) | |||
end | |||
return function(args, res) | |||
opts = getopt.getopt(args, '') | |||
opts = parser:parse(args) | |||
local sorted = sort_values(res) | |||
@@ -1,6 +1,27 @@ | |||
local util = require "rspamd_util" | |||
local opts = {} | |||
local argparse = require "argparse" | |||
local parser = argparse() | |||
:name "rspamadm confighelp" | |||
:description "Shows help for the specified configuration options" | |||
:help_description_margin(32) | |||
parser:flag "--no-ips" | |||
:description "No IPs stats" | |||
parser:flag "--no-keys" | |||
:description "No keys stats" | |||
parser:flag "--short" | |||
:description "Short output mode" | |||
parser:flag "-n --number" | |||
:description "Disable numbers humanization" | |||
parser:option "-s --sort" | |||
:description "Sort order" | |||
:convert { | |||
matched = "matched", | |||
errors = "errors", | |||
ip = "ip" | |||
} | |||
local function add_data(target, src) | |||
for k,v in pairs(src) do | |||
if k ~= 'ips' then | |||
@@ -143,13 +164,11 @@ local function print_result(r) | |||
return print_num(r) | |||
end | |||
local getopt = require "getopt" | |||
return function(args, res) | |||
local res_ips = {} | |||
local res_databases = {} | |||
local wrk = res['workers'] | |||
opts = getopt.getopt(args, '') | |||
opts = parser:parse(args) | |||
if wrk then | |||
for _,pr in pairs(wrk) do |
@@ -69,7 +69,7 @@ rspamadm_confighelp_help (gboolean full_help, const struct rspamadm_command *cmd | |||
"-j: output pretty formatted JSON\n" | |||
"-k: search by keyword in doc string\n" | |||
"-P: use specific Lua plugins path\n" | |||
"--no-color: show colored output\n" | |||
"--no-color: disable coloured output\n" | |||
"--short: show only option names\n" | |||
"--no-examples: do not show examples (impied by --short)\n" | |||
"--help: shows available options and commands"; |