aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xPolygLua.lua21
1 files 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 @@
2 2
3--[[ PolygLua. Gluing things onto Lua, making it a polyglot language. 3--[[ PolygLua. Gluing things onto Lua, making it a polyglot language.
4 4
5TODO - Allow -abc style, expand to -a -b -c.
6
7TODO - Make the parsing recursive. So the command "--fancy" could have it's own options table. 5TODO - Make the parsing recursive. So the command "--fancy" could have it's own options table.
8 --fancy option0 opt1=foo 'Random string!' --somethingElse 6 --fancy option0 opt1=foo 'Random string!' --somethingElse
9 When to stop and hand back? First time we see a ' -bar' or ' --foo'? 7 When to stop and hand back? First time we see a ' -bar' or ' --foo'?
@@ -49,7 +47,7 @@ local optionsCommon =
49 os.exit(0) 47 os.exit(0)
50 end 48 end
51 }, 49 },
52 ['--version'] = {help = 'Print the version details.', 50 version = {help = 'Print the version details.',
53 func = function(self, options, a, args, i) 51 func = function(self, options, a, args, i)
54 print('This is version ' ..Version .. ' of ' .. args[0]) 52 print('This is version ' ..Version .. ' of ' .. args[0])
55 os.exit(0) 53 os.exit(0)
@@ -68,7 +66,6 @@ local optionsCommon =
68 end 66 end
69 }, 67 },
70} 68}
71optionsCommon['--help'] = optionsCommon['help']
72 69
73_.usage = function(args, options, all) 70_.usage = function(args, options, all)
74 local h = '' 71 local h = ''
@@ -124,12 +121,24 @@ _.parse = function(args, options, confFile)
124 if 0 ~= #args then 121 if 0 ~= #args then
125 for i,a in ipairs(args) do 122 for i,a in ipairs(args) do
126 D('Argument ' .. i .. ' = ' .. a) 123 D('Argument ' .. i .. ' = ' .. a)
124 local ds = 0
125 if ('-' == a:sub(1, 1)) and ('-' ~= a:sub(2, 2)) then ds = 1 end
126 if '--' == a:sub(1, 2) then ds = 2; a = a:sub(3, -1) end
127 local s, e = a:find("=") 127 local s, e = a:find("=")
128 local k , v
128 if nil == s then 129 if nil == s then
129 e = 0 130 e = 0
130 o = doIt(a:sub(1, e - 1), nil, a, args, i) 131 v = nil
132 else
133 v = a:sub(e + 1, -1)
134 end
135 k = a:sub(1, e - 1)
136 if 1 == ds then
137 for j = 2, #k do
138 o = doIt('-' .. k:sub(j, j), v, a, args, i)
139 end
131 else 140 else
132 o = doIt(a:sub(1, e - 1), a:sub(e + 1, -1), a, args, i) 141 o = doIt(k, v, a, args, i)
133 end 142 end
134 end 143 end
135 end 144 end