Skip to main content

degenbot_cli_core/
prompt.rs

1//! Interactive policy as declared data (ADR-051 D4).
2//!
3//! Each command carries a [`PromptPlan`]; the plan declares WHEN the operator is
4//! asked, never WHAT is asked (the arm owns the ported message text). Ported
5//! verbatim from the click handlers and audited, never redesigned.
6
7/// Asks the operator a yes/no question.
8pub trait Prompter {
9    /// Ask `message`, returning the answer. `default` is the value a bare Enter
10    /// yields (every ported console prompt defaults to `false`).
11    fn confirm(&self, message: &str, default: bool) -> bool;
12}
13
14/// A command's declared confirmation policy.
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum PromptPlan {
17    /// Never prompt (`compact` / `inspect`).
18    None,
19    /// Prompt unless the arm's `--force` flag is set (`reset` / `upgrade` /
20    /// `cutover` / `heal`).
21    UnlessForce,
22    /// Prompt only when the named runtime condition holds — the backup arm's
23    /// `backup-target-exists` condition.
24    OnCondition(bool),
25}
26
27impl PromptPlan {
28    /// Whether this plan asks, given the arm's `--force` flag.
29    #[must_use]
30    pub const fn asks(self, force: bool) -> bool {
31        match self {
32            Self::None => false,
33            Self::UnlessForce => !force,
34            Self::OnCondition(condition) => condition,
35        }
36    }
37}