refactor(cli): promote sync backends to top-level subcommands
Problem: `:Pending sync gtasks auth` required an extra `sync` keyword
that added no value and made the command unnecessarily verbose.
Solution: route `gtasks` and `gcal` as top-level `:Pending` subcommands
via `SYNC_BACKEND_SET` lookup. Tab completion introspects backend
modules for available actions instead of hardcoding `{ 'auth', 'sync' }`.
This commit is contained in:
parent
27647d0575
commit
ffc588ccf9
3 changed files with 50 additions and 64 deletions
|
|
@ -523,14 +523,19 @@ function M.add(text)
|
|||
vim.notify('Pending added: ' .. description)
|
||||
end
|
||||
|
||||
---@type string[]
|
||||
local SYNC_BACKENDS = { 'gcal', 'gtasks' }
|
||||
|
||||
---@type table<string, true>
|
||||
local SYNC_BACKEND_SET = {}
|
||||
for _, b in ipairs(SYNC_BACKENDS) do
|
||||
SYNC_BACKEND_SET[b] = true
|
||||
end
|
||||
|
||||
---@param backend_name string
|
||||
---@param action? string
|
||||
---@return nil
|
||||
function M.sync(backend_name, action)
|
||||
if not backend_name or backend_name == '' then
|
||||
vim.notify('Usage: :Pending sync <backend> [action]', vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
local function run_sync(backend_name, action)
|
||||
action = (action and action ~= '') and action or 'sync'
|
||||
local ok, backend = pcall(require, 'pending.sync.' .. backend_name)
|
||||
if not ok then
|
||||
|
|
@ -835,9 +840,9 @@ function M.command(args)
|
|||
elseif cmd == 'edit' then
|
||||
local id_str, edit_rest = rest:match('^(%S+)%s*(.*)')
|
||||
M.edit(id_str, edit_rest)
|
||||
elseif cmd == 'sync' then
|
||||
local backend, action = rest:match('^(%S+)%s*(.*)')
|
||||
M.sync(backend, action)
|
||||
elseif SYNC_BACKEND_SET[cmd] then
|
||||
local action = rest:match('^(%S+)') or 'sync'
|
||||
run_sync(cmd, action)
|
||||
elseif cmd == 'archive' then
|
||||
local d = rest ~= '' and tonumber(rest) or nil
|
||||
M.archive(d)
|
||||
|
|
@ -854,4 +859,14 @@ function M.command(args)
|
|||
end
|
||||
end
|
||||
|
||||
---@return string[]
|
||||
function M.sync_backends()
|
||||
return SYNC_BACKENDS
|
||||
end
|
||||
|
||||
---@return table<string, true>
|
||||
function M.sync_backend_set()
|
||||
return SYNC_BACKEND_SET
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue