Skip to content

Commit 3cb6769

Browse files
factorydroidFactory Bot
authored andcommitted
fix(cortex-cli): add confirmation prompt to logout command
Fixes bounty issue #1393 The logout command now prompts for confirmation before removing credentials. Users can bypass the prompt using the --yes/-y flag for scripted usage.
1 parent 5579873 commit 3cb6769

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

cortex-cli/src/login.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,28 @@ pub async fn run_login_status(_config_overrides: CliConfigOverrides) -> ! {
9696
}
9797

9898
/// Run logout.
99-
pub async fn run_logout(_config_overrides: CliConfigOverrides) -> ! {
99+
pub async fn run_logout(_config_overrides: CliConfigOverrides, skip_confirmation: bool) -> ! {
100100
let Some(cortex_home) = get_cortex_home() else {
101101
eprintln!("Error: Could not determine home directory");
102102
std::process::exit(1);
103103
};
104104

105+
// Prompt for confirmation unless --yes flag is provided
106+
if !skip_confirmation {
107+
eprintln!(
108+
"Are you sure you want to log out? This will remove your stored credentials. [y/N]"
109+
);
110+
let mut input = String::new();
111+
if std::io::stdin().read_line(&mut input).is_err() {
112+
eprintln!("Error reading input");
113+
std::process::exit(1);
114+
}
115+
if !input.trim().eq_ignore_ascii_case("y") && !input.trim().eq_ignore_ascii_case("yes") {
116+
eprintln!("Logout cancelled.");
117+
std::process::exit(0);
118+
}
119+
}
120+
105121
match logout(&cortex_home, CredentialsStoreMode::default()) {
106122
Ok(true) => {
107123
eprintln!("Successfully logged out");

cortex-cli/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ enum LoginSubcommand {
269269
struct LogoutCommand {
270270
#[clap(skip)]
271271
config_overrides: CliConfigOverrides,
272+
273+
/// Skip confirmation prompt
274+
#[arg(long, short = 'y')]
275+
yes: bool,
272276
}
273277

274278
/// Completion command.
@@ -453,7 +457,7 @@ async fn main() -> Result<()> {
453457
Ok(())
454458
}
455459
Some(Commands::Logout(logout_cli)) => {
456-
run_logout(logout_cli.config_overrides).await;
460+
run_logout(logout_cli.config_overrides, logout_cli.yes).await;
457461
Ok(())
458462
}
459463
Some(Commands::Mcp(mcp_cli)) => mcp_cli.run().await,

0 commit comments

Comments
 (0)