From ae4daa54012fbc67557106f9adc3f7ad90cd5d47 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 30 Apr 2014 11:05:58 +0100 Subject: [PATCH] elua: also use hash fields to store resulting optional arguments --- src/bin/elua/modules/getopt.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/elua/modules/getopt.lua b/src/bin/elua/modules/getopt.lua index c9dfa745af..b10f46a30b 100644 --- a/src/bin/elua/modules/getopt.lua +++ b/src/bin/elua/modules/getopt.lua @@ -48,7 +48,9 @@ local parse_l = function(opts, opt, descs, args, parser) local rets if desc.callback then rets = { desc:callback(parser, optval) } end if not rets or #rets == 0 then rets = { optval } end - opts[#opts + 1] = { desc.alias or desc[1] or desc[2], unpack(rets) } + local optn = desc.alias or desc[1] or desc[2] + opts[#opts + 1] = { optn, unpack(rets) } + opts[optn] = #rets > 1 and rets or rets[1] return opts, args end @@ -74,7 +76,9 @@ local parse_s = function(opts, optstr, descs, args, parser) local rets if desc.callback then rets = { desc:callback(parser, optval) } end if not rets or #rets == 0 then rets = { optval } end - opts[#opts + 1] = { desc.alias or desc[1] or desc[2], unpack(rets) } + local optn = desc.alias or desc[1] or desc[2] + opts[#opts + 1] = { optn, unpack(rets) } + opts[optn] = #rets > 1 and rets or rets[1] end return opts, args end