gopher.nvim/lua/gopher/_utils/runner/gocmd.lua
Smirnov Oleksandr 9aa0038125
refactor: minimize amount of vimscript (#96)
* refactor: remove autoload

* since nvim 0.9 health.lua files are threaded as checkhealth provider

*  prof of concept 

* fix(runner.gocmd)!: i forgot to update it when i was working on #85

* fix(plugin): now commands register properly

* fix(plugin): fix command name for :GoIfErr

* fix(plugin): respect `setup_commands` option

* docs: update

* refactor(plugin): use vim.schedule

* docs: update CONTRIBUTING
2025-03-21 21:44:42 +02:00

51 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
function gocmd.run(subcmd, args)
if #args == 0 and subcmd ~= "generate" then
error "please provide any arguments"
end
if subcmd == "get" then
args = if_get(args)
end
if subcmd == "generate" then
args = if_generate(args)
end
local rs = r.sync { c.go, subcmd, unpack(args) }
if rs.code ~= 0 then
error("go " .. subcmd .. " failed: " .. rs.stderr)
end
u.notify(c.go .. " " .. subcmd .. " ran successful")
return rs.stdout
end
return gocmd