aboutsummaryrefslogtreecommitdiffstats
path: root/_.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-x_.lua41
1 files changed, 29 insertions, 12 deletions
diff --git a/_.lua b/_.lua
index 03761d2..945f4f2 100755
--- a/_.lua
+++ b/_.lua
@@ -28,14 +28,15 @@ C = function(s) print('CRITICAL ' .. s); io.flush() end
28 28
29local optionsCommon = 29local optionsCommon =
30{ 30{
31 help = {help = 'Print the help text', 31 help = {help = 'Print the help text.',
32 func = function(self, a, args, i) 32 func = function(self, options, a, args, i)
33 print(Help) 33 print(Help)
34 _.usage(args, options, true)
34 os.exit(0) 35 os.exit(0)
35 end 36 end
36 }, 37 },
37 ['--version'] = {help = 'Print the version details.', 38 ['--version'] = {help = 'Print the version details.',
38 func = function(self, a, args, i) 39 func = function(self, options, a, args, i)
39 print('This is version ' ..Version .. ' of ' .. args[0]) 40 print('This is version ' ..Version .. ' of ' .. args[0])
40 os.exit(0) 41 os.exit(0)
41 end 42 end
@@ -43,6 +44,29 @@ local optionsCommon =
43} 44}
44optionsCommon['--help'] = optionsCommon['help'] 45optionsCommon['--help'] = optionsCommon['help']
45 46
47_.usage = function(args, options, all)
48 local h = ''
49 for k, v in pairs(options) do
50 if 'table' == type(v) then h = h .. k .. ' | ' end
51 end
52 for k, v in pairs(optionsCommon) do
53 if 'table' == type(v) then h = h .. k .. ' | ' end
54 end
55 print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}')
56 if true == all then
57 for k, v in pairs(options) do
58 if 'table' == type(v) then
59 if nil ~= v.help then print(k .. '\t\t' .. v.help) end
60 end
61 end
62 for k, v in pairs(optionsCommon) do
63 if 'table' == type(v) then
64 if nil ~= v.help then print(k .. '\t\t' .. v.help) end
65 end
66 end
67 end
68end
69
46_.parse = function(args, options, confFile) 70_.parse = function(args, options, confFile)
47 local o = nil 71 local o = nil
48 72
@@ -51,7 +75,7 @@ _.parse = function(args, options, confFile)
51 if nil == o then o = optionsCommon[name] end 75 if nil == o then o = optionsCommon[name] end
52 if nil ~= o then 76 if nil ~= o then
53 if nil ~= val then o.value = val; D(name .. ' = ' .. tostring(val)) end 77 if nil ~= val then o.value = val; D(name .. ' = ' .. tostring(val)) end
54 if nil ~= o.func then o:func(a, args, i) end 78 if nil ~= o.func then o:func(options, a, args, i) end
55 end 79 end
56 return o 80 return o
57 end 81 end
@@ -85,14 +109,7 @@ _.parse = function(args, options, confFile)
85 end 109 end
86 110
87 if nil == o then 111 if nil == o then
88 local h = '' 112 _.usage(args, options)
89 for k, v in pairs(options) do
90 if 'table' == type(v) then h = h .. k .. ' | ' end
91 end
92 for k, v in pairs(optionsCommon) do
93 if 'table' == type(v) then h = h .. k .. ' | ' end
94 end
95 print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}')
96 os.exit(0) 113 os.exit(0)
97 end 114 end
98end 115end