diff options
author | dvs1 | 2024-10-25 17:03:00 +1000 |
---|---|---|
committer | dvs1 | 2024-10-25 17:03:00 +1000 |
commit | f28129b5c96317a0486592011db8e02655b18e1a (patch) | |
tree | ca38e8d662dd33b58667825605dd10030b52b883 /_.lua | |
parent | Turn on debug mode, or pretend to, this bit isn't functional yet. (diff) | |
download | JackOnAllDevices-f28129b5c96317a0486592011db8e02655b18e1a.zip JackOnAllDevices-f28129b5c96317a0486592011db8e02655b18e1a.tar.gz JackOnAllDevices-f28129b5c96317a0486592011db8e02655b18e1a.tar.bz2 JackOnAllDevices-f28129b5c96317a0486592011db8e02655b18e1a.tar.xz |
Help command now prints out full usage as well.
Diffstat (limited to '')
-rwxr-xr-x | _.lua | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -28,14 +28,15 @@ C = function(s) print('CRITICAL ' .. s); io.flush() end | |||
28 | 28 | ||
29 | local optionsCommon = | 29 | local 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 | } |
44 | optionsCommon['--help'] = optionsCommon['help'] | 45 | optionsCommon['--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 | ||
68 | end | ||
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 |
98 | end | 115 | end |