Add logout command to CLI and TUI (#1932)
## Summary - support `codex logout` via new subcommand and helper that removes the stored `auth.json` - expose a `logout` function in `codex-login` and test it - add `/logout` slash command in the TUI; command list is filtered when not logged in and the handler deletes `auth.json` then exits ## Testing - `just fix` *(fails: failed to get `diffy` from crates.io)* - `cargo test --all-features` *(fails: failed to get `diffy` from crates.io)* ------ https://chatgpt.com/codex/tasks/task_i_68945c3facac832ca83d48499716fb51
This commit is contained in:
@@ -8,6 +8,7 @@ use codex_login::OPENAI_API_KEY_ENV_VAR;
|
||||
use codex_login::load_auth;
|
||||
use codex_login::login_with_api_key;
|
||||
use codex_login::login_with_chatgpt;
|
||||
use codex_login::logout;
|
||||
|
||||
pub async fn run_login_with_chatgpt(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
let config = load_config_or_exit(cli_config_overrides);
|
||||
@@ -80,6 +81,25 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_logout(cli_config_overrides: CliConfigOverrides) -> ! {
|
||||
let config = load_config_or_exit(cli_config_overrides);
|
||||
|
||||
match logout(&config.codex_home) {
|
||||
Ok(true) => {
|
||||
eprintln!("Successfully logged out");
|
||||
std::process::exit(0);
|
||||
}
|
||||
Ok(false) => {
|
||||
eprintln!("Not logged in");
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error logging out: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_config_or_exit(cli_config_overrides: CliConfigOverrides) -> Config {
|
||||
let cli_overrides = match cli_config_overrides.parse_overrides() {
|
||||
Ok(v) => v,
|
||||
|
||||
Reference in New Issue
Block a user