@@ -3,7 +3,7 @@ import { defineCommand } from "../../../core/define-command.ts";
33import { resolveConfig } from "../../../config/index.ts" ;
44import { createDbClient } from "@bunny.net/api" ;
55import { resolveDbId } from "../resolve-db.ts" ;
6- import { spinner } from "../../../core/ui.ts" ;
6+ import { confirm , spinner } from "../../../core/ui.ts" ;
77import { logger } from "../../../core/logger.ts" ;
88import { UserError } from "../../../core/errors.ts" ;
99import { formatTable } from "../../../core/format.ts" ;
@@ -20,11 +20,13 @@ const DESCRIPTION = "Remove regions from a database.";
2020
2121const ARG_PRIMARY = "primary" ;
2222const ARG_REPLICAS = "replicas" ;
23+ const ARG_FORCE = "force" ;
2324
2425interface RemoveArgs {
2526 [ ARG_DATABASE_ID ] ?: string ;
2627 [ ARG_PRIMARY ] ?: string ;
2728 [ ARG_REPLICAS ] ?: string ;
29+ [ ARG_FORCE ] ?: boolean ;
2830}
2931
3032/**
@@ -43,6 +45,9 @@ interface RemoveArgs {
4345 *
4446 * # Remove replica regions
4547 * bunny db regions remove --replicas UK
48+ *
49+ * # Skip confirmation prompt
50+ * bunny db regions remove --primary FR --force
4651 * ```
4752 */
4853export const dbRegionsRemoveCommand = defineCommand < RemoveArgs > ( {
@@ -52,6 +57,7 @@ export const dbRegionsRemoveCommand = defineCommand<RemoveArgs>({
5257 [ "$0 db regions remove" , "Interactive — select regions to remove" ] ,
5358 [ "$0 db regions remove --primary FR,DE" , "Remove specific primary regions" ] ,
5459 [ "$0 db regions remove --replicas UK" , "Remove replica regions" ] ,
60+ [ "$0 db regions remove --primary FR --force" , "Skip confirmation prompt" ] ,
5561 ] ,
5662 describe : DESCRIPTION ,
5763
@@ -69,12 +75,17 @@ export const dbRegionsRemoveCommand = defineCommand<RemoveArgs>({
6975 . option ( ARG_REPLICAS , {
7076 type : "string" ,
7177 describe : "Comma-separated replica region IDs to remove (e.g. UK)" ,
78+ } )
79+ . option ( ARG_FORCE , {
80+ type : "boolean" ,
81+ describe : "Skip confirmation prompt" ,
7282 } ) ,
7383
7484 handler : async ( {
7585 [ ARG_DATABASE_ID ] : databaseIdArg ,
7686 primary : primaryArg ,
7787 replicas : replicasArg ,
88+ force,
7889 profile,
7990 output,
8091 verbose,
@@ -178,6 +189,29 @@ export const dbRegionsRemoveCommand = defineCommand<RemoveArgs>({
178189 ) ;
179190 }
180191
192+ const parts : string [ ] = [ ] ;
193+ if ( removePrimary . size > 0 ) {
194+ const names = [ ...removePrimary ]
195+ . map ( ( id ) => regionNames . get ( id ) ?? id )
196+ . join ( ", " ) ;
197+ parts . push ( `primary: ${ names } ` ) ;
198+ }
199+ if ( removeReplicas . size > 0 ) {
200+ const names = [ ...removeReplicas ]
201+ . map ( ( id ) => regionNames . get ( id ) ?? id )
202+ . join ( ", " ) ;
203+ parts . push ( `replica: ${ names } ` ) ;
204+ }
205+
206+ const confirmed = await confirm (
207+ `Remove regions from "${ db . name } " (${ parts . join ( "; " ) } )?` ,
208+ { force } ,
209+ ) ;
210+ if ( ! confirmed ) {
211+ logger . info ( "Aborted." ) ;
212+ return ;
213+ }
214+
181215 const updateSpin = spinner ( "Updating regions..." ) ;
182216 updateSpin . start ( ) ;
183217
0 commit comments