refactor: use vim.system instead of pleanry (#85)
* refactor!: migrate to vim.system * refactor(gotests): use vim.system * refactor(iferr): use vim.system * refactor(impl): use vim.system * refactor(installer): use vim.system and add sync mode * test: fix gotests' tests * refactor(struct_tags): use vim.system * chore(ci): install all deps explicitly * refactor(installer)!: add sync as an option * docs: update readme
This commit is contained in:
parent
837897a79d
commit
6016ca57d4
16 changed files with 169 additions and 126 deletions
|
|
@ -1,6 +1,7 @@
|
|||
local c = require("gopher.config").commands
|
||||
local r = require "gopher._utils.runner"
|
||||
local u = require "gopher._utils"
|
||||
local log = require "gopher._utils.log"
|
||||
local installer = {}
|
||||
|
||||
local urls = {
|
||||
|
|
@ -10,25 +11,42 @@ local urls = {
|
|||
iferr = "github.com/koron/iferr",
|
||||
}
|
||||
|
||||
---@param pkg string
|
||||
local function install(pkg)
|
||||
local url = urls[pkg] .. "@latest"
|
||||
r.sync(c.go, {
|
||||
args = { "install", url },
|
||||
on_exit = function(data, status)
|
||||
if not status == 0 then
|
||||
error("go install failed: " .. data)
|
||||
return
|
||||
end
|
||||
u.notify("installed: " .. url)
|
||||
end,
|
||||
})
|
||||
---@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.error("go install failed:", "url", url, "opt", vim.inspect(opt))
|
||||
return
|
||||
end
|
||||
|
||||
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 opts? {sync:boolean}
|
||||
function installer.install_deps(opts)
|
||||
opts = opts or {}
|
||||
for pkg, _ in pairs(urls) do
|
||||
install(pkg)
|
||||
local url = urls[pkg] .. "@latest"
|
||||
if opts.sync then
|
||||
install_sync(url)
|
||||
else
|
||||
install(url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue