* feat(utils): first impl of own commands runner * refactor(gotests): uses own runner instead of vendored * refactor(utils): back to plenary.job * refactor(gotests): use new runner, clean code * fix(runner): now it returns output correctly * refactor(iferr): use vim.system i have tried to use _utils.runner, but i can't figure out how to make `< file.go` for the command * refactor(impl): use new runner * refactor(installer): use new runner * refactor(struct_tags): use new runner * refactor: commands such as :GoGet runs with new runner * refactor: throw errors in more lua way, i think * refactor(utils): notify now has title * refactor: use more correct way of notifying * refactor(runner): write error message on error
53 lines
1.1 KiB
Lua
53 lines
1.1 KiB
Lua
local r = require "gopher._utils.runner"
|
|
local c = require("gopher.config").commands
|
|
local u = require "gopher._utils"
|
|
local gocmd = {}
|
|
|
|
---@param args string[]
|
|
---@return string[]
|
|
local function if_get(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
|
|
return args
|
|
end
|
|
|
|
---@param args unknown[]
|
|
---@return string[]
|
|
local function if_generate(args)
|
|
if #args == 1 and args[1] == "%" then
|
|
args[1] = vim.fn.expand "%"
|
|
end
|
|
return args
|
|
end
|
|
|
|
---@param subcmd string
|
|
---@param args string[]
|
|
---@return string[]|nil
|
|
function gocmd.run(subcmd, args)
|
|
if #args == 0 then
|
|
error "please provice any arguments"
|
|
end
|
|
|
|
if subcmd == "get" then
|
|
args = if_get(args)
|
|
end
|
|
|
|
if subcmd == "generate" then
|
|
args = if_generate(args)
|
|
end
|
|
|
|
return r.sync(c.go, {
|
|
args = { subcmd, unpack(args) },
|
|
on_exit = function(data, status)
|
|
if status ~= 0 then
|
|
error("gocmd failed: " .. data)
|
|
end
|
|
u.notify(c.go .. " " .. subcmd .. " successful runned")
|
|
end,
|
|
})
|
|
end
|
|
|
|
return gocmd
|