refactor(credentials): promote login/logout to top-level actions (#292)

## Problem

`:CP credentials login/logout/clear` is verbose and inconsistent with
other
actions that are all top-level (`:CP run`, `:CP submit`, etc.). The
clear-all
subcommand is also unnecessary since re-logging in overwrites existing
credentials.

## Solution

Replace `:CP credentials {login,logout,clear}` with `:CP login
[platform]`
and `:CP logout [platform]`. Remove the clear-all command and the
credentials
subcommand dispatch — login/logout are now regular actions routed
through the
standard action dispatcher.
This commit is contained in:
Barrett Ruth 2026-03-04 13:09:32 -05:00 committed by GitHub
parent 98ac0aa7a7
commit 49e0ae3885
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 28 additions and 73 deletions

View file

@ -83,28 +83,8 @@ local function parse_command(args)
else
return { type = 'action', action = 'interact' }
end
elseif first == 'credentials' then
local subcommand = args[2]
if not subcommand then
return {
type = 'error',
message = 'credentials command requires subcommand (login, logout, clear)',
}
end
if vim.tbl_contains({ 'login', 'logout' }, subcommand) then
return {
type = 'credentials',
subcommand = subcommand,
platform = args[3],
}
elseif subcommand == 'clear' then
return {
type = 'credentials',
subcommand = 'clear',
}
else
return { type = 'error', message = 'unknown credentials subcommand: ' .. subcommand }
end
elseif first == 'login' or first == 'logout' then
return { type = 'action', action = first, platform = args[2] }
elseif first == 'stress' then
return {
type = 'action',
@ -345,6 +325,10 @@ function M.handle_command(opts)
require('cp.race').start(cmd.platform, cmd.contest, cmd.language)
elseif cmd.action == 'race_stop' then
require('cp.race').stop()
elseif cmd.action == 'login' then
require('cp.credentials').login(cmd.platform)
elseif cmd.action == 'logout' then
require('cp.credentials').logout(cmd.platform)
end
elseif cmd.type == 'problem_jump' then
local platform = state.get_platform()
@ -374,15 +358,6 @@ 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 == 'login' then
creds.login(cmd.platform)
elseif cmd.subcommand == 'logout' then
creds.logout(cmd.platform)
elseif cmd.subcommand == 'clear' then
creds.clear()
end
elseif cmd.type == 'cache' then
local cache_commands = require('cp.commands.cache')
cache_commands.handle_cache_command(cmd)

View file

@ -13,7 +13,8 @@ M.ACTIONS = {
'race',
'stress',
'submit',
'credentials',
'login',
'logout',
}
M.PLATFORM_DISPLAY_NAMES = {

View file

@ -7,10 +7,7 @@ local state = require('cp.state')
function M.login(platform)
platform = platform or state.get_platform()
if not platform then
logger.log(
'No platform specified. Usage: :CP credentials login <platform>',
vim.log.levels.ERROR
)
logger.log('No platform specified. Usage: :CP login <platform>', vim.log.levels.ERROR)
return
end
@ -35,10 +32,7 @@ end
function M.logout(platform)
platform = platform or state.get_platform()
if not platform then
logger.log(
'No platform specified. Usage: :CP credentials logout <platform>',
vim.log.levels.ERROR
)
logger.log('No platform specified. Usage: :CP logout <platform>', vim.log.levels.ERROR)
return
end
cache.load()
@ -46,10 +40,4 @@ function M.logout(platform)
logger.log(platform .. ' credentials cleared', vim.log.levels.INFO, true)
end
function M.clear()
cache.load()
cache.clear_credentials(nil)
logger.log('all credentials cleared', vim.log.levels.INFO, true)
end
return M