aboutsummaryrefslogtreecommitdiffstats
path: root/_.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-x_.lua28
1 files changed, 24 insertions, 4 deletions
diff --git a/_.lua b/_.lua
index 5c8963b..a2607f5 100755
--- a/_.lua
+++ b/_.lua
@@ -26,12 +26,29 @@ E = function(s) print('ERROR ' .. s); io.flush() end
26C = function(s) print('CRITICAL ' .. s); io.flush() end 26C = function(s) print('CRITICAL ' .. s); io.flush() end
27 27
28 28
29-- TODO - move common stuff like -q, -v, --help, --version to an internal options table we scan as well. 29local optionsCommon =
30{
31 help = {help = 'Print the help text',
32 func = function(self, a, args, i)
33 print(Help)
34 os.exit(0)
35 end
36 },
37 ['--version'] = {help = 'Print the version details.',
38 func = function(self, a, args, i)
39 print('This is version ' ..Version .. ' of ' .. args[0])
40 os.exit(0)
41 end
42 },
43}
44optionsCommon['--help'] = optionsCommon['help']
45
30_.parse = function(args, options, confFile) 46_.parse = function(args, options, confFile)
31 local o = nil 47 local o = nil
32 48
33 local doIt = function(name, val, a, args, i) 49 local doIt = function(name, val, a, args, i)
34 local o = options[name] 50 local o = options[name]
51 if nil == o then o = optionsCommon[name] end
35 if nil ~= o then 52 if nil ~= o then
36 if nil ~= val then o.value = val; D(name .. ' = ' .. tostring(val)) end 53 if nil ~= val then o.value = val; D(name .. ' = ' .. tostring(val)) end
37 if nil ~= o.func then o:func(a, args, i) end 54 if nil ~= o.func then o:func(a, args, i) end
@@ -48,8 +65,8 @@ _.parse = function(args, options, confFile)
48 h:close() 65 h:close()
49 local ar = dofile(p) 66 local ar = dofile(p)
50 for k, w in pairs(ar) do 67 for k, w in pairs(ar) do
51 o = doIt(k, w, k .. '=' .. tostring(w), args, i) 68 doIt(k, w, k .. '=' .. tostring(w), args, i)
52 if nil == o then E('config variable not found ' .. k .. ' = ' .. tostring(w)) end 69 if nil == o then W('config variable not found ' .. k .. ' = ' .. tostring(w)) end
53 end 70 end
54 end 71 end
55 end 72 end
@@ -71,7 +88,10 @@ _.parse = function(args, options, confFile)
71 if nil == o then 88 if nil == o then
72 local h = '' 89 local h = ''
73 for k, v in pairs(options) do 90 for k, v in pairs(options) do
74 h = h .. k .. ' | ' 91 if 'table' == type(v) then h = h .. k .. ' | ' end
92 end
93 for k, v in pairs(optionsCommon) do
94 if 'table' == type(v) then h = h .. k .. ' | ' end
75 end 95 end
76 print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}') 96 print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}')
77 os.exit(0) 97 os.exit(0)