From e4fcdb2458635ca3c034fcd2df129f53d9e154e5 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Thu, 24 Oct 2024 13:28:18 +1000 Subject: Some more tidying up. --- _.lua | 71 +++++++++++++++++++------------------------------------------------ 1 file changed, 20 insertions(+), 51 deletions(-) (limited to '_.lua') diff --git a/_.lua b/_.lua index f5ab5b9..33b4183 100755 --- a/_.lua +++ b/_.lua @@ -45,7 +45,7 @@ _.parseArgs = function(options, args) if nil == o then local h = '' for k, v in pairs(options) do - h = h .. k .. '|' + h = h .. k .. ' | ' end print('Usage: aataaj.lua {' .. string.sub(h, 1, -2) .. '}') os.exit(0) @@ -62,9 +62,10 @@ end _.exists = function(f) local h, e = io.open(f, "r") - if nil == h then return false else h:close(); return true end + if nil == h then return false else h:close(); return true end end + _.killEmAll = function(all) for i,l in ipairs(all) do local c = 0 @@ -91,6 +92,7 @@ _.readCmd = function(cmd) return result end + __ = function(c) local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c, isScript = false, script = ''} local n = 0 @@ -130,15 +132,6 @@ __ = function(c) exe.cmd = exe.cmd .. ' } ' if 1 == n then exe.cmd = c end - function exe:log() - self.logging = true - return self - end - - function exe:show() - self.showing = true - return self - end function exe:Nice(c) if nil == c then @@ -160,38 +153,15 @@ __ = function(c) return self end - function exe:also(c) -- Should be called "then" but that's a reserved word. - if nil == c then c = '' else c = ' ' .. c end - self.cmd = self.cmd .. '; ' .. c .. ' ' - return self - end - - function exe:And(c) - if nil == c then c = '' else c = ' ' .. c end - self.cmd = self.cmd .. ' && ' .. c .. ' ' - return self - end - - function exe:Or(c) - if nil == c then c = '' end - self.cmd = self.cmd .. ' || ' .. c .. ' ' - return self - end - - function exe:noErr() - self.cmd = self.cmd .. ' 2>/dev/null ' - return self - end - - function exe:noOut() - self.cmd = self.cmd .. ' 1>/dev/null ' - return self - end - - function exe:wait(w) - self.cmd = self.cmd .. ' && touch ' .. w .. ' ' - return self - end + function exe:log() self.logging = true return self end + function exe:show() self.showing = true return self end + -- Should be called "then" but that's a reserved word. + function exe:also(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. '; ' .. c .. ' ' return self end + function exe:And(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. ' && ' .. c .. ' ' return self end + function exe:Or(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. ' || ' .. c .. ' ' return self end + function exe:noErr() self.cmd = self.cmd .. ' 2>/dev/null ' return self end + function exe:noOut() self.cmd = self.cmd .. ' 1>/dev/null ' return self end + function exe:wait(w) self.cmd = self.cmd .. ' && touch ' .. w .. ' ' return self end function exe:Do() --[[ "The condition expression of a control structure can return any @@ -207,17 +177,16 @@ __ = function(c) local ok, rslt, status = os.execute(s) ]] self.lines = _.readCmd(self.cmd .. '; echo "$?"', 'r') - -- The last line will be the command's returned status, collect everything else in lines. + -- The last line will be the command's returned status, fish that out and collect everything else in lines. self.status = tonumber(self.lines[#self.lines]) self.lines[#self.lines] = nil - if true == self.showing then for i, l in ipairs(self.lines) do D(l) end end - if (137 == self.status) or (124 == self.status) then - T("timeout killed " .. self.status .. ' ' .. self.command) - elseif (nil == self.status) then - D("STATUS |" .. "NIL" .. '| ' .. self.command) - elseif (0 ~= self.status) then - D("STATUS |" .. self.status .. '| ' .. self.command) + if true == self.showing then for i, l in ipairs(self.lines) do I(l) end end + + if (nil == self.status) then D("STATUS |" .. "NIL" .. '| ' .. self.command) + elseif (137 == self.status) or (124 == self.status) then T("timeout killed " .. self.status .. ' ' .. self.command) + elseif (0 ~= self.status) then D("STATUS |" .. self.status .. '| ' .. self.command) end + return self end -- cgit v1.1