Commit 4fa8ce2e authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

pretty output from awall list

parent 20ae74c3
......@@ -103,9 +103,7 @@ require 'awall'
policyset = awall.PolicySet.new(params.i, params.I)
if mode == 'list' then
for name, status, desc in policyset:list() do
print(name, status, desc)
end
awall.util.printtabular(policyset:list())
os.exit()
end
......
......@@ -220,19 +220,19 @@ end
function PolicySet:list()
local config, imported = self:load()
local pols = list(self.importdirs)
local i = 0
local res = {}
for i, pol in ipairs(list(self.importdirs)) do
local name = pol[1]
return function()
i = i + 1
if i > #pols then return end
local name = pols[i][1]
local status
if self:findsymlink(name) then status = 'enabled'
elseif util.contains(imported, name) then status = 'required'
else status = 'disabled' end
local status
if self:findsymlink(name) then status = 'enabled'
elseif util.contains(imported, name) then status = 'required'
else status = 'disabled' end
table.insert(res,
{name, status, self:loadJSON(name, pol[2]).description})
end
return name, status, self:loadJSON(name, pols[i][2]).description
end
return res
end
......@@ -37,3 +37,20 @@ end
function extend(tbl1, tbl2)
for i, var in listpairs(tbl2) do table.insert(tbl1, var) end
end
function printtabular(tbl)
local colwidth = {}
for i, row in ipairs(tbl) do
for j, col in ipairs(row) do
colwidth[j] = math.max(colwidth[j] or 0, string.len(col))
end
end
for i, row in ipairs(tbl) do
for j, col in ipairs(row) do
if j > 1 then io.write(' ') end
io.write(col)
for k = 1,colwidth[j] - string.len(col) do io.write(' ') end
end
io.write('\n')
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment