From 69a64dd62073df655e26c27ed5a225e2eb3329d0 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 7 May 2014 10:38:04 +0100 Subject: [PATCH] elua: a bit more informative getopt plus better arg handling when calling to xgettext --- src/bin/elua/modules/getopt.lua | 4 ++-- src/bin/elua/xgettext.lua | 38 +++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/bin/elua/modules/getopt.lua b/src/bin/elua/modules/getopt.lua index 393a13e9ed..343f8cb59f 100644 --- a/src/bin/elua/modules/getopt.lua +++ b/src/bin/elua/modules/getopt.lua @@ -50,7 +50,7 @@ local parse_l = function(opts, opt, descs, args, parser) if not rets or #rets == 0 then rets = { optval } end local optn = desc.alias or desc[1] or desc[2] opts[#opts + 1] = { optn, short = desc[1], long = desc[2], - alias = desc.alias, unpack(rets) } + alias = desc.alias, val = optval, unpack(rets) } local optret = #rets > 1 and rets or rets[1] if desc.list then desc.list[#desc.list + 1] = optret @@ -85,7 +85,7 @@ local parse_s = function(opts, optstr, descs, args, parser) if not rets or #rets == 0 then rets = { optval } end local optn = desc.alias or desc[1] or desc[2] opts[#opts + 1] = { optn, short = desc[1], long = desc[2], - alias = desc.alias, unpack(rets) } + alias = desc.alias, val = optval, unpack(rets) } local optret = #rets > 1 and rets or rets[1] if desc.list then desc.list[#desc.list + 1] = optret diff --git a/src/bin/elua/xgettext.lua b/src/bin/elua/xgettext.lua index ecba552bdb..922378de01 100644 --- a/src/bin/elua/xgettext.lua +++ b/src/bin/elua/xgettext.lua @@ -163,11 +163,41 @@ if not opts or opts["h"] or opts["v"] then return true end +local build_opt = function(opt) + local buf = {} + if opt.short then + buf[1] = "-" + buf[2] = opt.short + if opt.val then + buf[3] = opt.val + end + else + buf[1] = "--" + buf[2] = opt.long + if opt.val then + buf[3] = "=" + buf[4] = opt.val + end + end + return table.concat(buf) +end + +local onlylua = opts["L"] and opts["L"]:lower() == "lua" +local neverlua = opts["L"] and opts["L"]:lower() ~= "lua" + local hasxgettext = os.getenv("XGETTEXT") -if hasxgettext then - local gargs = { hasxgettext, "--join-existing" } - for i = 1, #opts do - gargs[#gargs + 1] = arg[i] +if hasxgettext and not onlylua then + local gargs = { hasxgettext } + if not opts["j"] and not neverlua then + for i, v in ipairs(args) do + if v:match("^.+%.lua$") then + gargs[#gargs + 1] = "--join-existing" + break + end + end + end + for i, opt in ipairs(opts) do + gargs[#gargs + 1] = build_opt(opt) end for i, v in ipairs(args) do if not v:match("^.+%.lua$") then