fix(utils): improve system command argument parsing
This commit is contained in:
@@ -11,9 +11,10 @@ local git = { url = "https://github.com/" }
|
||||
local function trim_or_nil(str) return type(str) == "string" and vim.trim(str) or nil end
|
||||
|
||||
--- Run a git command from the AstroNvim installation directory
|
||||
---@param args string[] the git arguments
|
||||
---@param args string|string[] the git arguments
|
||||
---@return string|nil # The result of the command or nil if unsuccessful
|
||||
function git.cmd(args, ...)
|
||||
if type(args) == "string" then args = { args } end
|
||||
return require("astronvim.utils").cmd(vim.list_extend({ "git", "-C", astronvim.install.home }, args), ...)
|
||||
end
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ end
|
||||
---@param show_error? boolean Whether or not to show an unsuccessful command as an error to the user
|
||||
---@return string|nil # The result of a successfully executed command or nil
|
||||
function M.cmd(cmd, show_error)
|
||||
if type(cmd) == "string" then cmd = vim.split(cmd, " ") end -- HACK: remove in AstroNvim v4 and require cmd to be a string[]
|
||||
if type(cmd) == "string" then cmd = { cmd } end
|
||||
if vim.fn.has "win32" == 1 then cmd = vim.list_extend({ "cmd.exe", "/C" }, cmd) end
|
||||
local result = vim.fn.system(cmd)
|
||||
local success = vim.api.nvim_get_vvar "shell_error" == 0
|
||||
|
||||
Reference in New Issue
Block a user