Skip to content

Commit

Permalink
fix(health): dont use vim.fn.system to get cmd versions
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 22, 2024
1 parent cc028e7 commit 7d29719
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lua/lazy/health.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Config = require("lazy.core.config")
local Process = require("lazy.manage.process")
local uv = vim.uv or vim.loop

local M = {}
Expand Down Expand Up @@ -36,11 +37,11 @@ function M.have(cmd, opts)
local found
for _, c in ipairs(cmd) do
if vim.fn.executable(c) == 1 then
local version = vim.fn.system(c .. " " .. opts.version) or ""
if vim.v.shell_error ~= 0 then
opts.error(("failed to get version of {%s}\n%s"):format(c, version))
local out, exit_code = Process.exec({ c, opts.version })
if exit_code ~= 0 then
opts.error(("failed to get version of {%s}\n%s"):format(c, table.concat(out, "\n")))
else
version = vim.trim(vim.split(version, "\n")[1])
local version = vim.trim(out[1] or "")
version = version:gsub("^%s*" .. vim.pesc(c) .. "%s*", "")
if opts.version_pattern and not version:find(opts.version_pattern, 1, true) then
opts.warn(("`%s` version `%s` needed, but found `%s`"):format(c, opts.version_pattern, version))
Expand Down

0 comments on commit 7d29719

Please sign in to comment.