refactor: commands such as :GoGet runs with new runner

This commit is contained in:
Smirnov Oleksandr 2023-08-10 11:10:04 +03:00
parent 12b01a95ec
commit 640a36a7f2
4 changed files with 59 additions and 50 deletions

View file

@ -0,0 +1,30 @@
local Job = require "plenary.job"
local runner = {}
---@class gopher.RunnerOpts
---@field args? string[]
---@field cwd? string?
---@field on_exit? fun(data:string, status:number)
---@param cmd string
---@param opts gopher.RunnerOpts
---@return string[]|nil
function runner.sync(cmd, opts)
local output
Job:new({
command = cmd,
args = opts.args,
cwd = opts.cwd,
on_exit = function(data, status)
output = data:result()
vim.schedule(function()
if opts.on_exit then
opts.on_exit(output, status)
end
end)
end,
}):sync()
return output
end
return runner