refactor(git): centralize registrations, defer submodule loads
This commit is contained in:
+31
-41
@@ -115,49 +115,39 @@ function M.open(opts)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
local group = vim.api.nvim_create_augroup("ow.git.log", { clear = true })
|
||||
vim.api.nvim_create_autocmd("BufReadCmd", {
|
||||
pattern = "gitlog://*",
|
||||
group = group,
|
||||
callback = function(args)
|
||||
M.read_uri(args.buf)
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("Glog", function(cmd_opts)
|
||||
local parsed = { max_count = 1000 }
|
||||
for _, a in ipairs(cmd_opts.fargs) do
|
||||
local k, v = a:match("^([%w_]+)=(.*)$")
|
||||
if not k then
|
||||
util.error("invalid argument: %s", a)
|
||||
return
|
||||
end
|
||||
---@cast v -nil
|
||||
local parser = M.opt_parsers[k]
|
||||
if parser then
|
||||
local value = parser(v)
|
||||
if value ~= nil then
|
||||
parsed[k] = value
|
||||
end
|
||||
---@param cmd_opts table
|
||||
function M.run_glog(cmd_opts)
|
||||
local parsed = { max_count = 1000 }
|
||||
for _, a in ipairs(cmd_opts.fargs) do
|
||||
local k, v = a:match("^([%w_]+)=(.*)$")
|
||||
if not k then
|
||||
util.error("invalid argument: %s", a)
|
||||
return
|
||||
end
|
||||
---@cast v -nil
|
||||
local parser = M.opt_parsers[k]
|
||||
if parser then
|
||||
local value = parser(v)
|
||||
if value ~= nil then
|
||||
parsed[k] = value
|
||||
end
|
||||
end
|
||||
M.open(parsed)
|
||||
end, {
|
||||
nargs = "*",
|
||||
complete = function(arg_lead)
|
||||
local matches = {}
|
||||
for k in pairs(M.opt_parsers) do
|
||||
local prefix = k .. "="
|
||||
if prefix:sub(1, #arg_lead) == arg_lead then
|
||||
table.insert(matches, prefix)
|
||||
end
|
||||
end
|
||||
table.sort(matches)
|
||||
return matches
|
||||
end,
|
||||
desc = "Show git log",
|
||||
})
|
||||
end
|
||||
M.open(parsed)
|
||||
end
|
||||
|
||||
---@param arg_lead string
|
||||
---@return string[]
|
||||
function M.complete_glog(arg_lead)
|
||||
local matches = {}
|
||||
for k in pairs(M.opt_parsers) do
|
||||
local prefix = k .. "="
|
||||
if prefix:sub(1, #arg_lead) == arg_lead then
|
||||
table.insert(matches, prefix)
|
||||
end
|
||||
end
|
||||
table.sort(matches)
|
||||
return matches
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user