elua: a bit more informative getopt plus better arg handling when calling to xgettext

This commit is contained in:
Daniel Kolesa 2014-05-07 10:38:04 +01:00 committed by Daniel Kolesa
parent 344c1cbaf1
commit 69a64dd620
2 changed files with 36 additions and 6 deletions

View File

@ -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

View File

@ -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