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
|
|
@ -36,7 +36,7 @@ tasks:
|
|||
|
||||
ci:install-deps:
|
||||
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:
|
||||
desc: generate vimhelp
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
---@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
|
||||
|
||||
u.deferred_notify("go install'ed: " .. url)
|
||||
u.deferred_notify("go install-ed: " .. url)
|
||||
end
|
||||
|
||||
r.async({ c.go, "install", url }, on_exit)
|
||||
---@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
|
||||
|
||||
|
|
|
|||
|
|
@ -11,4 +11,5 @@ command! -nargs=* GoGenerate :lua require"gopher".generate(<f-args>)
|
|||
command! GoCmt :lua require"gopher".comment()
|
||||
command! GoIfErr :lua require"gopher".iferr()
|
||||
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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue