add go boilerplate

pull/117/head
ray-x 2 years ago
parent eba7daeb16
commit 0c8ffc2b86

@ -38,6 +38,7 @@ _GO_NVIM_CFG = {
lsp_diag_virtual_text = { space = 0, prefix = "" },
lsp_diag_signs = true,
lsp_diag_update_in_insert = false,
go_boilplater_url = "https://github.com/thockin/go-build-template.git",
gopls_cmd = nil, --- you can provide gopls path and cmd if it not in PATH, e.g. cmd = { "/home/ray/.local/nvim/data/lspinstall/go/gopls" }
gopls_remote_auto = true,
gocoverage_sign = "",

@ -0,0 +1,17 @@
local M = {}
local util = require("go.utils")
local log = util.log
local warn = require("go.utils").warn
local function create_boilerplate(name)
if not _GO_NVIM_CFG.go_boilplater_url then
return warn("go boilerplate url missing")
end
local path = name or vim.fn.expand("%:p:h")
local cmd = 'git clone --depth 1 --branch master ' .. _GO_NVIM_CFG.go_boilplater_url .. ' ' .. path
log(cmd)
vim.notify( "create boilerplate project: " .. vim.fn.system(cmd))
util.deletedir(path .. "/.git")
end
return {create_boilerplate=create_boilerplate}

@ -495,4 +495,22 @@ function util.restart(cmd_args)
end
end
util.deletedir = function(dir)
local lfs = require("lfs")
for file in lfs.dir(dir) do
local file_path = dir .. "/" .. file
if file ~= "." and file ~= ".." then
if lfs.attributes(file_path, "mode") == "file" then
os.remove(file_path)
print("remove file", file_path)
elseif lfs.attributes(file_path, "mode") == "directory" then
print("dir", file_path)
util.deletedir(file_path)
end
end
end
lfs.rmdir(dir)
util.log("remove dir", dir)
end
return util

Loading…
Cancel
Save