auditd: refactoring

This commit is contained in:
Aleksey Nikitin
2023-01-30 10:21:56 +03:00
parent 8df2641f71
commit 4ea8a4bb93
+10 -6
View File
@@ -1,6 +1,6 @@
local exec = require "exec"
-- Replaces each occurrence of `{name}` in cmd with the corrensponding
-- Replaces each occurrence of `{name}` in cmd with the corresponding
-- value of key `name` from table vars.
--:: string, {string => string} -> string
local function format_cmd(cmd, vars)
@@ -10,9 +10,11 @@ local function format_cmd(cmd, vars)
return cmd
end
-- Manager is an abstraction over system package managers.
-- See the list of supported package managers below.
local Manager = {}; Manager.__index = Manager
local ManagerCommands = {
local backend_commands = {
test = "type {bin}",
sync = "false",
install = "false",
@@ -20,7 +22,7 @@ local ManagerCommands = {
function Manager.new(name, bin, commands)
commands = commands or {}
for type, cmd in pairs(ManagerCommands) do
for type, cmd in pairs(backend_commands) do
commands[type] = commands[type] or cmd
end
return setmetatable({
@@ -30,13 +32,14 @@ function Manager.new(name, bin, commands)
}, Manager)
end
-- Tests if the manager is available in current OS.
-- Tests if the manager is available on current OS.
--:: () -> ok::boolean, err::string?
function Manager:test()
local cmd = format_cmd(self._cmd.test, {name=self.name, bin=self.bin})
return exec(cmd)
end
-- Used to synchronize the package index files from their sources.
--:: () -> ok::boolean, err::string?
function Manager:sync()
local cmd = format_cmd(self._cmd.sync, {name=self.name, bin=self.bin})
@@ -71,7 +74,7 @@ local managers = {
}),
}
-- Tries to guess a package manager available in current OS.
-- Tries to guess a package manager available on current OS.
--:: () -> Manager?, err::string?
local function find_manager()
for _, manager in ipairs(managers) do
@@ -82,5 +85,6 @@ end
return {
find_manager = find_manager,
testing = {format_cmd = format_cmd},
testing = {
format_cmd = format_cmd },
}