diff options
author | dvs1 | 2024-10-25 09:38:35 +1000 |
---|---|---|
committer | dvs1 | 2024-10-25 09:38:35 +1000 |
commit | 31566d68cb3365ead1cdc8648c81d62ce966cb6f (patch) | |
tree | bbe3d4bc790530c6e955e21b18d1150d6036f73a | |
parent | Yet another TODO, YATODO. (diff) | |
download | JackOnAllDevices-31566d68cb3365ead1cdc8648c81d62ce966cb6f.zip JackOnAllDevices-31566d68cb3365ead1cdc8648c81d62ce966cb6f.tar.gz JackOnAllDevices-31566d68cb3365ead1cdc8648c81d62ce966cb6f.tar.bz2 JackOnAllDevices-31566d68cb3365ead1cdc8648c81d62ce966cb6f.tar.xz |
Just discovered the arg variable, use it and rename parseArgs() to just parse().
Diffstat (limited to '')
-rwxr-xr-x | _.lua | 6 | ||||
-rwxr-xr-x | aataaj.lua | 9 | ||||
-rwxr-xr-x | test_.lua | 10 |
3 files changed, 14 insertions, 11 deletions
@@ -24,7 +24,7 @@ E = function(s) print('ERROR ' .. s); io.flush() end | |||
24 | C = function(s) print('CRITICAL ' .. s); io.flush() end | 24 | C = function(s) print('CRITICAL ' .. s); io.flush() end |
25 | 25 | ||
26 | 26 | ||
27 | _.parseArgs = function(options, args) | 27 | _.parse = function(args, options) |
28 | --[[ TODO - use this for config files as well. | 28 | --[[ TODO - use this for config files as well. |
29 | An optional argument, the base config file name to look for. In this order, with later ones overriding earlier ones - | 29 | An optional argument, the base config file name to look for. In this order, with later ones overriding earlier ones - |
30 | defaults from the options table | 30 | defaults from the options table |
@@ -34,7 +34,7 @@ _.parseArgs = function(options, args) | |||
34 | ]] | 34 | ]] |
35 | local o = nil | 35 | local o = nil |
36 | if 0 ~= #args then | 36 | if 0 ~= #args then |
37 | for i,a in pairs(args) do | 37 | for i,a in ipairs(args) do |
38 | local s, e = a:find("=") | 38 | local s, e = a:find("=") |
39 | if nil == s then e = 0 end | 39 | if nil == s then e = 0 end |
40 | opt = a:sub(1, e - 1) | 40 | opt = a:sub(1, e - 1) |
@@ -51,7 +51,7 @@ _.parseArgs = function(options, args) | |||
51 | for k, v in pairs(options) do | 51 | for k, v in pairs(options) do |
52 | h = h .. k .. ' | ' | 52 | h = h .. k .. ' | ' |
53 | end | 53 | end |
54 | print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}') | 54 | print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}') |
55 | os.exit(0) | 55 | os.exit(0) |
56 | end | 56 | end |
57 | end | 57 | end |
@@ -143,8 +143,7 @@ local options = | |||
143 | ['--help'] = {help}, | 143 | ['--help'] = {help}, |
144 | } | 144 | } |
145 | 145 | ||
146 | local args = {...} | 146 | _.parse(arg, options) |
147 | _.parseArgs(options, args) | ||
148 | 147 | ||
149 | 148 | ||
150 | 149 | ||
@@ -184,7 +183,7 @@ for i,l in ipairs(cards.lines) do | |||
184 | Cards[l]['devs'][n] = n | 183 | Cards[l]['devs'][n] = n |
185 | print("\tFound playback device " .. Cards[l].card - 1 .. " : " .. Cards[l]['name'] .. "\tDEVICE: " .. Cards[l]['playbackDevs'][j] .. ' ' .. n) | 184 | print("\tFound playback device " .. Cards[l].card - 1 .. " : " .. Cards[l]['name'] .. "\tDEVICE: " .. Cards[l]['playbackDevs'][j] .. ' ' .. n) |
186 | io.flush() | 185 | io.flush() |
187 | if 'JACK' ~= args[1] then | 186 | if 'JACK' ~= arg[1] then |
188 | print('\t\tALSA_CARD=' .. Cards[l].card - 1 .. ' ' .. speaker .. ' "Found playback device ' .. Cards[l].card - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"') | 187 | print('\t\tALSA_CARD=' .. Cards[l].card - 1 .. ' ' .. speaker .. ' "Found playback device ' .. Cards[l].card - 1 .. ' : ' .. Cards[l]['name'] .. ' DEVICE: ' .. Cards[l]['playbackDevs'][j] .. ' ' .. n .. '"') |
189 | io.flush() | 188 | io.flush() |
190 | end | 189 | end |
@@ -221,7 +220,7 @@ print('') | |||
221 | io.flush() | 220 | io.flush() |
222 | 221 | ||
223 | 222 | ||
224 | if 'start' == args[1] then | 223 | if 'start' == arg[1] then |
225 | __('mkdir -p ' .. asoundrcPath):Do() | 224 | __('mkdir -p ' .. asoundrcPath):Do() |
226 | local a, e = io.open(asoundrcPath .. '/jack-plumbing', "w") | 225 | local a, e = io.open(asoundrcPath .. '/jack-plumbing', "w") |
227 | if nil == a then print("Could not open " .. asoundrcPath .. '/jack-plumbing') else | 226 | if nil == a then print("Could not open " .. asoundrcPath .. '/jack-plumbing') else |
@@ -391,7 +390,7 @@ pcm.!default { | |||
391 | ]]) | 390 | ]]) |
392 | a:close() | 391 | a:close() |
393 | end | 392 | end |
394 | elseif 'JACK' == args[1] then | 393 | elseif 'JACK' == arg[1] then |
395 | print('') | 394 | print('') |
396 | print("Start up JACK and friends.") | 395 | print("Start up JACK and friends.") |
397 | print("jack_control") | 396 | print("jack_control") |
@@ -55,8 +55,7 @@ local options = | |||
55 | ['--help'] = {help}, | 55 | ['--help'] = {help}, |
56 | } | 56 | } |
57 | 57 | ||
58 | local args = {...} | 58 | _.parse(arg, options) |
59 | _.parseArgs(options, args) | ||
60 | 59 | ||
61 | 60 | ||
62 | 61 | ||
@@ -137,7 +136,12 @@ print(__'command NoSuchCommand':log():show():Do().status) | |||
137 | --__'qpdfview':forkOnce() | 136 | --__'qpdfview':forkOnce() |
138 | --__'qpdfview':forkOnce() | 137 | --__'qpdfview':forkOnce() |
139 | 138 | ||
139 | print('') | ||
140 | |||
141 | for i,a in ipairs(arg) do print('arg[' .. i .. '] = ' .. a) end | ||
142 | print('') | ||
143 | for k,a in pairs(arg) do print('arg[' .. k .. '] = ' .. a) end | ||
140 | 144 | ||
141 | __'date':log():show():Do() | 145 | __'date':log():show():Do() |
142 | __'date; sleep 5; date':log():show():Do() | 146 | __'date; sleep 5; date':log():show():Do() |
143 | print('') | 147 | |