Rename util functions

This commit is contained in:
2023-09-04 15:23:43 +02:00
parent a4ec17b5c3
commit aafa05df7a
3 changed files with 18 additions and 19 deletions
+7 -7
View File
@@ -28,18 +28,18 @@ local utils = require("utils")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then if not vim.loop.fs_stat(lazypath) then
if utils.os_name == "Linux" then if utils.os_name == "Linux" then
utils.assert_any_available({ "curl", "wget", }) utils.assert_any_installed({ "curl", "wget", })
utils.assert_available("unzip") utils.assert_installed("unzip")
utils.assert_available("gzip") utils.assert_installed("gzip")
elseif utils.os_name == "Windows_NT" then elseif utils.os_name == "Windows_NT" then
utils.assert_any_available({ "pwsh", "powershell", }) utils.assert_any_installed({ "pwsh", "powershell", })
utils.assert_any_available({ "7z", "peazip", "arc", "wzzip", "rar", }) utils.assert_any_installed({ "7z", "peazip", "arc", "wzzip", "rar", })
else else
error("OS not supported: " .. utils.os_name) error("OS not supported: " .. utils.os_name)
end end
utils.assert_available("git") utils.assert_installed("git")
utils.assert_available("tar") utils.assert_installed("tar")
local resp = vim.system({ local resp = vim.system({
"git", "git",
+3 -4
View File
@@ -22,10 +22,9 @@ local env_ok = false
local dap = nil local dap = nil
local function check_env() local function check_env()
utils.exec("Asdf") utils.assert_installed("python3")
utils.assert_available("python3") utils.python3_module_installed("debugpy")
utils.assert_python3_module("debugpy") utils.python3_module_installed("pytest")
utils.assert_python3_module("pytest")
env_ok = true env_ok = true
end end
+8 -8
View File
@@ -21,16 +21,16 @@ M.os_name = vim.loop.os_uname().sysname
--- Check that an executable is available --- Check that an executable is available
--- @param exe string: Array to look for --- @param exe string: Array to look for
--- @return boolean --- @return boolean
function M.is_available(exe) function M.is_installed(exe)
return vim.fn.executable(exe) == 1 return vim.fn.executable(exe) == 1
end end
--- Check that at least one executable is available --- Check that at least one executable is available
--- @param exes table: Array of exes --- @param exes table: Array of exes
--- @return boolean --- @return boolean
function M.any_available(exes) function M.any_installed(exes)
for _, e in ipairs(exes) do for _, e in ipairs(exes) do
if M.is_available(e) then if M.is_installed(e) then
return true return true
end end
end end
@@ -41,8 +41,8 @@ end
--- Asserts that an executable is available --- Asserts that an executable is available
--- Raises error if missing. --- Raises error if missing.
--- @param exe string: Array to look for --- @param exe string: Array to look for
function M.assert_available(exe) function M.assert_installed(exe)
if not M.is_available(exe) then if not M.is_installed(exe) then
M.notify("Missing executable '" .. exe .. "'.") M.notify("Missing executable '" .. exe .. "'.")
end end
end end
@@ -50,15 +50,15 @@ end
--- Asserts that at least one executable is available --- Asserts that at least one executable is available
--- Raises error if missing. --- Raises error if missing.
--- @param exes table: Array of exes --- @param exes table: Array of exes
function M.assert_any_available(exes) function M.assert_any_installed(exes)
if not M.any_available(exes) then if not M.any_installed(exes) then
error("At least one of the following is required:\n" .. table.concat(exes, ", ")) error("At least one of the following is required:\n" .. table.concat(exes, ", "))
end end
end end
--- Asserts that a python module is installed --- Asserts that a python module is installed
---@param mod string: The python module to check ---@param mod string: The python module to check
function M.assert_python3_module(mod) function M.python3_module_installed(mod)
local resp = vim.system({ "python3", "-m", "pip", "show", mod, }):wait() local resp = vim.system({ "python3", "-m", "pip", "show", mod, }):wait()
if not resp.code == 0 then if not resp.code == 0 then
error("Python3 module " .. mod .. " not installed:\n" .. resp.stdout .. "\n" .. resp.stderr) error("Python3 module " .. mod .. " not installed:\n" .. resp.stdout .. "\n" .. resp.stderr)