diff options
Diffstat (limited to '')
| -rwxr-xr-x | _.lua | 45 |
1 files changed, 37 insertions, 8 deletions
| @@ -6,13 +6,38 @@ local _ = {} | |||
| 6 | _.version = '0.0 crap' | 6 | _.version = '0.0 crap' |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | D = function(s) print('DEBUG ' .. s) end | 9 | D = function(s) print('DEBUG ' .. s); io.flush() end |
| 10 | I = function(s) print('INFO ' .. s) end | 10 | I = function(s) print('INFO ' .. s); io.flush() end |
| 11 | T = function(s) print('TIMEOUT ' .. s) end | 11 | T = function(s) print('TIMEOUT ' .. s); io.flush() end |
| 12 | W = function(s) print('WARNING ' .. s) end | 12 | W = function(s) print('WARNING ' .. s); io.flush() end |
| 13 | E = function(s) print('ERROR ' .. s) end | 13 | E = function(s) print('ERROR ' .. s); io.flush() end |
| 14 | C = function(s) print('CRITICAL ' .. s) end | 14 | C = function(s) print('CRITICAL ' .. s); io.flush() end |
| 15 | |||
| 16 | |||
| 17 | _.parseArgs = function(options, args) | ||
| 18 | local o = nil | ||
| 19 | if 0 ~= #args then | ||
| 20 | for i,a in pairs(args) do | ||
| 21 | local s, e = a:find("=") | ||
| 22 | if nil == s then e = 0 end | ||
| 23 | opt = a:sub(1, e - 1) | ||
| 24 | o = options[opt] | ||
| 25 | D('Argument ' .. i .. ' = ' .. a) | ||
| 26 | if nil ~= o then | ||
| 27 | o:func(a, args, i) | ||
| 28 | end | ||
| 29 | end | ||
| 30 | end | ||
| 15 | 31 | ||
| 32 | if nil == o then | ||
| 33 | local h = '' | ||
| 34 | for k, v in pairs(options) do | ||
| 35 | h = h .. k .. '|' | ||
| 36 | end | ||
| 37 | print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}') | ||
| 38 | os.exit(0) | ||
| 39 | end | ||
| 40 | end | ||
| 16 | 41 | ||
| 17 | _.runnable = function(c) | 42 | _.runnable = function(c) |
| 18 | return ( 0 == __('which ' .. c):Do().status ) | 43 | return ( 0 == __('which ' .. c):Do().status ) |
| @@ -66,8 +91,12 @@ __ = function(c) | |||
| 66 | elseif 'string' == type(c) then | 91 | elseif 'string' == type(c) then |
| 67 | for l in string.gmatch(c, "\n*([^\n]+)\n*") do | 92 | for l in string.gmatch(c, "\n*([^\n]+)\n*") do |
| 68 | if '' ~= l then | 93 | if '' ~= l then |
| 69 | n = n + 1 | 94 | if ('#!' == l:sub(1,2)) and (n == 0) then |
| 70 | exe.cmd = exe.cmd .. l .. ' ; ' | 95 | -- TODO - should do something with this, not just run it as shell stuff. |
| 96 | else | ||
| 97 | n = n + 1 | ||
| 98 | exe.cmd = exe.cmd .. l .. ' ; ' | ||
| 99 | end | ||
| 71 | end | 100 | end |
| 72 | end | 101 | end |
| 73 | end | 102 | end |
