refactor: commands such as :GoGet runs with new runner
This commit is contained in:
parent
12b01a95ec
commit
640a36a7f2
4 changed files with 59 additions and 50 deletions
30
lua/gopher/_utils/runner/init.lua
Normal file
30
lua/gopher/_utils/runner/init.lua
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue