refactor(installer): add a way to install deps synchronously
This commit is contained in:
parent
0102d1b02f
commit
c96dafbaf6
3 changed files with 33 additions and 15 deletions
|
|
@ -11,26 +11,43 @@ local urls = {
|
|||
iferr = "github.com/koron/iferr",
|
||||
}
|
||||
|
||||
---@param pkg string
|
||||
local function install(pkg)
|
||||
local url = urls[pkg] .. "@latest"
|
||||
local function on_exit(opt)
|
||||
if opt.code ~= 0 then
|
||||
u.deferred_notify("go install failed: " .. url)
|
||||
log.debug("go install failed:", "url", url, "stderr", opt.stderr)
|
||||
return
|
||||
end
|
||||
|
||||
u.deferred_notify("go install'ed: " .. url)
|
||||
---@param opt vim.SystemCompleted
|
||||
---@param url string
|
||||
local function handle_intall_exit(opt, url)
|
||||
if opt.code ~= 0 then
|
||||
u.deferred_notify("go install failed: " .. url)
|
||||
log.debug("go install failed:", "url", url, "stderr", opt.stderr)
|
||||
return
|
||||
end
|
||||
|
||||
r.async({ c.go, "install", url }, on_exit)
|
||||
u.deferred_notify("go install-ed: " .. url)
|
||||
end
|
||||
|
||||
---@param url string
|
||||
local function install(url)
|
||||
r.async({ c.go, "install", url }, function(opt)
|
||||
handle_intall_exit(opt, url)
|
||||
end)
|
||||
end
|
||||
|
||||
---@param url string
|
||||
local function install_sync(url)
|
||||
local rs = r.sync { c.go, "install", url }
|
||||
handle_intall_exit(rs, url)
|
||||
end
|
||||
|
||||
---Install required go deps
|
||||
function installer.install_deps()
|
||||
---@param sync? boolean
|
||||
function installer.install_deps(sync)
|
||||
sync = sync or false
|
||||
|
||||
for pkg, _ in pairs(urls) do
|
||||
install(pkg)
|
||||
local url = urls[pkg] .. "@latest"
|
||||
if sync then
|
||||
install_sync(url)
|
||||
else
|
||||
install(url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue