feat(init): add clear and reset actions to :Pending auth

Problem: no CLI path existed to wipe stale tokens or reset credentials,
and the `vim.ui.select` backend picker was misleading given shared tokens.

Solution: accept an args string in `M.auth()`, dispatching `clear` to
`clear_tokens()`, `reset` to `_wipe()`, and bare backend names to the
existing auth flow. Remove the picker.
This commit is contained in:
Barrett Ruth 2026-03-06 12:33:53 -05:00
parent cfdcff9eba
commit c45aacfcbb

View file

@ -918,22 +918,33 @@ function M.edit(id_str, rest)
log.info('Task #' .. id .. ' updated: ' .. table.concat(feedback, ', '))
end
---@param args? string
---@return nil
function M.auth()
function M.auth(args)
local oauth = require('pending.sync.oauth')
vim.ui.select({ 'Google Tasks', 'Google Calendar', 'Google Tasks and Google Calendar' }, {
prompt = 'Authenticate with:',
}, function(choice)
if not choice then
return
end
local parts = {}
for w in (args or ''):gmatch('%S+') do
table.insert(parts, w)
end
local action = parts[#parts]
if action == parts[1] and (action == 'gtasks' or action == 'gcal') then
action = nil
end
if action == 'clear' then
oauth.google_client:clear_tokens()
log.info('OAuth tokens cleared — run :Pending auth to re-authenticate.')
elseif action == 'reset' then
oauth.google_client:_wipe()
log.info('OAuth tokens and credentials cleared — run :Pending auth to set up from scratch.')
else
local creds = oauth.google_client:resolve_credentials()
if creds.client_id == oauth.BUNDLED_CLIENT_ID then
oauth.google_client:setup()
else
oauth.google_client:auth()
end
end)
end
end
---@param args string
@ -952,7 +963,7 @@ function M.command(args)
local id_str, edit_rest = rest:match('^(%S+)%s*(.*)')
M.edit(id_str, edit_rest)
elseif cmd == 'auth' then
M.auth()
M.auth(rest)
elseif SYNC_BACKEND_SET[cmd] then
local action = rest:match('^(%S+)')
run_sync(cmd, action)