refactor(health): move all report function into table

This commit is contained in:
Smirnov Oleksandr 2023-07-17 18:24:56 +03:00
parent cc62df0128
commit 2b253ca72d

View file

@ -3,11 +3,13 @@ local cmd = require("gopher.config").config.commands
local u = require "gopher._utils.health" local u = require "gopher._utils.health"
local _h = vim.health or require "health" local _h = vim.health or require "health"
local start = _h.start or _h.report_start local h = {
local ok = _h.ok or _h.report_ok start = _h.start or _h.report_start,
local warn = _h.warn or _h.report_warn ok = _h.ok or _h.report_ok,
local error = _h.error or _h.report_error warn = _h.warn or _h.report_warn,
local info = _h.info or _h.report_info error = _h.error or _h.report_error,
info = _h.info or _h.report_info,
}
local deps = { local deps = {
plugin = { plugin = {
@ -34,29 +36,29 @@ local deps = {
} }
function health.check() function health.check()
start "required plugins" h.start "required plugins"
for _, plugin in ipairs(deps.plugin) do for _, plugin in ipairs(deps.plugin) do
if u.lualib_is_found(plugin.lib) then if u.lualib_is_found(plugin.lib) then
ok(plugin.lib .. " installed") h.ok(plugin.lib .. " installed")
else else
if plugin.optional then if plugin.optional then
warn(plugin.lib .. " not found, " .. plugin.msg) h.warn(plugin.lib .. " not found, " .. plugin.msg)
else else
error(plugin.lib .. " not found, " .. plugin.msg) h.error(plugin.lib .. " not found, " .. plugin.msg)
end end
end end
end end
start "required binaries" h.start "required binaries"
info "all those binaries can be installed by `:GoInstallDeps`" h.info "all those binaries can be installed by `:GoInstallDeps`"
for _, bin in ipairs(deps.bin) do for _, bin in ipairs(deps.bin) do
if u.binary_is_found(bin.bin) then if u.binary_is_found(bin.bin) then
ok(bin.bin .. " installed") h.ok(bin.bin .. " installed")
else else
if bin.optional then if bin.optional then
warn(bin.bin .. " not found, " .. bin.msg) h.warn(bin.bin .. " not found, " .. bin.msg)
else else
error(bin.bin .. " not found, " .. bin.msg) h.error(bin.bin .. " not found, " .. bin.msg)
end end
end end
end end