go.nvim/lua/go/install.lua

66 lines
1.6 KiB
Lua
Raw Normal View History

2021-03-10 12:15:06 +00:00
local uv = vim.loop
2021-07-14 15:35:38 +00:00
local DIR_SEP = package.config:sub(1, 1)
2021-03-10 12:15:06 +00:00
local url = {
2021-07-14 15:35:38 +00:00
gofumpt = "mvdan.cc/gofumpt",
gofumports = "mvdan.cc/gofumpt",
golines = "github.com/segmentio/golines",
2021-08-24 04:53:37 +00:00
goimports = "golang.org/x/tools/cmd/goimports",
gorename = "golang.org/x/tools/cmd/gorename",
gomodifytags = "github.com/fatih/gomodifytags",
2021-07-14 15:35:38 +00:00
gotsts = "github.com/cweill/gotests",
iferr = 'github.com/koron/iferr',
impl = 'github.com/josharian/impl',
fillstruct = 'github.com/davidrjenni/reftools/cmd/fillstruct',
fixplurals = 'github.com/davidrjenni/reftools/cmd/fixplurals',
fillswitch = 'github.com/davidrjenni/reftools/cmd/fillswitch'
2021-03-10 12:15:06 +00:00
}
local function is_installed(bin)
2021-07-14 15:35:38 +00:00
local env_path = os.getenv("PATH")
local base_paths = vim.split(env_path, ":", true)
2021-07-14 15:35:38 +00:00
for key, value in pairs(base_paths) do
if uv.fs_stat(value .. DIR_SEP .. bin) then
return true
end
2021-07-14 15:35:38 +00:00
end
return false
2021-03-10 12:15:06 +00:00
end
local function go_install(pkg)
local u = url[pkg]
2021-03-10 12:15:06 +00:00
if u == nil then
print("command " .. pkg .. " not supported, please update install.lua, or manually install it")
2021-03-10 12:15:06 +00:00
return
end
2021-04-23 06:31:00 +00:00
u = u .. "@latest"
local setup = {"go", "install", u}
2021-03-10 12:15:06 +00:00
2021-07-14 15:35:38 +00:00
vim.fn.jobstart(setup, {
on_stdout = function(c, data, name)
print(data)
end
})
2021-03-10 12:15:06 +00:00
end
local function install(bin)
if not is_installed(bin) then
print("installing " .. bin)
go_install(bin)
end
end
local function update(bin)
2021-07-14 15:35:38 +00:00
go_install(bin)
end
2021-03-10 12:15:06 +00:00
local function install_all()
for key, value in pairs(url) do
install(key)
end
end
return {install = install, update = update, install_all = install_all}