diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-05-31 17:20:12 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-05-31 17:20:12 +0100 |
commit | 98763319d1169ede18cb0470672cc7acb8f0d679 (patch) | |
tree | 2a844716829df745102c7c5abdc074253f6d873b /lualib | |
parent | c0262caefb3cdc6c3792bfe871e64333aa89783d (diff) | |
download | rspamd-98763319d1169ede18cb0470672cc7acb8f0d679.tar.gz rspamd-98763319d1169ede18cb0470672cc7acb8f0d679.zip |
[Project] Deprecate and remove getopt library
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/getopt.lua | 50 | ||||
-rw-r--r-- | lualib/rspamadm/confighelp.lua | 18 | ||||
-rw-r--r-- | lualib/rspamadm/fuzzy_stat.lua | 25 |
3 files changed, 36 insertions, 57 deletions
diff --git a/lualib/getopt.lua b/lualib/getopt.lua deleted file mode 100644 index 20715c387..000000000 --- a/lualib/getopt.lua +++ /dev/null @@ -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 -} diff --git a/lualib/rspamadm/confighelp.lua b/lualib/rspamadm/confighelp.lua index 8f0fd2b7d..d477ff69b 100644 --- a/lualib/rspamadm/confighelp.lua +++ b/lualib/rspamadm/confighelp.lua @@ -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) diff --git a/lualib/rspamadm/fuzzy_stat.lua b/lualib/rspamadm/fuzzy_stat.lua index 20945bd4a..45e13bb60 100644 --- a/lualib/rspamadm/fuzzy_stat.lua +++ b/lualib/rspamadm/fuzzy_stat.lua @@ -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 |