diff options
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/cli/commands/bookmarks.ts | 23 | ||||
| -rw-r--r-- | apps/cli/commands/lists.ts | 74 | ||||
| -rw-r--r-- | apps/cli/commands/tags.ts | 40 | ||||
| -rw-r--r-- | apps/cli/index.ts | 4 | ||||
| -rw-r--r-- | apps/cli/package.json | 9 |
5 files changed, 146 insertions, 4 deletions
diff --git a/apps/cli/commands/bookmarks.ts b/apps/cli/commands/bookmarks.ts index 55c87b05..0da3dd71 100644 --- a/apps/cli/commands/bookmarks.ts +++ b/apps/cli/commands/bookmarks.ts @@ -86,6 +86,27 @@ bookmarkCmd }); bookmarkCmd + .command("update") + .description("Archive a bookmark") + .option("--title <title>", "If set, the bookmark's title will be updated") + .option("--note <note>", "If set, the bookmark's note will be updated") + .option("--archive", "If set, the bookmark will be archived") + .option("--no-archive", "If set, the bookmark will be unarchived") + .option("--favourite", "If set, the bookmark will be favourited") + .option("--no-favourite", "If set, the bookmark will be unfavourited") + .argument("<id>", "The id of the bookmark to get") + .action(async (id, opts) => { + const api = getAPIClient(); + const resp = await api.bookmarks.updateBookmark.mutate({ + bookmarkId: id, + archived: opts.archive, + favourited: opts.favourite, + title: opts.title, + }); + console.log(resp); + }); + +bookmarkCmd .command("list") .description("list all bookmarks") .option( @@ -93,10 +114,12 @@ bookmarkCmd "If set, archived bookmarks will be fetched as well", false, ) + .option("--list-id <id>", "If set, only items from that list will be fetched") .action(async (opts) => { const api = getAPIClient(); const resp = await api.bookmarks.getBookmarks.query({ archived: opts.includeArchived ? undefined : false, + listId: opts.listId, }); console.log(resp.bookmarks.map(normalizeBookmark)); }); diff --git a/apps/cli/commands/lists.ts b/apps/cli/commands/lists.ts new file mode 100644 index 00000000..099b7869 --- /dev/null +++ b/apps/cli/commands/lists.ts @@ -0,0 +1,74 @@ +import { Command } from "@commander-js/extra-typings"; +import { getAPIClient } from "lib/trpc"; +import { getBorderCharacters, table } from "table"; + +import { listsToTree } from "@hoarder/shared/utils/listUtils"; + +export const listsCmd = new Command() + .name("lists") + .description("Manipulating lists"); + +listsCmd + .command("list") + .description("Lists all lists") + .action(async () => { + const api = getAPIClient(); + + const resp = await api.lists.list.query(); + const { allPaths } = listsToTree(resp.lists); + + const data: string[][] = [["Id", "Name"]]; + + allPaths.forEach((path) => { + const name = path.map((p) => `${p.icon} ${p.name}`).join(" / "); + const id = path[path.length - 1].id; + data.push([id, name]); + }); + console.log( + table(data, { border: getBorderCharacters("ramac"), singleLine: true }), + ); + }); + +listsCmd + .command("delete") + .description("Deletes a list") + .argument("<id>", "The id of the list") + .action(async (id) => { + const api = getAPIClient(); + + await api.lists.delete.mutate({ + listId: id, + }); + console.log("Successfully deleted list with id:", id); + }); + +listsCmd + .command("add-bookmark") + .description("Add a bookmark to list") + .requiredOption("--list <id>", "The id of the list") + .requiredOption("--bookmark <bookmark>", "The id of the bookmark") + .action(async (opts) => { + const api = getAPIClient(); + + await api.lists.addToList.mutate({ + listId: opts.list, + bookmarkId: opts.bookmark, + }); + console.log("Successfully added bookmark from list"); + }); + +listsCmd + .command("remove-bookmark") + .description("Remove a bookmark from list") + .requiredOption("--list <id>", "The id of the list") + .requiredOption("--bookmark <bookmark>", "The id of the bookmark") + .action(async (opts) => { + const api = getAPIClient(); + + await api.lists.removeFromList.mutate({ + listId: opts.list, + bookmarkId: opts.bookmark, + }); + + console.log("Successfully removed bookmark from list"); + }); diff --git a/apps/cli/commands/tags.ts b/apps/cli/commands/tags.ts new file mode 100644 index 00000000..f9df83cd --- /dev/null +++ b/apps/cli/commands/tags.ts @@ -0,0 +1,40 @@ +import { Command } from "@commander-js/extra-typings"; +import { getAPIClient } from "lib/trpc"; +import { getBorderCharacters, table } from "table"; + +export const tagsCmd = new Command() + .name("tags") + .description("Manipulating tags"); + +tagsCmd + .command("list") + .description("Lists all tags") + .action(async () => { + const api = getAPIClient(); + + const tags = (await api.tags.list.query()).tags; + tags.sort((a, b) => b.count - a.count); + + const data: string[][] = [["Id", "Name", "Num bookmarks"]]; + + tags.forEach((tag) => { + data.push([tag.id, tag.name, tag.count.toString()]); + }); + console.log( + table(data, { border: getBorderCharacters("ramac"), singleLine: true }), + ); + }); + +tagsCmd + .command("delete") + .description("Delete a tag") + .argument("<id>", "The id of the tag") + .action(async (id) => { + const api = getAPIClient(); + + await api.tags.delete.mutate({ + tagId: id, + }); + + console.log("Successfully delete the tag with id:", id); + }); diff --git a/apps/cli/index.ts b/apps/cli/index.ts index 4d0adafb..5971b811 100644 --- a/apps/cli/index.ts +++ b/apps/cli/index.ts @@ -1,5 +1,7 @@ import { Command, Option } from "@commander-js/extra-typings"; import { bookmarkCmd } from "commands/bookmarks"; +import { listsCmd } from "commands/lists"; +import { tagsCmd } from "commands/tags"; import { whoamiCmd } from "commands/whoami"; import { setGlobalOptions } from "lib/globals"; @@ -22,6 +24,8 @@ const program = new Command() .version(process.env.SERVER_VERSION ?? "nightly"); program.addCommand(bookmarkCmd); +program.addCommand(listsCmd); +program.addCommand(tagsCmd); program.addCommand(whoamiCmd); setGlobalOptions(program.opts()); diff --git a/apps/cli/package.json b/apps/cli/package.json index 05ab0d0f..87c02c3d 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -5,16 +5,17 @@ "private": true, "dependencies": { "@commander-js/extra-typings": "^12.0.1", - "@hoarder/trpc": "workspace:^0.1.0", "@hoarder/shared": "workspace:^0.1.0", + "@hoarder/trpc": "workspace:^0.1.0", "@hoarder/tsconfig": "workspace:^0.1.0", - "@tsconfig/node21": "^21.0.1", - "tsx": "^4.7.1", "@trpc/client": "11.0.0-next-beta.308", "@trpc/server": "11.0.0-next-beta.308", + "@tsconfig/node21": "^21.0.1", "chalk": "^5.3.0", "commander": "^12.0.0", - "superjson": "^2.2.1" + "superjson": "^2.2.1", + "table": "^6.8.2", + "tsx": "^4.7.1" }, "devDependencies": { "@hoarder/eslint-config": "workspace:^0.2.0", |
