diff options
| -rwxr-xr-x | _.lua | 41 | ||||
| -rwxr-xr-x | aataaj.lua | 2 | ||||
| -rwxr-xr-x | test_.lua | 2 |
3 files changed, 31 insertions, 14 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 |
| @@ -107,7 +107,7 @@ local options = | |||
| 107 | STOP = | 107 | STOP = |
| 108 | { | 108 | { |
| 109 | help = 'Command to stop the JACK stuff, for users.', | 109 | help = 'Command to stop the JACK stuff, for users.', |
| 110 | func = function(self, a, args, i) | 110 | func = function(self, options, a, args, i) |
| 111 | _.killEmAll{'qsynth'} | 111 | _.killEmAll{'qsynth'} |
| 112 | __[[#!/bin/bash | 112 | __[[#!/bin/bash |
| 113 | a2j_control --stop | 113 | a2j_control --stop |
| @@ -21,7 +21,7 @@ local options = | |||
| 21 | stop = {help = 'Command to stop the scanning process, for Sys V init.',}, | 21 | stop = {help = 'Command to stop the scanning process, for Sys V init.',}, |
| 22 | JACK = {help = 'Command to start the JACK stuff, for users.',}, | 22 | JACK = {help = 'Command to start the JACK stuff, for users.',}, |
| 23 | STOP = {help = 'Command to stop the JACK stuff, for users.', | 23 | STOP = {help = 'Command to stop the JACK stuff, for users.', |
| 24 | func = function(self, a, args, i) | 24 | func = function(self, options, a, args, i) |
| 25 | --[=[ | 25 | --[=[ |
| 26 | _.killEmAll{'qsynth'} | 26 | _.killEmAll{'qsynth'} |
| 27 | __[[ | 27 | __[[ |
