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:
Barrett Ruth 2026-03-05 00:59:00 -05:00
parent 27647d0575
commit ffc588ccf9
3 changed files with 50 additions and 64 deletions

View file

@ -23,7 +23,7 @@ describe('sync', function()
end)
describe('dispatch', function()
it('errors on bare :Pending sync with no backend', function()
it('errors on unknown subcommand', function()
local msg
local orig = vim.notify
vim.notify = function(m, level)
@ -31,35 +31,9 @@ describe('sync', function()
msg = m
end
end
pending.sync(nil)
pending.command('notreal')
vim.notify = orig
assert.are.equal('Usage: :Pending sync <backend> [action]', msg)
end)
it('errors on empty backend string', function()
local msg
local orig = vim.notify
vim.notify = function(m, level)
if level == vim.log.levels.ERROR then
msg = m
end
end
pending.sync('')
vim.notify = orig
assert.are.equal('Usage: :Pending sync <backend> [action]', msg)
end)
it('errors on unknown backend', function()
local msg
local orig = vim.notify
vim.notify = function(m, level)
if level == vim.log.levels.ERROR then
msg = m
end
end
pending.sync('notreal')
vim.notify = orig
assert.are.equal('Unknown sync backend: notreal', msg)
assert.are.equal('Unknown Pending subcommand: notreal', msg)
end)
it('errors on unknown action for valid backend', function()
@ -70,7 +44,7 @@ describe('sync', function()
msg = m
end
end
pending.sync('gcal', 'notreal')
pending.command('gcal notreal')
vim.notify = orig
assert.are.equal("gcal backend has no 'notreal' action", msg)
end)
@ -82,7 +56,7 @@ describe('sync', function()
gcal.sync = function()
called = true
end
pending.sync('gcal')
pending.command('gcal')
gcal.sync = orig_sync
assert.is_true(called)
end)
@ -94,7 +68,7 @@ describe('sync', function()
gcal.sync = function()
called = true
end
pending.sync('gcal', 'sync')
pending.command('gcal sync')
gcal.sync = orig_sync
assert.is_true(called)
end)
@ -106,7 +80,7 @@ describe('sync', function()
gcal.auth = function()
called = true
end
pending.sync('gcal', 'auth')
pending.command('gcal auth')
gcal.auth = orig_auth
assert.is_true(called)
end)