diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-03-03 13:10:11 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-03-03 13:10:11 +0000 |
commit | c711b12514d29da6123247e39ab8a12e8633a393 (patch) | |
tree | 982b63a7e274f7a8ad25c84344f3483cce1a7b2b /lualib | |
parent | 63a9a0b5a875a2e33d61906eb62b0afa08e24d52 (diff) | |
download | rspamd-c711b12514d29da6123247e39ab8a12e8633a393.tar.gz rspamd-c711b12514d29da6123247e39ab8a12e8633a393.zip |
[Minor] Support multiple arguments in lua getopt
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/rspamadm/getopt.lua | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lualib/rspamadm/getopt.lua b/lualib/rspamadm/getopt.lua index bd0a2f67e..c36774092 100644 --- a/lualib/rspamadm/getopt.lua +++ b/lualib/rspamadm/getopt.lua @@ -1,9 +1,25 @@ +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 tab[string.sub(v, 3, x - 1)] = string.sub(v, x + 1) + 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 @@ -14,10 +30,10 @@ local function getopt(arg, options) jopt = string.sub(v, y, y) if string.find(options, jopt, 1, true) then if y < l then - tab[jopt] = string.sub(v, y + 1) + insert_option(tab, jopt, string.sub(v, y + 1)) y = l else - tab[jopt] = arg[k + 1] + insert_option(tab, jopt, arg[k + 1]) end else tab[jopt] = true |