diff options
author | dvs1 | 2024-10-25 13:40:21 +1000 |
---|---|---|
committer | dvs1 | 2024-10-25 13:40:21 +1000 |
commit | 5833e7483357daa24b8ddc1f766a6446d0d30495 (patch) | |
tree | de47d4ced1efa62c865677f7711534bb0b2c7865 | |
parent | TODO++ (diff) | |
download | JackOnAllDevices-5833e7483357daa24b8ddc1f766a6446d0d30495.zip JackOnAllDevices-5833e7483357daa24b8ddc1f766a6446d0d30495.tar.gz JackOnAllDevices-5833e7483357daa24b8ddc1f766a6446d0d30495.tar.bz2 JackOnAllDevices-5833e7483357daa24b8ddc1f766a6446d0d30495.tar.xz |
Moved common stuff like --help, --version to an internal options table we scan as well.
-rwxr-xr-x | _.lua | 28 | ||||
-rwxr-xr-x | aataaj.lua | 15 | ||||
-rwxr-xr-x | test_.lua | 12 |
3 files changed, 30 insertions, 25 deletions
@@ -26,12 +26,29 @@ E = function(s) print('ERROR ' .. s); io.flush() end | |||
26 | C = function(s) print('CRITICAL ' .. s); io.flush() end | 26 | C = 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. | 29 | local 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 | } | ||
44 | optionsCommon['--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) |
@@ -17,7 +17,7 @@ | |||
17 | local _ = require '_' | 17 | local _ = require '_' |
18 | 18 | ||
19 | 19 | ||
20 | local Help = [[ | 20 | Help = [[ |
21 | This is part of the AllAudioToALSAandJACK project, aataaj for short, | 21 | This is part of the AllAudioToALSAandJACK project, aataaj for short, |
22 | pronounced like "attach". | 22 | pronounced like "attach". |
23 | 23 | ||
@@ -81,7 +81,7 @@ NOTE - Seems both ALSA and JACK are per user. So you need to run | |||
81 | "aataaj JACK" for each user. | 81 | "aataaj JACK" for each user. |
82 | 82 | ||
83 | ]] | 83 | ]] |
84 | 84 | Version = '0.0 crap' | |
85 | 85 | ||
86 | 86 | ||
87 | local options = | 87 | local options = |
@@ -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(a, args, i) | 110 | func = function(self, a, args, i) |
111 | _.killEmAll{'qsynth'} | 111 | _.killEmAll{'qsynth'} |
112 | __[[#!/bin/bash | 112 | __[[#!/bin/bash |
113 | a2j_control --stop | 113 | a2j_control --stop |
@@ -132,15 +132,6 @@ local options = | |||
132 | os.exit(0) | 132 | os.exit(0) |
133 | end | 133 | end |
134 | }, | 134 | }, |
135 | help = | ||
136 | { | ||
137 | help = 'Print help.', | ||
138 | func = function(a, args, i) | ||
139 | print(Help) | ||
140 | os.exit(0) | ||
141 | end | ||
142 | }, | ||
143 | ['--help'] = {help}, | ||
144 | } | 135 | } |
145 | 136 | ||
146 | _.parse(arg, options) | 137 | _.parse(arg, options) |
@@ -6,10 +6,11 @@ local _ = require '_' | |||
6 | 6 | ||
7 | I'Starting from the top.' | 7 | I'Starting from the top.' |
8 | 8 | ||
9 | local Help = [[ | 9 | Help = [[ |
10 | This is part of the blah blah blah... | 10 | This is part of the blah blah blah... |
11 | ]] | 11 | ]] |
12 | 12 | ||
13 | Version = '0.0 crap' | ||
13 | 14 | ||
14 | local options = | 15 | local options = |
15 | { | 16 | { |
@@ -20,7 +21,7 @@ local options = | |||
20 | 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.',}, |
21 | JACK = {help = 'Command to start the JACK stuff, for users.',}, | 22 | JACK = {help = 'Command to start the JACK stuff, for users.',}, |
22 | STOP = {help = 'Command to stop the JACK stuff, for users.', | 23 | STOP = {help = 'Command to stop the JACK stuff, for users.', |
23 | func = function(a, args, i) | 24 | func = function(self, a, args, i) |
24 | --[=[ | 25 | --[=[ |
25 | _.killEmAll{'qsynth'} | 26 | _.killEmAll{'qsynth'} |
26 | __[[ | 27 | __[[ |
@@ -46,13 +47,6 @@ local options = | |||
46 | ]=] | 47 | ]=] |
47 | end | 48 | end |
48 | }, | 49 | }, |
49 | help = {help = 'Print help.', | ||
50 | func = function(a, args, i) | ||
51 | print(Help) | ||
52 | os.exit(0) | ||
53 | end | ||
54 | }, | ||
55 | ['--help'] = {help}, | ||
56 | } | 50 | } |
57 | 51 | ||
58 | print("start = " .. options.start.value) | 52 | print("start = " .. options.start.value) |