Skip to content

feat(cli): add y/n confirmation prompt to bs down command#395

Open
shallowtensr wants to merge 2 commits intoone-covenant:mainfrom
shallowtensr:feat/down-confirm
Open

feat(cli): add y/n confirmation prompt to bs down command#395
shallowtensr wants to merge 2 commits intoone-covenant:mainfrom
shallowtensr:feat/down-confirm

Conversation

@shallowtensr
Copy link
Copy Markdown

@shallowtensr shallowtensr commented Mar 27, 2026

Summary

Add y/n confirmation prompt to bs down command to prevent accidental instance termination. Adds --yes/-y flag to skip confirmation for scripting.

Related Issues

User (my) request from Discord — accidental double-enter on interactive selector killed a running instance.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Changes Made

List the main changes in this PR:

  • Added --yes/-y flag to Down command definition
  • Added confirmation prompt before stopping a single rental: Stop rental <id>? [y/N]
  • Added confirmation prompt before --all: Are you sure you want to stop all N active rental(s)? [y/N]
  • Uses spawn_blocking + dialoguer::Confirm with default(false), matching existing patterns in volumes.rs, ssh_keys.rs, and tokens.rs

Testing

How Has This Been Tested?

Describe the tests you ran to verify your changes.

  • Unit tests pass (cargo test)
  • Integration tests pass
  • Manual testing completed

Test Configuration

  • OS: macOS Darwin 25.3.0
  • Rust version: rustc 1.93.1 (Homebrew)

Checklist

  • My code follows the project's style guidelines
  • I have run cargo fmt to format my code
  • I have run cargo clippy and addressed all warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Context

Manual testing proof :

down_all.mov
down_help.mov
down_id_yes.mov
down_with_id.mov
down.mov

Summary by CodeRabbit

  • New Features
    • Added --yes / -y to the terminate instance command to skip confirmation prompts.
    • When stopping all rentals, the CLI now reports if no active rentals exist and exits early.
    • For single or all terminations, interactive confirmation is presented unless --yes is used; cancelling prints "Cancelled." and aborts the operation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0ea024e3-9aa1-4666-87de-66d9f0abd3f4

📥 Commits

Reviewing files that changed from the base of the PR and between b9438d7 and e451ea7.

📒 Files selected for processing (1)
  • crates/basilica-cli/src/cli/handlers/gpu_rental.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/basilica-cli/src/cli/handlers/gpu_rental.rs

Walkthrough

Added a --yes / -y flag to the down command, threaded it through argument dispatch, and updated handle_down to accept skip_confirm: bool and conditionally prompt (or skip) confirmation before terminating rentals.

Changes

Cohort / File(s) Summary
Command Definition
crates/basilica-cli/src/cli/commands.rs
Added yes: bool field to Commands::Down with --yes / -y flags.
Argument Dispatch
crates/basilica-cli/src/cli/args.rs
Extracts the new yes flag in Commands::Down pattern and forwards it to handlers::gpu_rental::handle_down(...).
Handler Implementation
crates/basilica-cli/src/cli/handlers/gpu_rental.rs
Extended handle_down(...) signature to include skip_confirm: bool; added blocking dialoguer::Confirm prompts (via spawn_blocking) for --all and single-rental flows, early exit when no active rentals, and error mapping for prompt failures.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as "basilica-cli\nArgs -> Handler"
    participant Prompt as "dialoguer::Confirm\n(spawn_blocking)"
    participant API as "GPU Rental API"

    User->>CLI: run `down [--all] [--yes]` / `down <id> [--yes]`
    alt skip_confirm == false
        CLI->>Prompt: spawn_blocking(Confirm)
        Prompt->>User: "Stop all X rentals?" / "Stop rental {id}?"
        User-->>Prompt: confirm / deny
        Prompt->>CLI: bool
        alt confirmed
            CLI->>API: call stop_rental(s)...
            API-->>CLI: success/fail
        else denied
            CLI->>User: "Cancelled."
        end
    else skip_confirm == true
        CLI->>API: call stop_rental(s) without prompting
        API-->>CLI: success/fail
    end
    CLI->>User: completion status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • epappas

Poem

🐇 I hopped through flags with a cheerful "yes",
No prompts to linger, no second guess.
Rentals fall silent with a single skip—
A quick little hop, a tidy little trip. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a y/n confirmation prompt to the 'bs down' command, which aligns with the primary objective of reducing accidental instance termination.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/basilica-cli/src/cli/handlers/gpu_rental.rs (1)

2069-2089: Consider extracting duplicated confirmation flow into one helper.

Both branches repeat the same spawn_blocking + Confirm + error mapping logic. A shared helper would reduce drift risk.

Refactor sketch
+async fn confirm_down_action(prompt: String) -> Result<bool, CliError> {
+    tokio::task::spawn_blocking(move || {
+        let theme = dialoguer::theme::ColorfulTheme::default();
+        Confirm::with_theme(&theme)
+            .with_prompt(prompt)
+            .default(false)
+            .interact()
+    })
+    .await
+    .map_err(|e| CliError::Internal(eyre!("Task join error: {}", e)))?
+    .map_err(|e| CliError::Internal(e.into()))
+}
...
-            let confirmed = tokio::task::spawn_blocking(move || { ... }).await ... ?;
+            let confirmed = confirm_down_action(format!(
+                "Are you sure you want to stop all {} active rental{}?",
+                all_count,
+                if all_count == 1 { "" } else { "s" }
+            ))
+            .await?;
...
-            let confirmed = tokio::task::spawn_blocking(move || { ... }).await ... ?;
+            let confirmed = confirm_down_action(format!("Stop rental {}?", confirm_id)).await?;

Also applies to: 2217-2234

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/basilica-cli/src/cli/handlers/gpu_rental.rs` around lines 2069 - 2089,
Extract the repeated confirmation logic (tokio::task::spawn_blocking +
dialoguer::Confirm::with_theme + the current error mapping to
CliError::Internal) into a single async helper function (e.g., async fn
prompt_confirm(prompt: impl Into<String>) -> Result<bool, CliError>) and replace
both occurrences (the block using skip_confirm and the similar block at
2217-2234) to call this helper; ensure the helper encapsulates creating
ColorfulTheme, building the prompt string, running interact() inside
spawn_blocking, and mapping both spawn join errors and interact errors into
CliError::Internal so callers only need to check the returned bool.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/basilica-cli/src/cli/handlers/gpu_rental.rs`:
- Around line 2069-2089: Extract the repeated confirmation logic
(tokio::task::spawn_blocking + dialoguer::Confirm::with_theme + the current
error mapping to CliError::Internal) into a single async helper function (e.g.,
async fn prompt_confirm(prompt: impl Into<String>) -> Result<bool, CliError>)
and replace both occurrences (the block using skip_confirm and the similar block
at 2217-2234) to call this helper; ensure the helper encapsulates creating
ColorfulTheme, building the prompt string, running interact() inside
spawn_blocking, and mapping both spawn join errors and interact errors into
CliError::Internal so callers only need to check the returned bool.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 96244adb-6aee-414c-aacb-6660fc433d58

📥 Commits

Reviewing files that changed from the base of the PR and between 659e9e1 and b9438d7.

📒 Files selected for processing (3)
  • crates/basilica-cli/src/cli/args.rs
  • crates/basilica-cli/src/cli/commands.rs
  • crates/basilica-cli/src/cli/handlers/gpu_rental.rs

Copy link
Copy Markdown
Contributor

@itzlambda itzlambda left a comment

Choose a reason for hiding this comment

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

thanks for the contribution! just one nitpick that i noticed, not a blocker.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants