refactor(commands): move login/logout under platform namespace

Problem: `:CP login codeforces` was inconsistent with every other
command which uses `:CP <platform> <action>` ordering.

Solution: restructure to `:CP codeforces login` / `:CP codeforces
logout`. Remove `login`/`logout` from top-level `ACTIONS` and move
parsing into the platform branch of `parse_command`. Update completion
to offer `login`/`logout` as platform subcommands.
This commit is contained in:
Barrett Ruth 2026-03-05 14:10:05 -05:00
parent df934efb19
commit ccaedfebc1
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
3 changed files with 6 additions and 9 deletions

View file

@ -83,8 +83,6 @@ local function parse_command(args)
else else
return { type = 'action', action = 'interact' } return { type = 'action', action = 'interact' }
end end
elseif first == 'login' or first == 'logout' then
return { type = 'action', action = first, platform = args[2] }
elseif first == 'stress' then elseif first == 'stress' then
return { return {
type = 'action', type = 'action',
@ -245,6 +243,9 @@ local function parse_command(args)
message = 'Too few arguments - specify a contest.', message = 'Too few arguments - specify a contest.',
} }
elseif #args == 2 then elseif #args == 2 then
if args[2] == 'login' or args[2] == 'logout' then
return { type = 'action', action = args[2], platform = first }
end
return { return {
type = 'contest_setup', type = 'contest_setup',
platform = first, platform = first,

View file

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

View file

@ -43,7 +43,6 @@ end, {
vim.list_extend(candidates, platforms) vim.list_extend(candidates, platforms)
table.insert(candidates, 'cache') table.insert(candidates, 'cache')
table.insert(candidates, 'pick') table.insert(candidates, 'pick')
if platform and contest_id then if platform and contest_id then
vim.list_extend(candidates, actions) vim.list_extend(candidates, actions)
local cache = require('cp.cache') local cache = require('cp.cache')
@ -60,10 +59,11 @@ end, {
return filter_candidates(candidates) return filter_candidates(candidates)
elseif num_args == 3 then elseif num_args == 3 then
if vim.tbl_contains(platforms, args[2]) then if vim.tbl_contains(platforms, args[2]) then
local candidates = { 'login', 'logout' }
local cache = require('cp.cache') local cache = require('cp.cache')
cache.load() cache.load()
local contests = cache.get_cached_contest_ids(args[2]) vim.list_extend(candidates, cache.get_cached_contest_ids(args[2]))
return filter_candidates(contests) return filter_candidates(candidates)
elseif args[2] == 'cache' then elseif args[2] == 'cache' then
return filter_candidates({ 'clear', 'read' }) return filter_candidates({ 'clear', 'read' })
elseif args[2] == 'stress' or args[2] == 'interact' then elseif args[2] == 'stress' or args[2] == 'interact' then
@ -103,8 +103,6 @@ end, {
end end
end end
return filter_candidates(candidates) return filter_candidates(candidates)
elseif args[2] == 'login' or args[2] == 'logout' then
return filter_candidates(platforms)
elseif args[2] == 'race' then elseif args[2] == 'race' then
local candidates = { 'stop' } local candidates = { 'stop' }
vim.list_extend(candidates, platforms) vim.list_extend(candidates, platforms)