refactor(installer): add a way to install deps synchronously

This commit is contained in:
Oleksandr Smirnov 2025-02-27 23:10:00 +02:00
parent 0102d1b02f
commit c96dafbaf6
No known key found for this signature in database
3 changed files with 33 additions and 15 deletions

View file

@ -36,7 +36,7 @@ tasks:
ci:install-deps: ci:install-deps:
desc: install dependencies for CI desc: install dependencies for CI
cmds: ['nvim --headless -u "./scripts/minimal_init.lua" -c "GoInstallDeps" -c "qa!"'] cmds: ['nvim --headless -u "./scripts/minimal_init.lua" -c "GoInstallDepsSync" -c "qa!"']
docgen: docgen:
desc: generate vimhelp desc: generate vimhelp

View file

@ -11,26 +11,43 @@ local urls = {
iferr = "github.com/koron/iferr", iferr = "github.com/koron/iferr",
} }
---@param pkg string ---@param opt vim.SystemCompleted
local function install(pkg) ---@param url string
local url = urls[pkg] .. "@latest" local function handle_intall_exit(opt, url)
local function on_exit(opt) if opt.code ~= 0 then
if opt.code ~= 0 then u.deferred_notify("go install failed: " .. url)
u.deferred_notify("go install failed: " .. url) log.debug("go install failed:", "url", url, "stderr", opt.stderr)
log.debug("go install failed:", "url", url, "stderr", opt.stderr) return
return
end
u.deferred_notify("go install'ed: " .. url)
end 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 end
---Install required go deps ---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 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
end end

View file

@ -11,4 +11,5 @@ command! -nargs=* GoGenerate :lua require"gopher".generate(<f-args>)
command! GoCmt :lua require"gopher".comment() command! GoCmt :lua require"gopher".comment()
command! GoIfErr :lua require"gopher".iferr() command! GoIfErr :lua require"gopher".iferr()
command! GoInstallDeps :lua require"gopher".install_deps() command! GoInstallDeps :lua require"gopher".install_deps()
command! GoInstallDepsSync :lua require"gopher".install_deps(true)
command! GopherLog :lua vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile()) command! GopherLog :lua vim.cmd("tabnew " .. require("gopher._utils.log").get_outfile())