local c = require "gopher.config" local u = require "gopher._utils" local r = require "gopher._utils.runner" local go = {} local function run(subcmd, args) local rs = r.sync { c.commands.go, subcmd, unpack(args) } if rs.code ~= 0 then error("go " .. subcmd .. " failed: " .. rs.stderr) end u.notify(c.commands.go .. " " .. subcmd .. " ran successful") return rs.stdout end ---@param args string[] function go.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 run("get", args) end ---@param args string[] function go.mod(args) run("mod", args) end ---@param args string[] function go.work(args) -- TODO: use `gopls.tidy` run("work", args) end ---Executes `go generate` ---If only argument is `%` it's going to be equivalent to `go generate ` ---@param args string[] function go.generate(args) -- TODO: use `gopls.generate` if #args == 0 then error "please provide arguments" end if #args == 1 and args[1] == "%" then args[1] = vim.fn.expand "%" end run("generate", args) end return go