-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Expand file tree
/
Copy pathregister.snapshot.ts
More file actions
73 lines (68 loc) · 2.87 KB
/
Copy pathregister.snapshot.ts
File metadata and controls
73 lines (68 loc) · 2.87 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Snapshot command registration for SQLite-safe snapshot artifacts.
import type { Command } from "commander";
import {
snapshotCreateCommand,
snapshotListCommand,
snapshotRestoreCommand,
snapshotVerifyCommand,
type SnapshotCreateOptions,
type SnapshotJsonOptions,
type SnapshotRepositoryOptions,
type SnapshotRestoreOptions,
} from "../../commands/snapshot.js";
import { defaultRuntime } from "../../runtime.js";
import { runCommandWithRuntime } from "../cli-utils.js";
/** Register snapshot create/list/verify/restore subcommands. */
export function registerSnapshotCommand(program: Command): void {
const snapshot = program
.command("snapshot")
.description("Create, verify, list, and restore SQLite snapshots")
.action(() => {
snapshot.outputHelp();
process.exitCode = 1;
});
snapshot
.command("create")
.description("Create a consistent SQLite snapshot in a local repository")
.requiredOption("--db <path>", "SQLite database path")
.requiredOption("--repository <path>", "Snapshot repository directory")
.option("--id <id>", "Logical database id recorded in the manifest")
.option("--kind <kind>", "Logical database kind recorded in the manifest")
.option("--json", "Emit JSON output")
.action(async (options: SnapshotCreateOptions) => {
await runCommandWithRuntime(defaultRuntime, async () => {
process.exitCode = await snapshotCreateCommand(options, defaultRuntime);
});
});
snapshot
.command("verify")
.description("Verify a snapshot manifest, artifact hash, and SQLite integrity")
.argument("<snapshot>", "Snapshot directory")
.option("--json", "Emit JSON output")
.action(async (snapshotPath: string, options: SnapshotJsonOptions) => {
await runCommandWithRuntime(defaultRuntime, async () => {
process.exitCode = await snapshotVerifyCommand(snapshotPath, options, defaultRuntime);
});
});
snapshot
.command("restore")
.description("Restore a verified snapshot to a new SQLite database path")
.argument("<snapshot>", "Snapshot directory")
.requiredOption("--target <path>", "Target SQLite database path; must not already exist")
.option("--json", "Emit JSON output")
.action(async (snapshotPath: string, options: SnapshotRestoreOptions) => {
await runCommandWithRuntime(defaultRuntime, async () => {
process.exitCode = await snapshotRestoreCommand(snapshotPath, options, defaultRuntime);
});
});
snapshot
.command("list")
.description("List snapshots in a local repository")
.requiredOption("--repository <path>", "Snapshot repository directory")
.option("--json", "Emit JSON output")
.action(async (options: SnapshotRepositoryOptions) => {
await runCommandWithRuntime(defaultRuntime, async () => {
process.exitCode = await snapshotListCommand(options, defaultRuntime);
});
});
}