From 5dc70f96c316706a61d591bd555ccac154a9f150 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Sun, 27 Oct 2024 11:36:06 +1000 Subject: Allow -abc style, expand to -a -b -c, and can put -- in front of any option. --- PolygLua.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/PolygLua.lua b/PolygLua.lua index 003702f..ed14fc5 100755 --- a/PolygLua.lua +++ b/PolygLua.lua @@ -2,8 +2,6 @@ --[[ PolygLua. Gluing things onto Lua, making it a polyglot language. -TODO - Allow -abc style, expand to -a -b -c. - TODO - Make the parsing recursive. So the command "--fancy" could have it's own options table. --fancy option0 opt1=foo 'Random string!' --somethingElse When to stop and hand back? First time we see a ' -bar' or ' --foo'? @@ -49,7 +47,7 @@ local optionsCommon = os.exit(0) end }, - ['--version'] = {help = 'Print the version details.', + version = {help = 'Print the version details.', func = function(self, options, a, args, i) print('This is version ' ..Version .. ' of ' .. args[0]) os.exit(0) @@ -68,7 +66,6 @@ local optionsCommon = end }, } -optionsCommon['--help'] = optionsCommon['help'] _.usage = function(args, options, all) local h = '' @@ -124,12 +121,24 @@ _.parse = function(args, options, confFile) if 0 ~= #args then for i,a in ipairs(args) do D('Argument ' .. i .. ' = ' .. a) + local ds = 0 + if ('-' == a:sub(1, 1)) and ('-' ~= a:sub(2, 2)) then ds = 1 end + if '--' == a:sub(1, 2) then ds = 2; a = a:sub(3, -1) end local s, e = a:find("=") + local k , v if nil == s then e = 0 - o = doIt(a:sub(1, e - 1), nil, a, args, i) + v = nil + else + v = a:sub(e + 1, -1) + end + k = a:sub(1, e - 1) + if 1 == ds then + for j = 2, #k do + o = doIt('-' .. k:sub(j, j), v, a, args, i) + end else - o = doIt(a:sub(1, e - 1), a:sub(e + 1, -1), a, args, i) + o = doIt(k, v, a, args, i) end end end -- cgit v1.1