test: improve helpers.argss_to_cmd()

This commit is contained in:
Lewis Russell 2024-01-15 20:21:14 +00:00
parent c9240daf73
commit b92318d67c

View File

@ -42,20 +42,22 @@ function module.isdir(path)
return stat.type == 'directory' return stat.type == 'directory'
end end
--- @param ... string|string[]
--- @return string --- @return string
function module.argss_to_cmd(...) function module.argss_to_cmd(...)
local cmd = '' local cmd = {} --- @type string[]
for i = 1, select('#', ...) do for i = 1, select('#', ...) do
local arg = select(i, ...) local arg = select(i, ...)
if type(arg) == 'string' then if type(arg) == 'string' then
cmd = cmd .. ' ' .. shell_quote(arg) cmd[#cmd + 1] = shell_quote(arg)
else else
--- @cast arg string[]
for _, subarg in ipairs(arg) do for _, subarg in ipairs(arg) do
cmd = cmd .. ' ' .. shell_quote(subarg) cmd[#cmd + 1] = shell_quote(subarg)
end end
end end
end end
return cmd return table.concat(cmd, ' ')
end end
function module.popen_r(...) function module.popen_r(...)