@@ -7,7 +7,7 @@ use cortex_login::{
77 safe_format_key, save_auth_with_fallback,
88} ;
99use std:: collections:: HashSet ;
10- use std:: io:: { IsTerminal , Read } ;
10+ use std:: io:: { BufRead , IsTerminal , Read } ;
1111use std:: path:: PathBuf ;
1212
1313/// Check for duplicate config override keys and warn the user.
@@ -41,6 +41,14 @@ fn get_cortex_home() -> PathBuf {
4141 } )
4242}
4343
44+ /// Read and parse a logout confirmation response.
45+ pub fn read_logout_confirmation < R : BufRead > ( reader : & mut R ) -> std:: io:: Result < bool > {
46+ let mut input = String :: new ( ) ;
47+ reader. read_line ( & mut input) ?;
48+ let input = input. trim ( ) . to_lowercase ( ) ;
49+ Ok ( input == "y" || input == "yes" )
50+ }
51+
4452/// Run login with API key.
4553pub async fn run_login_with_api_key ( config_overrides : CliConfigOverrides , api_key : String ) -> ! {
4654 check_duplicate_config_overrides ( & config_overrides) ;
@@ -205,13 +213,18 @@ pub async fn run_logout(config_overrides: CliConfigOverrides, skip_confirmation:
205213 ) ;
206214 let _ = std:: io:: Write :: flush ( & mut std:: io:: stderr ( ) ) ;
207215
208- let mut input = String :: new ( ) ;
209- if std:: io:: stdin ( ) . read_line ( & mut input) . is_ok ( ) {
210- let input = input. trim ( ) . to_lowercase ( ) ;
211- if input != "y" && input != "yes" {
216+ let stdin = std:: io:: stdin ( ) ;
217+ let mut stdin = stdin. lock ( ) ;
218+ match read_logout_confirmation ( & mut stdin) {
219+ Ok ( true ) => { }
220+ Ok ( false ) => {
212221 print_info ( "Logout cancelled." ) ;
213222 std:: process:: exit ( 0 ) ;
214223 }
224+ Err ( e) => {
225+ print_error ( & format ! ( "Failed to read logout confirmation: {e}" ) ) ;
226+ std:: process:: exit ( 1 ) ;
227+ }
215228 }
216229 }
217230 }
0 commit comments