refactor(sync): extract backend interface, adapt gcal module
Problem: :Pending sync hardcodes Google Calendar — M.sync() does
pcall(require, 'pending.sync.gcal') and calls gcal.sync() directly.
The config has a flat gcal field. This prevents adding new sync backends
without modifying init.lua.
Solution: Define a backend interface contract (name, auth, sync, health
fields), refactor :Pending sync to dispatch via require('pending.sync.'
.. backend_name), add sync table to config with legacy gcal migration,
rename gcal.authorize to gcal.auth, add gcal.health for checkhealth,
and add tab completion for backend names and actions.
This commit is contained in:
parent
8d3d21b330
commit
7de9c23ec1
5 changed files with 85 additions and 18 deletions
|
|
@ -171,6 +171,34 @@ end, {
|
|||
if cmd_line:match('^Pending%s+edit') then
|
||||
return complete_edit(arg_lead, cmd_line)
|
||||
end
|
||||
if cmd_line:match('^Pending%s+sync') then
|
||||
local after_sync = cmd_line:match('^Pending%s+sync%s+(.*)')
|
||||
if not after_sync then
|
||||
return {}
|
||||
end
|
||||
local parts = {}
|
||||
for part in after_sync:gmatch('%S+') do
|
||||
table.insert(parts, part)
|
||||
end
|
||||
local trailing_space = after_sync:match('%s$')
|
||||
if #parts == 0 or (#parts == 1 and not trailing_space) then
|
||||
local backends = {}
|
||||
local pattern = vim.fn.globpath(vim.o.runtimepath, 'lua/pending/sync/*.lua', false, true)
|
||||
for _, path in ipairs(pattern) do
|
||||
local name = vim.fn.fnamemodify(path, ':t:r')
|
||||
table.insert(backends, name)
|
||||
end
|
||||
table.sort(backends)
|
||||
return filter_candidates(arg_lead, backends)
|
||||
end
|
||||
if #parts == 1 and trailing_space then
|
||||
return filter_candidates(arg_lead, { 'auth', 'sync' })
|
||||
end
|
||||
if #parts >= 2 and not trailing_space then
|
||||
return filter_candidates(arg_lead, { 'auth', 'sync' })
|
||||
end
|
||||
return {}
|
||||
end
|
||||
return {}
|
||||
end,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue