diff options
Diffstat (limited to '_.lua')
-rwxr-xr-x | _.lua | 71 |
1 files changed, 20 insertions, 51 deletions
@@ -45,7 +45,7 @@ _.parseArgs = function(options, args) | |||
45 | if nil == o then | 45 | if nil == o then |
46 | local h = '' | 46 | local h = '' |
47 | for k, v in pairs(options) do | 47 | for k, v in pairs(options) do |
48 | h = h .. k .. '|' | 48 | h = h .. k .. ' | ' |
49 | end | 49 | end |
50 | print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}') | 50 | print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}') |
51 | os.exit(0) | 51 | os.exit(0) |
@@ -62,9 +62,10 @@ end | |||
62 | 62 | ||
63 | _.exists = function(f) | 63 | _.exists = function(f) |
64 | local h, e = io.open(f, "r") | 64 | local h, e = io.open(f, "r") |
65 | if nil == h then return false else h:close(); return true end | 65 | if nil == h then return false else h:close(); return true end |
66 | end | 66 | end |
67 | 67 | ||
68 | |||
68 | _.killEmAll = function(all) | 69 | _.killEmAll = function(all) |
69 | for i,l in ipairs(all) do | 70 | for i,l in ipairs(all) do |
70 | local c = 0 | 71 | local c = 0 |
@@ -91,6 +92,7 @@ _.readCmd = function(cmd) | |||
91 | return result | 92 | return result |
92 | end | 93 | end |
93 | 94 | ||
95 | |||
94 | __ = function(c) | 96 | __ = function(c) |
95 | local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c, isScript = false, script = ''} | 97 | local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c, isScript = false, script = ''} |
96 | local n = 0 | 98 | local n = 0 |
@@ -130,15 +132,6 @@ __ = function(c) | |||
130 | exe.cmd = exe.cmd .. ' } ' | 132 | exe.cmd = exe.cmd .. ' } ' |
131 | if 1 == n then exe.cmd = c end | 133 | if 1 == n then exe.cmd = c end |
132 | 134 | ||
133 | function exe:log() | ||
134 | self.logging = true | ||
135 | return self | ||
136 | end | ||
137 | |||
138 | function exe:show() | ||
139 | self.showing = true | ||
140 | return self | ||
141 | end | ||
142 | 135 | ||
143 | function exe:Nice(c) | 136 | function exe:Nice(c) |
144 | if nil == c then | 137 | if nil == c then |
@@ -160,38 +153,15 @@ __ = function(c) | |||
160 | return self | 153 | return self |
161 | end | 154 | end |
162 | 155 | ||
163 | function exe:also(c) -- Should be called "then" but that's a reserved word. | 156 | function exe:log() self.logging = true return self end |
164 | if nil == c then c = '' else c = ' ' .. c end | 157 | function exe:show() self.showing = true return self end |
165 | self.cmd = self.cmd .. '; ' .. c .. ' ' | 158 | -- Should be called "then" but that's a reserved word. |
166 | return self | 159 | function exe:also(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. '; ' .. c .. ' ' return self end |
167 | end | 160 | function exe:And(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. ' && ' .. c .. ' ' return self end |
168 | 161 | function exe:Or(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. ' || ' .. c .. ' ' return self end | |
169 | function exe:And(c) | 162 | function exe:noErr() self.cmd = self.cmd .. ' 2>/dev/null ' return self end |
170 | if nil == c then c = '' else c = ' ' .. c end | 163 | function exe:noOut() self.cmd = self.cmd .. ' 1>/dev/null ' return self end |
171 | self.cmd = self.cmd .. ' && ' .. c .. ' ' | 164 | function exe:wait(w) self.cmd = self.cmd .. ' && touch ' .. w .. ' ' return self end |
172 | return self | ||
173 | end | ||
174 | |||
175 | function exe:Or(c) | ||
176 | if nil == c then c = '' end | ||
177 | self.cmd = self.cmd .. ' || ' .. c .. ' ' | ||
178 | return self | ||
179 | end | ||
180 | |||
181 | function exe:noErr() | ||
182 | self.cmd = self.cmd .. ' 2>/dev/null ' | ||
183 | return self | ||
184 | end | ||
185 | |||
186 | function exe:noOut() | ||
187 | self.cmd = self.cmd .. ' 1>/dev/null ' | ||
188 | return self | ||
189 | end | ||
190 | |||
191 | function exe:wait(w) | ||
192 | self.cmd = self.cmd .. ' && touch ' .. w .. ' ' | ||
193 | return self | ||
194 | end | ||
195 | 165 | ||
196 | function exe:Do() | 166 | function exe:Do() |
197 | --[[ "The condition expression of a control structure can return any | 167 | --[[ "The condition expression of a control structure can return any |
@@ -207,17 +177,16 @@ __ = function(c) | |||
207 | local ok, rslt, status = os.execute(s) | 177 | local ok, rslt, status = os.execute(s) |
208 | ]] | 178 | ]] |
209 | self.lines = _.readCmd(self.cmd .. '; echo "$?"', 'r') | 179 | self.lines = _.readCmd(self.cmd .. '; echo "$?"', 'r') |
210 | -- The last line will be the command's returned status, collect everything else in lines. | 180 | -- The last line will be the command's returned status, fish that out and collect everything else in lines. |
211 | self.status = tonumber(self.lines[#self.lines]) | 181 | self.status = tonumber(self.lines[#self.lines]) |
212 | self.lines[#self.lines] = nil | 182 | self.lines[#self.lines] = nil |
213 | if true == self.showing then for i, l in ipairs(self.lines) do D(l) end end | 183 | if true == self.showing then for i, l in ipairs(self.lines) do I(l) end end |
214 | if (137 == self.status) or (124 == self.status) then | 184 | |
215 | T("timeout killed " .. self.status .. ' ' .. self.command) | 185 | if (nil == self.status) then D("STATUS |" .. "NIL" .. '| ' .. self.command) |
216 | elseif (nil == self.status) then | 186 | elseif (137 == self.status) or (124 == self.status) then T("timeout killed " .. self.status .. ' ' .. self.command) |
217 | D("STATUS |" .. "NIL" .. '| ' .. self.command) | 187 | elseif (0 ~= self.status) then D("STATUS |" .. self.status .. '| ' .. self.command) |
218 | elseif (0 ~= self.status) then | ||
219 | D("STATUS |" .. self.status .. '| ' .. self.command) | ||
220 | end | 188 | end |
189 | |||
221 | return self | 190 | return self |
222 | end | 191 | end |
223 | 192 | ||