From ccaedfebc166c0a082854e0adf4a3ce4076d9261 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 5 Mar 2026 14:10:05 -0500 Subject: [PATCH] refactor(commands): move login/logout under platform namespace Problem: `:CP login codeforces` was inconsistent with every other command which uses `:CP ` 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. --- lua/cp/commands/init.lua | 5 +++-- lua/cp/constants.lua | 2 -- plugin/cp.lua | 8 +++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lua/cp/commands/init.lua b/lua/cp/commands/init.lua index 64e37fb..4c594bd 100644 --- a/lua/cp/commands/init.lua +++ b/lua/cp/commands/init.lua @@ -83,8 +83,6 @@ local function parse_command(args) else return { type = 'action', action = 'interact' } end - elseif first == 'login' or first == 'logout' then - return { type = 'action', action = first, platform = args[2] } elseif first == 'stress' then return { type = 'action', @@ -245,6 +243,9 @@ local function parse_command(args) message = 'Too few arguments - specify a contest.', } elseif #args == 2 then + if args[2] == 'login' or args[2] == 'logout' then + return { type = 'action', action = args[2], platform = first } + end return { type = 'contest_setup', platform = first, diff --git a/lua/cp/constants.lua b/lua/cp/constants.lua index 5d1c3c5..21e8f62 100644 --- a/lua/cp/constants.lua +++ b/lua/cp/constants.lua @@ -13,8 +13,6 @@ M.ACTIONS = { 'race', 'stress', 'submit', - 'login', - 'logout', } M.PLATFORM_DISPLAY_NAMES = { diff --git a/plugin/cp.lua b/plugin/cp.lua index db9a8bd..60efb7a 100644 --- a/plugin/cp.lua +++ b/plugin/cp.lua @@ -43,7 +43,6 @@ end, { vim.list_extend(candidates, platforms) table.insert(candidates, 'cache') table.insert(candidates, 'pick') - if platform and contest_id then vim.list_extend(candidates, actions) local cache = require('cp.cache') @@ -60,10 +59,11 @@ end, { return filter_candidates(candidates) elseif num_args == 3 then if vim.tbl_contains(platforms, args[2]) then + local candidates = { 'login', 'logout' } local cache = require('cp.cache') cache.load() - local contests = cache.get_cached_contest_ids(args[2]) - return filter_candidates(contests) + vim.list_extend(candidates, cache.get_cached_contest_ids(args[2])) + return filter_candidates(candidates) elseif args[2] == 'cache' then return filter_candidates({ 'clear', 'read' }) elseif args[2] == 'stress' or args[2] == 'interact' then @@ -103,8 +103,6 @@ end, { end end return filter_candidates(candidates) - elseif args[2] == 'login' or args[2] == 'logout' then - return filter_candidates(platforms) elseif args[2] == 'race' then local candidates = { 'stop' } vim.list_extend(candidates, platforms)