-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdelete.ts
More file actions
52 lines (46 loc) · 1.59 KB
/
delete.ts
File metadata and controls
52 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Command } from "@cliffy/command";
import VTClient from "~/vt/vt/VTClient.ts";
import { doWithSpinner } from "~/cmd/utils.ts";
import { Confirm } from "@cliffy/prompt";
import { findVtRoot } from "~/vt/vt/utils.ts";
import { colors } from "@cliffy/ansi/colors";
import { getVal } from "~/sdk.ts";
export const deleteCmd = new Command()
.name("delete")
.description("Delete the current Val")
.option("-f, --force", "Skip confirmation prompt")
.example("Delete current val", "vt delete")
.action(async ({ force }: { force?: boolean }) => {
await doWithSpinner("Deleting val...", async (spinner) => {
const vtRoot = await findVtRoot(Deno.cwd());
const vt = VTClient.from(vtRoot);
const meta = vt.getMeta();
const vtState = await meta.loadVtState();
// Get Val name for display
const val = await getVal(vtState.val.id);
const valName = val.name;
// Confirm deletion unless --force is used
if (!force) {
spinner.stop();
const shouldDelete = await Confirm.prompt({
message:
`Are you sure you want to delete Val "${valName}"? This action cannot be undone.`,
default: false,
});
if (!shouldDelete) {
spinner.warn("Deletion cancelled.");
return;
}
}
spinner.start();
await vt.delete();
spinner.succeed(`Val "${valName}" has been deleted.`);
spinner.info(
colors.red(
`You will no longer be able to use ${
colors.bold("vt")
} commands in this directory.`,
),
);
});
});