refactor(credentials): rename set/clear to login/logout/clear (#291)
## Problem The `set` and `clear` subcommands don't clearly convey their intent — `set` reads like a generic setter rather than an auth action, and `clear` overloads single-platform and all-platform semantics in one subcommand. ## Solution Rename `set` to `login`, split `clear` into `logout` (per-platform, defaults to active) and `clear` (all platforms). New API: - `:CP credentials login [platform]` — prompt and save credentials - `:CP credentials logout [platform]` — remove credentials for one platform - `:CP credentials clear` — remove all stored credentials
This commit is contained in:
parent
18a60da2d8
commit
98ac0aa7a7
4 changed files with 58 additions and 29 deletions
|
|
@ -433,27 +433,29 @@ COMMANDS *cp-commands*
|
||||||
Cancel an active race countdown.
|
Cancel an active race countdown.
|
||||||
|
|
||||||
Credential Commands ~
|
Credential Commands ~
|
||||||
:CP credentials set [platform]
|
:CP credentials login [platform]
|
||||||
Set or update stored credentials for a platform.
|
Set or update stored credentials for a platform.
|
||||||
Always prompts for username and password,
|
Always prompts for username and password,
|
||||||
overwriting any previously saved credentials.
|
overwriting any previously saved credentials.
|
||||||
If [platform] is omitted, uses the active platform.
|
If [platform] is omitted, uses the active platform.
|
||||||
Examples: >
|
Examples: >
|
||||||
:CP credentials set atcoder
|
:CP credentials login atcoder
|
||||||
:CP credentials set codeforces
|
:CP credentials login codeforces
|
||||||
<
|
<
|
||||||
:CP credentials clear [platform]
|
:CP credentials logout [platform]
|
||||||
Remove stored credentials. Without [platform],
|
Remove stored credentials for a platform.
|
||||||
clears credentials for all platforms.
|
If [platform] is omitted, uses the active platform.
|
||||||
Examples: >
|
Examples: >
|
||||||
:CP credentials clear atcoder
|
:CP credentials logout atcoder
|
||||||
:CP credentials clear
|
<
|
||||||
|
:CP credentials clear
|
||||||
|
Remove stored credentials for all platforms.
|
||||||
<
|
<
|
||||||
Submit Commands ~
|
Submit Commands ~
|
||||||
:CP submit [--lang {language}]
|
:CP submit [--lang {language}]
|
||||||
Submit the current solution to the online
|
Submit the current solution to the online
|
||||||
judge. Uses stored credentials (set via
|
judge. Uses stored credentials (set via
|
||||||
:CP credentials set). Prompts on first use
|
:CP credentials login). Prompts on first use
|
||||||
if no credentials are saved.
|
if no credentials are saved.
|
||||||
--lang: Submit solution for a specific language.
|
--lang: Submit solution for a specific language.
|
||||||
|
|
||||||
|
|
@ -714,7 +716,7 @@ Example: Setting up and solving AtCoder contest ABC324
|
||||||
|
|
||||||
8. Submit solution: >
|
8. Submit solution: >
|
||||||
:CP submit
|
:CP submit
|
||||||
< Prompts for credentials on first use and submits to AtCoder.
|
< Uses stored credentials and submits to AtCoder.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
I/O VIEW *cp-io-view*
|
I/O VIEW *cp-io-view*
|
||||||
|
|
@ -968,13 +970,17 @@ Manage stored login credentials for platform submission.
|
||||||
Credentials are stored under _credentials in the main cache file
|
Credentials are stored under _credentials in the main cache file
|
||||||
(stdpath('data')/cp-nvim.json). Use :CP cache read to inspect them.
|
(stdpath('data')/cp-nvim.json). Use :CP cache read to inspect them.
|
||||||
|
|
||||||
:CP credentials set [platform]
|
:CP credentials login [platform]
|
||||||
Set or update credentials for a platform. Always prompts for
|
Set or update credentials for a platform. Always prompts for
|
||||||
username and password, overwriting any previously saved values.
|
username and password, overwriting any previously saved values.
|
||||||
Omit [platform] to use the currently active platform.
|
Omit [platform] to use the currently active platform.
|
||||||
|
|
||||||
:CP credentials clear [platform]
|
:CP credentials logout [platform]
|
||||||
Remove stored credentials. Without [platform], clears all platforms.
|
Remove stored credentials for a platform.
|
||||||
|
Omit [platform] to use the currently active platform.
|
||||||
|
|
||||||
|
:CP credentials clear
|
||||||
|
Remove stored credentials for all platforms.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
SUBMIT *cp-submit*
|
SUBMIT *cp-submit*
|
||||||
|
|
@ -983,7 +989,7 @@ Submit the current solution to the online judge.
|
||||||
|
|
||||||
:CP submit [--lang {language}]
|
:CP submit [--lang {language}]
|
||||||
Submit the current solution. Uses stored credentials (set via
|
Submit the current solution. Uses stored credentials (set via
|
||||||
:CP credentials set). Prompts on first use if no credentials
|
:CP credentials login). Prompts on first use if no credentials
|
||||||
are saved.
|
are saved.
|
||||||
--lang: Override the language to submit.
|
--lang: Override the language to submit.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,14 +86,22 @@ local function parse_command(args)
|
||||||
elseif first == 'credentials' then
|
elseif first == 'credentials' then
|
||||||
local subcommand = args[2]
|
local subcommand = args[2]
|
||||||
if not subcommand then
|
if not subcommand then
|
||||||
return { type = 'error', message = 'credentials command requires subcommand (set, clear)' }
|
return {
|
||||||
|
type = 'error',
|
||||||
|
message = 'credentials command requires subcommand (login, logout, clear)',
|
||||||
|
}
|
||||||
end
|
end
|
||||||
if vim.tbl_contains({ 'set', 'clear' }, subcommand) then
|
if vim.tbl_contains({ 'login', 'logout' }, subcommand) then
|
||||||
return {
|
return {
|
||||||
type = 'credentials',
|
type = 'credentials',
|
||||||
subcommand = subcommand,
|
subcommand = subcommand,
|
||||||
platform = args[3],
|
platform = args[3],
|
||||||
}
|
}
|
||||||
|
elseif subcommand == 'clear' then
|
||||||
|
return {
|
||||||
|
type = 'credentials',
|
||||||
|
subcommand = 'clear',
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return { type = 'error', message = 'unknown credentials subcommand: ' .. subcommand }
|
return { type = 'error', message = 'unknown credentials subcommand: ' .. subcommand }
|
||||||
end
|
end
|
||||||
|
|
@ -368,10 +376,12 @@ function M.handle_command(opts)
|
||||||
setup.setup_contest(platform, contest_id, problem_id, cmd.language)
|
setup.setup_contest(platform, contest_id, problem_id, cmd.language)
|
||||||
elseif cmd.type == 'credentials' then
|
elseif cmd.type == 'credentials' then
|
||||||
local creds = require('cp.credentials')
|
local creds = require('cp.credentials')
|
||||||
if cmd.subcommand == 'set' then
|
if cmd.subcommand == 'login' then
|
||||||
creds.set(cmd.platform)
|
creds.login(cmd.platform)
|
||||||
|
elseif cmd.subcommand == 'logout' then
|
||||||
|
creds.logout(cmd.platform)
|
||||||
elseif cmd.subcommand == 'clear' then
|
elseif cmd.subcommand == 'clear' then
|
||||||
creds.clear(cmd.platform)
|
creds.clear()
|
||||||
end
|
end
|
||||||
elseif cmd.type == 'cache' then
|
elseif cmd.type == 'cache' then
|
||||||
local cache_commands = require('cp.commands.cache')
|
local cache_commands = require('cp.commands.cache')
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,13 @@ local cache = require('cp.cache')
|
||||||
local logger = require('cp.log')
|
local logger = require('cp.log')
|
||||||
local state = require('cp.state')
|
local state = require('cp.state')
|
||||||
|
|
||||||
function M.set(platform)
|
function M.login(platform)
|
||||||
platform = platform or state.get_platform()
|
platform = platform or state.get_platform()
|
||||||
if not platform then
|
if not platform then
|
||||||
logger.log('No platform specified. Usage: :CP credentials set <platform>', vim.log.levels.ERROR)
|
logger.log(
|
||||||
|
'No platform specified. Usage: :CP credentials login <platform>',
|
||||||
|
vim.log.levels.ERROR
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -29,14 +32,24 @@ function M.set(platform)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.clear(platform)
|
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
|
||||||
|
)
|
||||||
|
return
|
||||||
|
end
|
||||||
cache.load()
|
cache.load()
|
||||||
cache.clear_credentials(platform)
|
cache.clear_credentials(platform)
|
||||||
if platform then
|
logger.log(platform .. ' credentials cleared', vim.log.levels.INFO, true)
|
||||||
logger.log(platform .. ' credentials cleared', vim.log.levels.INFO, true)
|
end
|
||||||
else
|
|
||||||
logger.log('all credentials cleared', vim.log.levels.INFO, true)
|
function M.clear()
|
||||||
end
|
cache.load()
|
||||||
|
cache.clear_credentials(nil)
|
||||||
|
logger.log('all credentials cleared', vim.log.levels.INFO, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ end, {
|
||||||
end
|
end
|
||||||
return filter_candidates(candidates)
|
return filter_candidates(candidates)
|
||||||
elseif args[2] == 'credentials' then
|
elseif args[2] == 'credentials' then
|
||||||
return filter_candidates({ 'set', 'clear' })
|
return filter_candidates({ 'login', 'logout', 'clear' })
|
||||||
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)
|
||||||
|
|
@ -126,7 +126,7 @@ end, {
|
||||||
cache.load()
|
cache.load()
|
||||||
local contests = cache.get_cached_contest_ids(args[3])
|
local contests = cache.get_cached_contest_ids(args[3])
|
||||||
return filter_candidates(contests)
|
return filter_candidates(contests)
|
||||||
elseif args[2] == 'credentials' and vim.tbl_contains({ 'set', 'clear' }, args[3]) then
|
elseif args[2] == 'credentials' and vim.tbl_contains({ 'login', 'logout' }, args[3]) then
|
||||||
return filter_candidates(platforms)
|
return filter_candidates(platforms)
|
||||||
elseif args[2] == 'cache' and args[3] == 'clear' then
|
elseif args[2] == 'cache' and args[3] == 'clear' then
|
||||||
local candidates = vim.list_extend({}, platforms)
|
local candidates = vim.list_extend({}, platforms)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue