refactor(runner.gocmd): use vim.system
This commit is contained in:
parent
20f0bcbd00
commit
3688a65cf9
1 changed files with 16 additions and 22 deletions
|
|
@ -1,22 +1,23 @@
|
||||||
local r = require "gopher._utils.runner"
|
local r = require "gopher._utils.runner"
|
||||||
local c = require("gopher.config").commands
|
local c = require("gopher.config").commands
|
||||||
local u = require "gopher._utils"
|
local u = require "gopher._utils"
|
||||||
|
local log = require "gopher._utils.log"
|
||||||
local gocmd = {}
|
local gocmd = {}
|
||||||
|
|
||||||
---@param args string[]
|
---@param args string[]
|
||||||
---@return string[]
|
---@return string[]
|
||||||
local function if_get(args)
|
local function handle_get_cmd(args)
|
||||||
for i, arg in ipairs(args) do
|
for i, arg in ipairs(args) do
|
||||||
local m = string.match(arg, "^https://(.*)$") or string.match(arg, "^http://(.*)$") or arg
|
local m = string.match(arg, "^https?://(.*)$") or arg
|
||||||
table.remove(args, i)
|
table.remove(args, i)
|
||||||
table.insert(args, i, m)
|
table.insert(args, i, m)
|
||||||
end
|
end
|
||||||
return args
|
return args
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param args unknown[]
|
---@param args string[]
|
||||||
---@return string[]
|
---@return string[]
|
||||||
local function if_generate(args)
|
local function handle_generate_cmd(args)
|
||||||
if #args == 1 and args[1] == "%" then
|
if #args == 1 and args[1] == "%" then
|
||||||
args[1] = vim.fn.expand "%"
|
args[1] = vim.fn.expand "%"
|
||||||
end
|
end
|
||||||
|
|
@ -25,29 +26,22 @@ end
|
||||||
|
|
||||||
---@param subcmd string
|
---@param subcmd string
|
||||||
---@param args string[]
|
---@param args string[]
|
||||||
---@return string[]|nil
|
|
||||||
function gocmd.run(subcmd, args)
|
function gocmd.run(subcmd, args)
|
||||||
if #args == 0 then
|
args = args or {}
|
||||||
error "please provice any arguments"
|
|
||||||
end
|
|
||||||
|
|
||||||
if subcmd == "get" then
|
if subcmd == "get" then
|
||||||
args = if_get(args)
|
args = handle_get_cmd(args)
|
||||||
|
elseif subcmd == "generate" then
|
||||||
|
args = handle_generate_cmd(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
if subcmd == "generate" then
|
r.async({ c.go, unpack(args) }, function(opt)
|
||||||
args = if_generate(args)
|
if opt.code ~= 0 then
|
||||||
end
|
log.error("go " .. subcmd .. " failed: " .. opt.stderr)
|
||||||
|
error("go " .. subcmd .. " failed: " .. opt.stderr)
|
||||||
|
end
|
||||||
|
|
||||||
return r.sync(c.go, {
|
u.notify("go " .. subcmd .. " output: " .. opt.stdout)
|
||||||
args = { subcmd, unpack(args) },
|
end)
|
||||||
on_exit = function(data, status)
|
|
||||||
if status ~= 0 then
|
|
||||||
error("gocmd failed: " .. data)
|
|
||||||
end
|
|
||||||
u.notify(c.go .. " " .. subcmd .. " successful runned")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return gocmd
|
return gocmd
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue