thecatapi-cli 0.1.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.
- package/README.md +72 -0
- package/bun.lock +32 -0
- package/dist/index.js +2840 -0
- package/dist/thecatapi-cli.js +2840 -0
- package/package.json +21 -0
- package/skills/thecatapi-cli/SKILL.md +80 -0
- package/src/commands/auth.ts +53 -0
- package/src/index.ts +41 -0
- package/src/lib/auth.ts +54 -0
- package/src/lib/client.ts +107 -0
- package/src/lib/config.ts +29 -0
- package/src/lib/errors.ts +101 -0
- package/src/lib/logger.ts +41 -0
- package/src/lib/output.ts +169 -0
- package/src/resources/breeds.ts +103 -0
- package/src/resources/example.ts +125 -0
- package/src/resources/facts.ts +35 -0
- package/src/resources/favourites.ts +83 -0
- package/src/resources/images.ts +153 -0
- package/src/resources/votes.ts +88 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { client } from "../lib/client.js";
|
|
3
|
+
import { output } from "../lib/output.js";
|
|
4
|
+
import { handleError } from "../lib/errors.js";
|
|
5
|
+
|
|
6
|
+
interface ActionOpts {
|
|
7
|
+
json?: boolean;
|
|
8
|
+
format?: string;
|
|
9
|
+
fields?: string;
|
|
10
|
+
imageId?: string;
|
|
11
|
+
subId?: string;
|
|
12
|
+
value?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const votesResource = new Command("votes")
|
|
16
|
+
.description("Vote on cat images");
|
|
17
|
+
|
|
18
|
+
// ── LIST ───────────────────────────────────────────
|
|
19
|
+
votesResource
|
|
20
|
+
.command("list")
|
|
21
|
+
.description("List your votes")
|
|
22
|
+
.option("--fields <cols>", "Comma-separated columns to display")
|
|
23
|
+
.option("--json", "Output as JSON")
|
|
24
|
+
.option("--format <fmt>", "Output format: text, json, csv, yaml")
|
|
25
|
+
.addHelpText("after", "\nExample:\n thecatapi-cli votes list")
|
|
26
|
+
.action(async (opts: ActionOpts) => {
|
|
27
|
+
try {
|
|
28
|
+
const data = await client.get("/votes");
|
|
29
|
+
const fields = opts.fields?.split(",");
|
|
30
|
+
output(data, { json: opts.json, format: opts.format, fields });
|
|
31
|
+
} catch (err) {
|
|
32
|
+
handleError(err, opts.json);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ── GET ────────────────────────────────────────────
|
|
37
|
+
votesResource
|
|
38
|
+
.command("get")
|
|
39
|
+
.description("Get a specific vote")
|
|
40
|
+
.argument("<id>", "Vote ID")
|
|
41
|
+
.option("--json", "Output as JSON")
|
|
42
|
+
.option("--format <fmt>", "Output format: text, json, csv, yaml")
|
|
43
|
+
.action(async (id: string, opts: ActionOpts) => {
|
|
44
|
+
try {
|
|
45
|
+
const data = await client.get(`/votes/${id}`);
|
|
46
|
+
output(data, { json: opts.json, format: opts.format });
|
|
47
|
+
} catch (err) {
|
|
48
|
+
handleError(err, opts.json);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// ── CREATE ─────────────────────────────────────────
|
|
53
|
+
votesResource
|
|
54
|
+
.command("create")
|
|
55
|
+
.description("Vote on an image (1 = upvote, 0 = downvote)")
|
|
56
|
+
.requiredOption("--image-id <id>", "Image ID to vote on")
|
|
57
|
+
.requiredOption("--value <n>", "Vote value: 1 (up) or 0 (down)")
|
|
58
|
+
.option("--sub-id <id>", "User segment identifier")
|
|
59
|
+
.option("--json", "Output as JSON")
|
|
60
|
+
.addHelpText("after", "\nExample:\n thecatapi-cli votes create --image-id abc123 --value 1")
|
|
61
|
+
.action(async (opts: ActionOpts) => {
|
|
62
|
+
try {
|
|
63
|
+
const body: Record<string, unknown> = {
|
|
64
|
+
image_id: opts.imageId,
|
|
65
|
+
value: Number(opts.value),
|
|
66
|
+
};
|
|
67
|
+
if (opts.subId) body.sub_id = opts.subId;
|
|
68
|
+
const data = await client.post("/votes", body);
|
|
69
|
+
output(data, { json: opts.json });
|
|
70
|
+
} catch (err) {
|
|
71
|
+
handleError(err, opts.json);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ── DELETE ─────────────────────────────────────────
|
|
76
|
+
votesResource
|
|
77
|
+
.command("delete")
|
|
78
|
+
.description("Delete a vote")
|
|
79
|
+
.argument("<id>", "Vote ID")
|
|
80
|
+
.option("--json", "Output as JSON")
|
|
81
|
+
.action(async (id: string, opts: ActionOpts) => {
|
|
82
|
+
try {
|
|
83
|
+
await client.delete(`/votes/${id}`);
|
|
84
|
+
output({ deleted: true, id }, { json: opts.json });
|
|
85
|
+
} catch (err) {
|
|
86
|
+
handleError(err, opts.json);
|
|
87
|
+
}
|
|
88
|
+
});
|