From 8e7c1c219589120f2088ce9924907c7d66492312 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Wed, 23 Oct 2024 19:16:01 +1000 Subject: New options parsing stuff. --- _.lua | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to '_.lua') diff --git a/_.lua b/_.lua index 19b73b4..12d7461 100755 --- a/_.lua +++ b/_.lua @@ -6,13 +6,38 @@ local _ = {} _.version = '0.0 crap' -D = function(s) print('DEBUG ' .. s) end -I = function(s) print('INFO ' .. s) end -T = function(s) print('TIMEOUT ' .. s) end -W = function(s) print('WARNING ' .. s) end -E = function(s) print('ERROR ' .. s) end -C = function(s) print('CRITICAL ' .. s) end +D = function(s) print('DEBUG ' .. s); io.flush() end +I = function(s) print('INFO ' .. s); io.flush() end +T = function(s) print('TIMEOUT ' .. s); io.flush() end +W = function(s) print('WARNING ' .. s); io.flush() end +E = function(s) print('ERROR ' .. s); io.flush() end +C = function(s) print('CRITICAL ' .. s); io.flush() end + + +_.parseArgs = function(options, args) + local o = nil + if 0 ~= #args then + for i,a in pairs(args) do + local s, e = a:find("=") + if nil == s then e = 0 end + opt = a:sub(1, e - 1) + o = options[opt] + D('Argument ' .. i .. ' = ' .. a) + if nil ~= o then + o:func(a, args, i) + end + end + end + if nil == o then + local h = '' + for k, v in pairs(options) do + h = h .. k .. '|' + end + print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}') + os.exit(0) + end +end _.runnable = function(c) return ( 0 == __('which ' .. c):Do().status ) @@ -66,8 +91,12 @@ __ = function(c) elseif 'string' == type(c) then for l in string.gmatch(c, "\n*([^\n]+)\n*") do if '' ~= l then - n = n + 1 - exe.cmd = exe.cmd .. l .. ' ; ' + if ('#!' == l:sub(1,2)) and (n == 0) then + -- TODO - should do something with this, not just run it as shell stuff. + else + n = n + 1 + exe.cmd = exe.cmd .. l .. ' ; ' + end end end end -- cgit v1.1