feat: add goget support

feat(goget): remove http or https from provided url
This commit is contained in:
Smirnov Olexander 2022-06-07 01:17:51 +03:00
parent f507a37a72
commit 04e1af228b
4 changed files with 38 additions and 0 deletions

View file

@ -43,6 +43,15 @@ By default be added/removed `json` tag, if not set.
:GoMod init asdf " Runs `go mod init asdf`
```
1. Run `go get` command
Link can has a `http` or `https` prefix.
You can provide more that one package url.
```viml
:GoGet github.com/gorilla/mux
```
## Thanks
- [go.nvim](https://github.com/ray-x/go.nvim)

27
lua/gopher/goget.lua Normal file
View file

@ -0,0 +1,27 @@
local Job = require "plenary.job"
return function(...)
local args = { ... }
for i, arg in ipairs(args) do
local m = string.match(arg, "^https://(.*)$") or string.match(arg, "^http://(.*)$") or arg
table.remove(args, i)
table.insert(args, i, m)
end
local cmd_args = vim.list_extend({ "get" }, args)
Job
:new({
command = "go",
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
print("command exited with code " .. retval)
return
else
print "command runs successfully"
end
end,
})
:start()
end

View file

@ -5,5 +5,6 @@ gopher.install_deps = require("gopher.installer").install_all
gopher.tags_add = tags.add
gopher.tags_rm = tags.remove
gopher.mod = require "gopher.gomod"
gopher.get = require "gopher.goget"
return gopher

View file

@ -1,4 +1,5 @@
command! -nargs=* GoTagAdd :lua require"gopher".tags_add(<f-args>)
command! -nargs=* GoTagRm :lua require"gopher".tags_rm(<f-args>)
command! -nargs=* GoMod :lua require"gopher".mod(<f-args>)
command! -nargs=* GoGet :lua require"gopher".get(<f-args>)
command! GoInstallDeps :lua require"gopher".install_deps()