@ghostpaw/questlog 0.10.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,95 +0,0 @@
1
- #!/usr/bin/env node
2
- import { parseCliArgs } from './chunk-GVD6A3RR.js';
3
- import { watchQuestlog, testHook, removeHook, hookLabel, listHooks, addHook } from './chunk-N7V7VUI5.js';
4
-
5
- // src/surface/run_hook_command.ts
6
- async function runHookCommand(command, args, io, open) {
7
- let db;
8
- try {
9
- if (args.includes("--help") || args.includes("-h")) {
10
- io.stdout.write(
11
- "questlog hook add <url> [--tag name] [--events types] [--min-gap seconds] [--secret-stdin] [--json]\nquestlog hook list|remove <id>|test <id>|label [name]\nquestlog watch [--interval seconds] [--json]\n"
12
- );
13
- return 0;
14
- }
15
- const action = command === "watch" ? "watch" : args.shift();
16
- if (!["add", "list", "remove", "test", "label", "watch"].includes(action ?? ""))
17
- throw new Error("Expected hook add, list, remove, test, or label");
18
- const values = parseCliArgs(args, {
19
- command,
20
- flags: [
21
- { name: "json", type: "boolean" },
22
- ...action === "add" ? [
23
- { name: "tag", type: "string" },
24
- { name: "events", type: "string" },
25
- { name: "min-gap", type: "integer" },
26
- { name: "secret-stdin", type: "boolean" }
27
- ] : action === "watch" ? [{ name: "interval", type: "number" }] : []
28
- ],
29
- positionals: action === "add" ? [{ name: "url", type: "string", required: true }] : ["remove", "test"].includes(action ?? "") ? [{ name: "id", type: "integer", required: true }] : action === "label" ? [{ name: "name", type: "string" }] : []
30
- });
31
- if (action === "watch" && values.interval !== void 0 && Number(values.interval) < 5)
32
- throw new Error("Interval must be at least 5 seconds");
33
- db = await open();
34
- let result;
35
- switch (action) {
36
- case "add": {
37
- let secret;
38
- if (values.secretStdin) {
39
- secret = "";
40
- for await (const chunk of io.stdin) secret += String(chunk);
41
- secret = secret.replace(/\r?\n$/, "");
42
- }
43
- result = addHook(db, {
44
- url: String(values.url),
45
- ...values.tag === void 0 ? {} : { tag: String(values.tag) },
46
- ...values.events === void 0 ? {} : { events: String(values.events).split(",") },
47
- ...values.minGap === void 0 ? {} : { minGap: Number(values.minGap) },
48
- ...secret === void 0 ? {} : { secret }
49
- });
50
- break;
51
- }
52
- case "list":
53
- result = listHooks(db);
54
- break;
55
- case "label":
56
- result = { label: hookLabel(db, values.name) };
57
- break;
58
- case "remove":
59
- removeHook(db, Number(values.id));
60
- result = { removed: Number(values.id) };
61
- break;
62
- case "test":
63
- result = await testHook(db, Number(values.id));
64
- break;
65
- case "watch": {
66
- const controller = new AbortController();
67
- const stop = () => controller.abort();
68
- process.on("SIGINT", stop);
69
- process.on("SIGTERM", stop);
70
- try {
71
- await watchQuestlog(db, {
72
- signal: controller.signal,
73
- interval: Number(values.interval ?? 60),
74
- onTick: (tick) => io.stdout.write(`${JSON.stringify(tick)}
75
- `)
76
- });
77
- } finally {
78
- process.off("SIGINT", stop);
79
- process.off("SIGTERM", stop);
80
- }
81
- return 0;
82
- }
83
- }
84
- io.stdout.write(`${JSON.stringify(result, null, 2)}
85
- `);
86
- return 0;
87
- } catch {
88
- io.stderr.write("Invalid webhook command or unavailable target. Run questlog hook --help.\n");
89
- return 2;
90
- } finally {
91
- db?.close();
92
- }
93
- }
94
-
95
- export { runHookCommand };