From f28129b5c96317a0486592011db8e02655b18e1a Mon Sep 17 00:00:00 2001 From: dvs1 Date: Fri, 25 Oct 2024 17:03:00 +1000 Subject: Help command now prints out full usage as well. --- _.lua | 41 +++++++++++++++++++++++++++++------------ aataaj.lua | 2 +- test_.lua | 2 +- 3 files changed, 31 insertions(+), 14 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 local optionsCommon = { - help = {help = 'Print the help text', - func = function(self, a, args, i) + help = {help = 'Print the help text.', + func = function(self, options, a, args, i) print(Help) + _.usage(args, options, true) os.exit(0) end }, ['--version'] = {help = 'Print the version details.', - func = function(self, a, args, i) + func = function(self, options, a, args, i) print('This is version ' ..Version .. ' of ' .. args[0]) os.exit(0) end @@ -43,6 +44,29 @@ local optionsCommon = } optionsCommon['--help'] = optionsCommon['help'] +_.usage = function(args, options, all) + local h = '' + for k, v in pairs(options) do + if 'table' == type(v) then h = h .. k .. ' | ' end + end + for k, v in pairs(optionsCommon) do + if 'table' == type(v) then h = h .. k .. ' | ' end + end + print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}') + if true == all then + for k, v in pairs(options) do + if 'table' == type(v) then + if nil ~= v.help then print(k .. '\t\t' .. v.help) end + end + end + for k, v in pairs(optionsCommon) do + if 'table' == type(v) then + if nil ~= v.help then print(k .. '\t\t' .. v.help) end + end + end + end +end + _.parse = function(args, options, confFile) local o = nil @@ -51,7 +75,7 @@ _.parse = function(args, options, confFile) if nil == o then o = optionsCommon[name] end if nil ~= o then if nil ~= val then o.value = val; D(name .. ' = ' .. tostring(val)) end - if nil ~= o.func then o:func(a, args, i) end + if nil ~= o.func then o:func(options, a, args, i) end end return o end @@ -85,14 +109,7 @@ _.parse = function(args, options, confFile) end if nil == o then - local h = '' - for k, v in pairs(options) do - if 'table' == type(v) then h = h .. k .. ' | ' end - end - for k, v in pairs(optionsCommon) do - if 'table' == type(v) then h = h .. k .. ' | ' end - end - print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}') + _.usage(args, options) os.exit(0) end end diff --git a/aataaj.lua b/aataaj.lua index aa2829d..6f840f3 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -107,7 +107,7 @@ local options = STOP = { help = 'Command to stop the JACK stuff, for users.', - func = function(self, a, args, i) + func = function(self, options, a, args, i) _.killEmAll{'qsynth'} __[[#!/bin/bash a2j_control --stop diff --git a/test_.lua b/test_.lua index e4ebcc8..b1ded7d 100755 --- a/test_.lua +++ b/test_.lua @@ -21,7 +21,7 @@ local options = stop = {help = 'Command to stop the scanning process, for Sys V init.',}, JACK = {help = 'Command to start the JACK stuff, for users.',}, STOP = {help = 'Command to stop the JACK stuff, for users.', - func = function(self, a, args, i) + func = function(self, options, a, args, i) --[=[ _.killEmAll{'qsynth'} __[[ -- cgit v1.1