add new command: govulncheck 🇦🇷 a🇭🇷

This commit is contained in:
ray-x 2022-12-14 08:39:09 +11:00
parent 12d262b99d
commit 5e980b00c7
7 changed files with 65 additions and 2 deletions

View File

@ -612,6 +612,9 @@ Gomvp old_mod_name
Gomvp old_mod_name new_mod_name
### govulncheck
* GoVulnCheck {arguments}
Run govulncheck on current project
### Debug Commands

View File

@ -350,6 +350,10 @@ COMMANDS *go-nvim-commands*
:GoGenReturn
generate return values for current function
:Govulncheck
run govulncheck on current project
==============================================================================
OPTIONS *go-nvim-options*

View File

@ -228,7 +228,7 @@ function M.make(...)
syntax = 'lua',
rect = { height = 1, width = 30},
data = { 'Running '.. cmdstr },
timeout = 5000,
timeout = 20000,
hl_line = 1,
})
else

View File

@ -358,5 +358,9 @@ return {
create_cmd('Gomvp', function(opts)
require('go.gomvp').run(opts.fargs)
end, { nargs = '*' })
create_cmd('Govulnckeck', function(opts)
require('go.govulncheck').run(opts.fargs)
end, { nargs = '*' })
end,
}

32
lua/go/govulncheck.lua Normal file
View File

@ -0,0 +1,32 @@
local runner = require('go.runner')
local utils = require('go.utils')
local log = utils.log
local M = {}
function M.run(args)
require('go.install').install('govulncheck')
args = args or {}
local cmd = { 'govulncheck' }
local pkg
if #args > 1 then
pkg = args[2]
else
pkg = './...'
end
vim.list_extend(cmd, { pkg })
log(cmd)
local opts = {
update_buffer = true,
on_exit = function()
vim.schedule(function()
utils.restart()
end)
end,
}
log('running', cmd)
runner.run(cmd, opts)
return cmd, opts
end
return M

View File

@ -24,7 +24,8 @@ local url = {
gotestsum = 'gotest.tools/gotestsum',
mockgen = 'github.com/golang/mock',
['json-to-struct'] = 'github.com/tmc/json-to-struct',
gomvp = 'https://github.com/abenz1267/gomvp',
gomvp = 'github.com/abenz1267/gomvp',
govulncheck = 'golang.org/x/vuln/cmd/govulncheck',
}
local tools = {}

View File

@ -60,6 +60,8 @@ local run = function(cmd, opts)
log(locopts)
vim.schedule(function()
vim.fn.setloclist(0, {}, ' ', locopts)
-- vim.notify(vim.inspect(locopts))
vim.cmd('lopen')
end)
end
return lines
@ -76,6 +78,21 @@ local run = function(cmd, opts)
end
end
log('job:', cmd, job_options)
local Sprite = util.load_plugin('guihua.lua', 'guihua.sprite')
local sprite
if Sprite then
sprite = Sprite:new({
loc = 'top_center',
syntax = 'lua',
rect = { height = 1, width = 30},
data = { 'Running '.. vim.inspect(cmd) },
timeout = 30000,
hl_line = 1,
})
else
sprite = {on_close = function() end}
end
handle, _ = uv.spawn(
cmd,
{ stdio = { stdin, stdout, stderr }, args = job_options.args },
@ -89,6 +106,8 @@ local run = function(cmd, opts)
stderr:close()
handle:close()
log("spawn finished", code, signal)
sprite.on_close()
if output_stderr ~= '' then
vim.schedule(function()