---------------------------------------------------------------------------- -- lua/gitea/commands.lua -- -- Single :Gitea command with subcommands for issues, PRs, etc. -- Removed "pr open" as requested. Only "list" and "create" remain for PR. ---------------------------------------------------------------------------- local M = {} -------------------------------------------------------------------------- -- A simple completion function for the :Gitea command -------------------------------------------------------------------------- function M._gitea_cmd_complete(arg_lead, cmd_line, cursor_pos) local tokens = vim.split(cmd_line, "%s+") -- If the user hasn't typed anything after ":Gitea", suggest top-level words if #tokens <= 1 then return { "issue", "pr" } end local main_sub = tokens[2] if #tokens == 2 then local candidates = { "issue", "pr" } local results = {} for _, c in ipairs(candidates) do if c:find("^" .. arg_lead) then table.insert(results, c) end end return results end -- If "issue" was selected, next subcommands can be list, create if main_sub == "issue" then if #tokens == 3 then local candidates = { "list", "create" } local results = {} for _, c in ipairs(candidates) do if c:find("^" .. arg_lead) then table.insert(results, c) end end return results end return {} end -- If "pr" was selected, next subcommands can be list, create -- (removed "open" and "merge" as subcommands) if main_sub == "pr" then if #tokens == 3 then local candidates = { "list", "create" } local results = {} for _, c in ipairs(candidates) do if c:find("^" .. arg_lead) then table.insert(results, c) end end return results end return {} end return {} end function M.setup_commands(core) local issues_mod = require("gitea.issues") local telescope_mod = require("gitea.telescope") -- local pulls_mod = require("gitea.pulls") -- if needed vim.api.nvim_create_user_command("Gitea", function(opts) local args = vim.split(opts.args, "%s+") local main = args[1] or "" if main == "issue" then local sub = args[2] or "" if sub == "list" then -- :Gitea issue list telescope_mod.list_issues_in_telescope() elseif sub == "create" then -- :Gitea issue create [owner] [repo] ... if #args < 3 then vim.cmd([[echoerr "Usage: :Gitea issue create <title> [body...]"]]) return end local owner, repo, title, body if #args >= 5 then owner = args[3] repo = args[4] title = args[5] body = table.concat(vim.list_slice(args, 6), " ") else title = args[3] body = table.concat(vim.list_slice(args, 4), " ") end issues_mod.create_issue(owner, repo, title, body) else print("Unknown issue subcommand: " .. sub) print("Available subcommands: list, create") end elseif main == "pr" then local sub = args[2] or "" if sub == "list" then vim.cmd([[echo "TODO: :Gitea pr list"]]) elseif sub == "create" then vim.cmd([[echo "TODO: :Gitea pr create"]]) else print("Unknown PR subcommand: " .. sub) print("Available subcommands: list, create") end else print("Usage: :Gitea <issue|pr> <subcommand> [arguments...]") print("For issues: list, create") print("For PRs: list, create") end end, { nargs = "*", desc = "Unified Gitea command with subcommands", complete = M._gitea_cmd_complete, }) end return M