You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go.nvim/lua/go/install.lua

68 lines
1.7 KiB
Lua

3 years ago
local uv = vim.loop
3 years ago
local DIR_SEP = package.config:sub(1, 1)
3 years ago
local url = {
3 years ago
gofumpt = "mvdan.cc/gofumpt",
golines = "github.com/segmentio/golines",
goimports = "golang.org/x/tools/cmd/goimports",
gorename = "golang.org/x/tools/cmd/gorename",
gomodifytags = "github.com/fatih/gomodifytags",
gotests = "github.com/cweill/gotests",
3 years ago
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',
dlv = 'github.com/go-delve/delve/cmd/dlv',
ginkgo = 'github.com/onsi/ginkgo/ginkgo',
richgo = 'github.com/kyoh86/richgo'
3 years ago
}
local function is_installed(bin)
3 years ago
local env_path = os.getenv("PATH")
local base_paths = vim.split(env_path, ":", true)
3 years ago
for key, value in pairs(base_paths) do
if uv.fs_stat(value .. DIR_SEP .. bin) then
return true
end
3 years ago
end
return false
3 years ago
end
local function go_install(pkg)
local u = url[pkg]
3 years ago
if u == nil then
print("command " .. pkg .. " not supported, please update install.lua, or manually install it")
3 years ago
return
end
u = u .. "@latest"
local setup = {"go", "install", u}
3 years ago
3 years ago
vim.fn.jobstart(setup, {
on_stdout = function(c, data, name)
print(data)
end
})
3 years ago
end
local function install(bin)
if not is_installed(bin) then
print("installing " .. bin)
go_install(bin)
end
end
local function update(bin)
3 years ago
go_install(bin)
end
3 years ago
local function install_all()
for key, value in pairs(url) do
install(key)
end
end
return {install = install, update = update, install_all = install_all}