refactor(installer): use new async runner
This commit is contained in:
parent
9881da4db7
commit
c544a2f969
3 changed files with 16 additions and 12 deletions
|
|
@ -3,8 +3,9 @@ local log = require "gopher._utils.log"
|
||||||
local utils = {}
|
local utils = {}
|
||||||
|
|
||||||
---@param msg string
|
---@param msg string
|
||||||
---@param lvl number
|
---@param lvl? number
|
||||||
function utils.deferred_notify(msg, lvl)
|
function utils.deferred_notify(msg, lvl)
|
||||||
|
lvl = lvl or vim.log.levels.INFO
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
vim.notify(msg, lvl, {
|
vim.notify(msg, lvl, {
|
||||||
title = c.___plugin_name,
|
title = c.___plugin_name,
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,10 @@ end
|
||||||
|
|
||||||
---@param cmd (string|number)[]
|
---@param cmd (string|number)[]
|
||||||
---@param on_exit fun(out:vim.SystemCompleted)
|
---@param on_exit fun(out:vim.SystemCompleted)
|
||||||
---@param opts gopher.RunnerOpts
|
---@param opts? gopher.RunnerOpts
|
||||||
---@return vim.SystemObj
|
---@return vim.SystemObj
|
||||||
function runner.async(cmd, on_exit, opts)
|
function runner.async(cmd, on_exit, opts)
|
||||||
|
opts = opts or {}
|
||||||
return vim.system(cmd, {
|
return vim.system(cmd, {
|
||||||
cwd = opts.cwd or nil,
|
cwd = opts.cwd or nil,
|
||||||
timeout = opts.timeout or 2000,
|
timeout = opts.timeout or 2000,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
local c = require("gopher.config").commands
|
local c = require("gopher.config").commands
|
||||||
local r = require "gopher._utils.runner"
|
local r = require "gopher._utils.runner"
|
||||||
local u = require "gopher._utils"
|
local u = require "gopher._utils"
|
||||||
|
local log = require "gopher._utils.log"
|
||||||
local installer = {}
|
local installer = {}
|
||||||
|
|
||||||
local urls = {
|
local urls = {
|
||||||
|
|
@ -13,16 +14,17 @@ local urls = {
|
||||||
---@param pkg string
|
---@param pkg string
|
||||||
local function install(pkg)
|
local function install(pkg)
|
||||||
local url = urls[pkg] .. "@latest"
|
local url = urls[pkg] .. "@latest"
|
||||||
r.sync(c.go, {
|
local function on_exit(opt)
|
||||||
args = { "install", url },
|
if opt.code ~= 0 then
|
||||||
on_exit = function(data, status)
|
u.deferred_notify("go install failed: " .. url)
|
||||||
if not status == 0 then
|
log.debug("go install failed:", "url", url, "stderr", opt.stderr)
|
||||||
error("go install failed: " .. data)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
u.notify("installed: " .. url)
|
|
||||||
end,
|
u.deferred_notify("go install'ed: " .. url)
|
||||||
})
|
end
|
||||||
|
|
||||||
|
r.async({ c.go, "install", url }, on_exit)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Install required go deps
|
---Install required go deps
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue