mirror of https://github.com/folke/lazy.nvim.git
fix(health): dont use vim.fn.system to get cmd versions
This commit is contained in:
parent
cc028e77eb
commit
7d29719ade
|
@ -1,4 +1,5 @@
|
||||||
local Config = require("lazy.core.config")
|
local Config = require("lazy.core.config")
|
||||||
|
local Process = require("lazy.manage.process")
|
||||||
local uv = vim.uv or vim.loop
|
local uv = vim.uv or vim.loop
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
@ -36,11 +37,11 @@ function M.have(cmd, opts)
|
||||||
local found
|
local found
|
||||||
for _, c in ipairs(cmd) do
|
for _, c in ipairs(cmd) do
|
||||||
if vim.fn.executable(c) == 1 then
|
if vim.fn.executable(c) == 1 then
|
||||||
local version = vim.fn.system(c .. " " .. opts.version) or ""
|
local out, exit_code = Process.exec({ c, opts.version })
|
||||||
if vim.v.shell_error ~= 0 then
|
if exit_code ~= 0 then
|
||||||
opts.error(("failed to get version of {%s}\n%s"):format(c, version))
|
opts.error(("failed to get version of {%s}\n%s"):format(c, table.concat(out, "\n")))
|
||||||
else
|
else
|
||||||
version = vim.trim(vim.split(version, "\n")[1])
|
local version = vim.trim(out[1] or "")
|
||||||
version = version:gsub("^%s*" .. vim.pesc(c) .. "%s*", "")
|
version = version:gsub("^%s*" .. vim.pesc(c) .. "%s*", "")
|
||||||
if opts.version_pattern and not version:find(opts.version_pattern, 1, true) then
|
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))
|
opts.warn(("`%s` version `%s` needed, but found `%s`"):format(c, opts.version_pattern, version))
|
||||||
|
|
Loading…
Reference in New Issue