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:
parent
cfdcff9eba
commit
c45aacfcbb
1 changed files with 20 additions and 9 deletions
|
|
@ -918,22 +918,33 @@ function M.edit(id_str, rest)
|
||||||
log.info('Task #' .. id .. ' updated: ' .. table.concat(feedback, ', '))
|
log.info('Task #' .. id .. ' updated: ' .. table.concat(feedback, ', '))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param args? string
|
||||||
---@return nil
|
---@return nil
|
||||||
function M.auth()
|
function M.auth(args)
|
||||||
local oauth = require('pending.sync.oauth')
|
local oauth = require('pending.sync.oauth')
|
||||||
vim.ui.select({ 'Google Tasks', 'Google Calendar', 'Google Tasks and Google Calendar' }, {
|
local parts = {}
|
||||||
prompt = 'Authenticate with:',
|
for w in (args or ''):gmatch('%S+') do
|
||||||
}, function(choice)
|
table.insert(parts, w)
|
||||||
if not choice then
|
end
|
||||||
return
|
local action = parts[#parts]
|
||||||
end
|
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()
|
local creds = oauth.google_client:resolve_credentials()
|
||||||
if creds.client_id == oauth.BUNDLED_CLIENT_ID then
|
if creds.client_id == oauth.BUNDLED_CLIENT_ID then
|
||||||
oauth.google_client:setup()
|
oauth.google_client:setup()
|
||||||
else
|
else
|
||||||
oauth.google_client:auth()
|
oauth.google_client:auth()
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param args string
|
---@param args string
|
||||||
|
|
@ -952,7 +963,7 @@ function M.command(args)
|
||||||
local id_str, edit_rest = rest:match('^(%S+)%s*(.*)')
|
local id_str, edit_rest = rest:match('^(%S+)%s*(.*)')
|
||||||
M.edit(id_str, edit_rest)
|
M.edit(id_str, edit_rest)
|
||||||
elseif cmd == 'auth' then
|
elseif cmd == 'auth' then
|
||||||
M.auth()
|
M.auth(rest)
|
||||||
elseif SYNC_BACKEND_SET[cmd] then
|
elseif SYNC_BACKEND_SET[cmd] then
|
||||||
local action = rest:match('^(%S+)')
|
local action = rest:match('^(%S+)')
|
||||||
run_sync(cmd, action)
|
run_sync(cmd, action)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue