Skip to content

Commit 3810341

Browse files
author
Jake King
committed
refactor(minimal): parameterize confirmation default
1 parent ae0bfa8 commit 3810341

1 file changed

Lines changed: 12 additions & 23 deletions

File tree

crates/minimal/src/lib.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -592,33 +592,22 @@ fn ensure_daemon(global: &GlobalArgs) -> Result<(), anyhow::Error> {
592592
.context("Failed to ensure the minimald daemon is running")
593593
}
594594

595-
/// Prompt the user with a yes/no question on stderr. Defaults to yes
596-
/// (empty input or Y/y/yes returns true; anything else returns false).
597-
fn confirm(question: &str) -> Result<bool, anyhow::Error> {
598-
eprint!("{question} [Y/n] ");
595+
/// Prompt the user with a yes/no question on stderr.
596+
fn confirm(question: &str, default: bool) -> Result<bool, anyhow::Error> {
597+
let prompt = if default { "[Y/n]" } else { "[y/N]" };
598+
eprint!("{question} {prompt} ");
599599
std::io::stderr().flush().ok();
600600

601601
let mut input = String::new();
602602
std::io::stdin()
603603
.read_line(&mut input)
604604
.context("reading stdin")?;
605605
let trimmed = input.trim();
606-
Ok(trimmed.is_empty()
607-
|| trimmed.eq_ignore_ascii_case("y")
608-
|| trimmed.eq_ignore_ascii_case("yes"))
609-
}
610-
611-
/// Prompt for confirmation, defaulting to no.
612-
fn confirm_default_no(question: &str) -> Result<bool, anyhow::Error> {
613-
eprint!("{question} [y/N] ");
614-
std::io::stderr().flush().ok();
615-
616-
let mut input = String::new();
617-
std::io::stdin()
618-
.read_line(&mut input)
619-
.context("reading stdin")?;
620-
let trimmed = input.trim();
621-
Ok(trimmed.eq_ignore_ascii_case("y") || trimmed.eq_ignore_ascii_case("yes"))
606+
Ok(if trimmed.is_empty() {
607+
default
608+
} else {
609+
trimmed.eq_ignore_ascii_case("y") || trimmed.eq_ignore_ascii_case("yes")
610+
})
622611
}
623612

624613
/// List sessions via the `ListSessions` RPC.
@@ -879,7 +868,7 @@ fn offer_mfile_scaffold(
879868
// "yes" — and, when a config is discovered under `.minimal/`, the init
880869
// writer would clobber it. Only prompt on a real terminal; anywhere else
881870
// (and on a declined prompt) carry on without scaffolding.
882-
if !std::io::stdin().is_terminal() || !confirm("Would you like to create one?")? {
871+
if !std::io::stdin().is_terminal() || !confirm("Would you like to create one?", true)? {
883872
eprintln!(
884873
"Continuing without one; the session gets a default environment. \
885874
Run 'minimal init' to give the project its own config."
@@ -1321,7 +1310,7 @@ async fn destroy_all_sessions(
13211310
if !std::io::stdin().is_terminal() {
13221311
bail!("refusing to destroy all sessions without confirmation; pass --force")
13231312
}
1324-
if !confirm_default_no(&format!("Destroy all {} sessions?", sessions.len()))? {
1313+
if !confirm(&format!("Destroy all {} sessions?", sessions.len()), false)? {
13251314
println!("Aborted.");
13261315
return Ok(());
13271316
}
@@ -1646,7 +1635,7 @@ fn run_init_flow(config: mctx::Config, skip_confirm: bool) -> Result<(), anyhow:
16461635
eprint!("{}", plan.content);
16471636
eprintln!("---");
16481637
eprintln!();
1649-
if !confirm("Continue?")? {
1638+
if !confirm("Continue?", true)? {
16501639
eprintln!("Aborted.");
16511640
return Ok(());
16521641
}

0 commit comments

Comments
 (0)