refactor: replace :CP login with :CP credentials subcommand
Problem: :CP login was a poor API — no way to clear credentials without raw Lua, and the single command didn't scale to multiple operations. Solution: replace login with a :CP credentials subcommand following the same pattern as :CP cache. :CP credentials set [platform] prompts and saves; :CP credentials clear [platform] removes one or all platforms. Add cache.clear_credentials(), rename login.lua to credentials.lua, update parse/dispatch/tab-complete, and rewrite vimdoc accordingly.
This commit is contained in:
parent
3e0b7beabf
commit
a04702d87c
6 changed files with 88 additions and 32 deletions
|
|
@ -83,12 +83,20 @@ local function parse_command(args)
|
|||
else
|
||||
return { type = 'action', action = 'interact' }
|
||||
end
|
||||
elseif first == 'login' then
|
||||
return {
|
||||
type = 'action',
|
||||
action = 'login',
|
||||
platform = args[2],
|
||||
}
|
||||
elseif first == 'credentials' then
|
||||
local subcommand = args[2]
|
||||
if not subcommand then
|
||||
return { type = 'error', message = 'credentials command requires subcommand (set, clear)' }
|
||||
end
|
||||
if vim.tbl_contains({ 'set', 'clear' }, subcommand) then
|
||||
return {
|
||||
type = 'credentials',
|
||||
subcommand = subcommand,
|
||||
platform = args[3],
|
||||
}
|
||||
else
|
||||
return { type = 'error', message = 'unknown credentials subcommand: ' .. subcommand }
|
||||
end
|
||||
elseif first == 'stress' then
|
||||
return {
|
||||
type = 'action',
|
||||
|
|
@ -323,8 +331,6 @@ function M.handle_command(opts)
|
|||
edit.toggle_edit(cmd.test_index)
|
||||
elseif cmd.action == 'stress' then
|
||||
require('cp.stress').toggle(cmd.generator_cmd, cmd.brute_cmd)
|
||||
elseif cmd.action == 'login' then
|
||||
require('cp.login').login(cmd.platform)
|
||||
elseif cmd.action == 'submit' then
|
||||
require('cp.submit').submit({ language = cmd.language })
|
||||
elseif cmd.action == 'race' then
|
||||
|
|
@ -360,6 +366,13 @@ function M.handle_command(opts)
|
|||
|
||||
local setup = require('cp.setup')
|
||||
setup.setup_contest(platform, contest_id, problem_id, cmd.language)
|
||||
elseif cmd.type == 'credentials' then
|
||||
local creds = require('cp.credentials')
|
||||
if cmd.subcommand == 'set' then
|
||||
creds.set(cmd.platform)
|
||||
elseif cmd.subcommand == 'clear' then
|
||||
creds.clear(cmd.platform)
|
||||
end
|
||||
elseif cmd.type == 'cache' then
|
||||
local cache_commands = require('cp.commands.cache')
|
||||
cache_commands.handle_cache_command(cmd)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue