@shiori-sh/cli 0.2.3 → 0.3.0

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.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/dist/index.js +177 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,6 +51,13 @@ shiori delete <id> # Move to trash
51
51
  shiori trash # List trashed links
52
52
  shiori trash --empty # Permanently delete all trash
53
53
 
54
+ shiori subscriptions list # List RSS subscriptions
55
+ shiori subscriptions add <url> # Subscribe to an RSS feed
56
+ shiori subscriptions add <url> --sync # Subscribe and sync recent items
57
+ shiori subscriptions remove <id> # Remove a subscription
58
+ shiori subscriptions sync <id> # Sync a subscription now
59
+ shiori subscriptions sync <id> --limit 5 # Sync with item limit
60
+
54
61
  shiori me # Show account info
55
62
  shiori auth --status # Check auth status
56
63
  shiori auth --logout # Remove stored credentials
package/dist/index.js CHANGED
@@ -196,9 +196,16 @@ function hasFlag(args, ...names) {
196
196
  function getPositional(args) {
197
197
  for (let i = 0; i < args.length; i++) {
198
198
  if (args[i].startsWith("--")) {
199
- if (i + 1 < args.length && !args[i + 1].startsWith("--") && ["--limit", "--offset", "--sort", "--read", "--title", "--summary", "--since"].includes(
200
- args[i]
201
- )) {
199
+ if (i + 1 < args.length && !args[i + 1].startsWith("--") && [
200
+ "--limit",
201
+ "--offset",
202
+ "--sort",
203
+ "--read",
204
+ "--title",
205
+ "--summary",
206
+ "--since",
207
+ "--format"
208
+ ].includes(args[i])) {
202
209
  i++;
203
210
  }
204
211
  continue;
@@ -492,8 +499,167 @@ Results: ${data.links.length} of ${data.total} matches
492
499
  console.log();
493
500
  }
494
501
 
495
- // src/commands/trash.ts
502
+ // src/commands/subscriptions.ts
503
+ var HELP = `shiori subscriptions - Manage RSS subscriptions
504
+
505
+ Usage: shiori subscriptions <subcommand> [options]
506
+
507
+ Subcommands:
508
+ list List your subscriptions
509
+ add <url> Subscribe to an RSS feed
510
+ remove <id> Remove a subscription
511
+ sync <id> Sync a subscription now
512
+
513
+ Options:
514
+ --json Output raw JSON
515
+ --help, -h Show this help
516
+
517
+ Examples:
518
+ shiori subscriptions list
519
+ shiori subscriptions add https://example.com/feed.xml
520
+ shiori subscriptions add https://example.com --sync
521
+ shiori subscriptions remove <id>
522
+ shiori subscriptions sync <id> --limit 5`;
496
523
  async function run9(args) {
524
+ if (hasFlag(args, "--help", "-h") && !args[0]) {
525
+ console.log(HELP);
526
+ return;
527
+ }
528
+ const subcommand = args[0];
529
+ const subArgs = args.slice(1);
530
+ switch (subcommand) {
531
+ case "list":
532
+ case "ls":
533
+ return listSubscriptions(subArgs);
534
+ case "add":
535
+ return addSubscription(subArgs);
536
+ case "remove":
537
+ case "rm":
538
+ return removeSubscription(subArgs);
539
+ case "sync":
540
+ return syncSubscription(subArgs);
541
+ default:
542
+ if (subcommand) {
543
+ console.error(`Unknown subcommand: ${subcommand}
544
+ `);
545
+ }
546
+ console.log(HELP);
547
+ if (subcommand) process.exit(1);
548
+ }
549
+ }
550
+ async function listSubscriptions(args) {
551
+ if (hasFlag(args, "--help", "-h")) {
552
+ console.log(`shiori subscriptions list - List your RSS subscriptions
553
+
554
+ Usage: shiori subscriptions list [options]
555
+
556
+ Options:
557
+ --json Output raw JSON
558
+ --help, -h Show this help`);
559
+ return;
560
+ }
561
+ const { data } = await api("GET", "/api/subscriptions/");
562
+ if (hasFlag(args, "--json")) {
563
+ console.log(JSON.stringify(data, null, 2));
564
+ return;
565
+ }
566
+ const subs = data.subscriptions;
567
+ if (subs.length === 0) {
568
+ console.log("\n No subscriptions. Add one with: shiori subscriptions add <url>\n");
569
+ return;
570
+ }
571
+ console.log(`
572
+ Subscriptions: ${subs.length}
573
+ `);
574
+ for (const sub of subs) {
575
+ const title = truncate(sub.title || sub.feed_url, 50);
576
+ const synced = sub.last_synced_at ? `synced ${formatDate(sub.last_synced_at)}` : "never synced";
577
+ console.log(` ${sub.id} ${title} ${synced}`);
578
+ }
579
+ console.log();
580
+ }
581
+ async function addSubscription(args) {
582
+ if (hasFlag(args, "--help", "-h")) {
583
+ console.log(`shiori subscriptions add - Subscribe to an RSS feed
584
+
585
+ Usage: shiori subscriptions add <url> [options]
586
+
587
+ Options:
588
+ --sync Sync the 3 most recent items immediately
589
+ --json Output raw JSON
590
+ --help, -h Show this help`);
591
+ return;
592
+ }
593
+ const url = getPositional(args);
594
+ if (!url) {
595
+ console.error("Usage: shiori subscriptions add <url>");
596
+ process.exit(1);
597
+ }
598
+ const body = { feedUrl: url };
599
+ if (hasFlag(args, "--sync")) {
600
+ body.initialSync = true;
601
+ }
602
+ const { data } = await api("POST", "/api/subscriptions/", body);
603
+ if (hasFlag(args, "--json")) {
604
+ console.log(JSON.stringify(data, null, 2));
605
+ return;
606
+ }
607
+ const sub = data.subscription;
608
+ console.log(`Subscribed: ${sub.title || sub.feed_url} (${sub.id})`);
609
+ }
610
+ async function removeSubscription(args) {
611
+ if (hasFlag(args, "--help", "-h")) {
612
+ console.log(`shiori subscriptions remove - Remove a subscription
613
+
614
+ Usage: shiori subscriptions remove <id> [options]
615
+
616
+ Options:
617
+ --json Output raw JSON
618
+ --help, -h Show this help`);
619
+ return;
620
+ }
621
+ const id = getPositional(args);
622
+ if (!id) {
623
+ console.error("Usage: shiori subscriptions remove <id>");
624
+ process.exit(1);
625
+ }
626
+ const { data } = await api("DELETE", `/api/subscriptions/${id}`);
627
+ if (hasFlag(args, "--json")) {
628
+ console.log(JSON.stringify(data, null, 2));
629
+ return;
630
+ }
631
+ console.log("Subscription removed.");
632
+ }
633
+ async function syncSubscription(args) {
634
+ if (hasFlag(args, "--help", "-h")) {
635
+ console.log(`shiori subscriptions sync - Sync a subscription now
636
+
637
+ Usage: shiori subscriptions sync <id> [options]
638
+
639
+ Options:
640
+ --limit <n> Max items to sync (1-100)
641
+ --json Output raw JSON
642
+ --help, -h Show this help`);
643
+ return;
644
+ }
645
+ const id = getPositional(args);
646
+ if (!id) {
647
+ console.error("Usage: shiori subscriptions sync <id>");
648
+ process.exit(1);
649
+ }
650
+ const body = {};
651
+ const limit = getFlag(args, "--limit");
652
+ if (limit) body.limit = Number(limit);
653
+ const { data } = await api("POST", `/api/subscriptions/sync/${id}`, body);
654
+ if (hasFlag(args, "--json")) {
655
+ console.log(JSON.stringify(data, null, 2));
656
+ return;
657
+ }
658
+ console.log(`Synced: ${data.newItems} new, ${data.skipped} skipped, ${data.errors} errors`);
659
+ }
660
+
661
+ // src/commands/trash.ts
662
+ async function run10(args) {
497
663
  if (hasFlag(args, "--help", "-h")) {
498
664
  console.log(`shiori trash - List or empty the trash
499
665
 
@@ -544,7 +710,7 @@ Trashed links: ${data.links.length} of ${data.total} total
544
710
  }
545
711
 
546
712
  // src/commands/update.ts
547
- async function run10(args) {
713
+ async function run11(args) {
548
714
  if (hasFlag(args, "--help", "-h")) {
549
715
  console.log(`shiori update - Update a link
550
716
 
@@ -602,7 +768,7 @@ function reportError(command, error) {
602
768
  method: "POST",
603
769
  headers: { "Content-Type": "application/json" },
604
770
  body: JSON.stringify({
605
- version: "0.2.3",
771
+ version: "0.3.0",
606
772
  command,
607
773
  error: message,
608
774
  platform: process.platform
@@ -648,9 +814,10 @@ var COMMANDS = {
648
814
  get: { run: run4, desc: "Get a link by ID (includes content)" },
649
815
  content: { run: run2, desc: "Print link content as markdown" },
650
816
  save: { run: run7, desc: "Save a new link" },
651
- update: { run: run10, desc: "Update a link" },
817
+ update: { run: run11, desc: "Update a link" },
652
818
  delete: { run: run3, desc: "Delete a link (move to trash)" },
653
- trash: { run: run9, desc: "List or empty the trash" },
819
+ trash: { run: run10, desc: "List or empty the trash" },
820
+ subscriptions: { run: run9, desc: "Manage RSS subscriptions" },
654
821
  me: { run: run6, desc: "Show current user info" }
655
822
  };
656
823
  function printHelp() {
@@ -680,7 +847,7 @@ async function main() {
680
847
  return;
681
848
  }
682
849
  if (command === "--version" || command === "-v") {
683
- console.log("0.2.3");
850
+ console.log("0.3.0");
684
851
  return;
685
852
  }
686
853
  const cmd = COMMANDS[command];
@@ -693,7 +860,7 @@ async function main() {
693
860
  const cmdArgs = args.slice(1);
694
861
  const isJson = cmdArgs.includes("--json");
695
862
  await cmd.run(cmdArgs);
696
- checkForUpdate("0.2.3", isJson).catch(() => {
863
+ checkForUpdate("0.3.0", isJson).catch(() => {
697
864
  });
698
865
  }
699
866
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiori-sh/cli",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "CLI for managing your Shiori link library",
5
5
  "author": "Brian Lovin",
6
6
  "license": "MIT",