aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-x_.lua28
-rwxr-xr-xaataaj.lua15
-rwxr-xr-xtest_.lua12
3 files changed, 30 insertions, 25 deletions
diff --git a/_.lua b/_.lua
index 5c8963b..a2607f5 100755
--- a/_.lua
+++ b/_.lua
@@ -26,12 +26,29 @@ E = function(s) print('ERROR ' .. s); io.flush() end
26C = function(s) print('CRITICAL ' .. s); io.flush() end 26C = 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. 29local 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}
44optionsCommon['--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)
diff --git a/aataaj.lua b/aataaj.lua
index 6108dd5..5e45525 100755
--- a/aataaj.lua
+++ b/aataaj.lua
@@ -17,7 +17,7 @@
17local _ = require '_' 17local _ = require '_'
18 18
19 19
20local Help = [[ 20Help = [[
21This is part of the AllAudioToALSAandJACK project, aataaj for short, 21This is part of the AllAudioToALSAandJACK project, aataaj for short,
22pronounced like "attach". 22pronounced 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 84Version = '0.0 crap'
85 85
86 86
87local options = 87local 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)
diff --git a/test_.lua b/test_.lua
index 8d52896..82c418f 100755
--- a/test_.lua
+++ b/test_.lua
@@ -6,10 +6,11 @@ local _ = require '_'
6 6
7I'Starting from the top.' 7I'Starting from the top.'
8 8
9local Help = [[ 9Help = [[
10This is part of the blah blah blah... 10This is part of the blah blah blah...
11]] 11]]
12 12
13Version = '0.0 crap'
13 14
14local options = 15local 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
58print("start = " .. options.start.value) 52print("start = " .. options.start.value)