Skip to content

Commit e1b2fc2

Browse files
factorydroidechobt
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 403f708 commit e1b2fc2

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
@@ -277,6 +277,10 @@ enum LoginSubcommand {
277277
struct LogoutCommand {
278278
#[clap(skip)]
279279
config_overrides: CliConfigOverrides,
280+
281+
/// Skip confirmation prompt
282+
#[arg(long, short = 'y')]
283+
yes: bool,
280284
}
281285

282286
/// Completion command.
@@ -473,7 +477,7 @@ async fn main() -> Result<()> {
473477
Ok(())
474478
}
475479
Some(Commands::Logout(logout_cli)) => {
476-
run_logout(logout_cli.config_overrides).await;
480+
run_logout(logout_cli.config_overrides, logout_cli.yes).await;
477481
Ok(())
478482
}
479483
Some(Commands::Mcp(mcp_cli)) => mcp_cli.run().await,

0 commit comments

Comments
 (0)