Skip to content

Commit 9cbf8ae

Browse files
Merge pull request #22 from BunnyWay/db-regions-confirm-remove
feat(db/regions): confirm when removing a database region
2 parents 292797f + 689830f commit 9cbf8ae

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

.changeset/lazy-colts-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bunny.net/cli": patch
3+
---
4+
5+
ask for confirmation when removing a database region

packages/cli/src/commands/db/regions/remove.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineCommand } from "../../../core/define-command.ts";
33
import { resolveConfig } from "../../../config/index.ts";
44
import { createDbClient } from "@bunny.net/api";
55
import { resolveDbId } from "../resolve-db.ts";
6-
import { spinner } from "../../../core/ui.ts";
6+
import { confirm, spinner } from "../../../core/ui.ts";
77
import { logger } from "../../../core/logger.ts";
88
import { UserError } from "../../../core/errors.ts";
99
import { formatTable } from "../../../core/format.ts";
@@ -20,11 +20,13 @@ const DESCRIPTION = "Remove regions from a database.";
2020

2121
const ARG_PRIMARY = "primary";
2222
const ARG_REPLICAS = "replicas";
23+
const ARG_FORCE = "force";
2324

2425
interface 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
*/
4853
export 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

Comments
 (0)