Skip to content

CLI - Refactor yes/no prompts into a YesOrNo builder - #6340

Open
bfops wants to merge 17 commits into
masterfrom
bfops/yes-or-no-builder
Open

bfops wants to merge 17 commits into
masterfrom
bfops/yes-or-no-builder

Conversation

@bfops

@bfops bfops commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description of Changes

#6337 wants to add a new bool param to the shared y_or_n function (for the default value). It made the invocations look ugly, and made alllll the call sites change, so factored it into its own PR with a builder pattern that is much more readable imo.

This PR replaces y_or_n with YesOrNo::new(message).force(...).default(...).prompt(). EOF now returns an error instead of using the default; pressing Enter still uses the configured default.

API and ABI breaking changes

This changes how our CLI prompts respond to EOF (it is now an error instead of answering "no")

Rollback safety impact

n/a

Expected complexity level and risk

1

Testing

Existing smoketests have been updated.

Comment thread crates/cli/src/util.rs Outdated
Comment thread crates/cli/src/util.rs
.force(force)
.default(false)
.prompt()?
{

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I changed printing behavior here. Now in non-interactive mode we still print the database tree info and the prompt (followed by "skipping confirmation due to --yes").

That just seems clearer and better to me? Totally fine to revert it though.

Comment thread crates/cli/src/util.rs Outdated
Comment thread crates/cli/src/util.rs
// Note that this includes EOF
return Ok(default);
}
Ok(input == "y" || input == "yes")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is the previous behavior, but since we now have an optional default, I could see an argument for requiring a clear yes or no, and ambiguous input causing a re-prompt.

I'm happy to update that here/now if we think it's worth it.

Signed-off-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Comment thread crates/cli/src/util.rs Outdated
std::io::stdin().read_line(&mut input)?;
let input = input.trim().to_lowercase();
if input.is_empty() {
// Note that this includes EOF

@bfops bfops Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda think that we should fail on EOF, since non-interactive contexts should be using force and not hitting this, but this is the previous behavior.

Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I probably wouldn't return Ok(default) here I would return an Err

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread crates/cli/src/util.rs Outdated
@bfops bfops added the api-break A PR that makes an API breaking change label Oct 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-break A PR that makes an API breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants