byr-pt-cli 0.1.2 → 0.1.4

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 CHANGED
@@ -6,7 +6,7 @@ CLI for `byr.pt` with stable machine-readable output (`--json`) and script-frien
6
6
 
7
7
  ```bash
8
8
  npm i -g byr-pt-cli
9
- byr --help
9
+ byr help
10
10
  ```
11
11
 
12
12
  ## Quick start
@@ -27,6 +27,10 @@ byr download --id 1001 --output ./1001.torrent --dry-run
27
27
  ## Commands
28
28
 
29
29
  ```bash
30
+ byr --help
31
+ byr --version
32
+ byr check --json
33
+ byr whoami --json
30
34
  byr search --query "ubuntu" --limit 5 --category movie --spstate free
31
35
  byr search --imdb tt0133093 --json
32
36
  byr get --id 1001
@@ -1,9 +1,10 @@
1
1
  import { renderDownloadOutput, runDownloadCommand } from "./commands/download.mjs";
2
2
  import { renderGetOutput, runGetCommand } from "./commands/get.mjs";
3
3
  import { renderSearchOutput, runSearchCommand } from "./commands/search.mjs";
4
- import { a as BYR_INCLDEAD_FACET, c as parseCategoryAliases, i as BYR_BOOKMARKED_FACET, l as parseSimpleFacetAliases, o as BYR_SPSTATE_FACET, s as getByrMetadata, t as createByrClient } from "./client-DT9oDCaE.mjs";
4
+ import { a as BYR_INCLDEAD_FACET, c as parseCategoryAliases, i as BYR_BOOKMARKED_FACET, l as parseSimpleFacetAliases, o as BYR_SPSTATE_FACET, s as getByrMetadata, t as createByrClient } from "./client-CXGKExl2.mjs";
5
+ import { createRequire } from "node:module";
5
6
  import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
6
- import { CliAppError, EXIT_CODES, createCommandContext, createErrorEnvelope, createSuccessEnvelope, mapErrorCodeToExitCode, toCliAppError } from "@onemoreproduct/cli-core";
7
+ import { CliAppError, EXIT_CODES, createCommandContext, createErrorEnvelope, createSuccessEnvelope, mapErrorCodeToExitCode, toCliAppError } from "clawkit-cli-core";
7
8
  import { copyFileSync, existsSync, readFileSync, rmSync, statSync } from "node:fs";
8
9
  import { homedir, tmpdir } from "node:os";
9
10
  import { dirname, join } from "node:path";
@@ -453,6 +454,12 @@ async function resolveClientConfig(input) {
453
454
 
454
455
  //#endregion
455
456
  //#region src/cli.ts
457
+ const SHORT_FLAG_ALIASES = {
458
+ "-h": "help",
459
+ "-V": "version",
460
+ "-v": "verbose"
461
+ };
462
+ const CLI_VERSION = loadVersionInfo();
456
463
  async function runCli(argv, deps = {}) {
457
464
  const stdout = deps.stdout ?? process.stdout;
458
465
  const stderr = deps.stderr ?? process.stderr;
@@ -465,8 +472,20 @@ async function runCli(argv, deps = {}) {
465
472
  requestIdFactory: deps.requestIdFactory,
466
473
  verbose
467
474
  });
468
- if (parsed.command === void 0 || parsed.command === "help") {
469
- stdout.write(`${renderHelp()}\n`);
475
+ if (hasFlag(parsed.flags, "version") || parsed.command === "version") {
476
+ if (json) stdout.write(`${JSON.stringify(createSuccessEnvelope(CLI_VERSION, context.toMeta()))}\n`);
477
+ else stdout.write(`${CLI_VERSION.name} ${CLI_VERSION.version}\n`);
478
+ return EXIT_CODES.SUCCESS;
479
+ }
480
+ if (parsed.command === void 0 || parsed.command === "help" || hasFlag(parsed.flags, "help")) {
481
+ const helpTarget = resolveHelpTarget(parsed);
482
+ const helpText = renderHelp(helpTarget.command, helpTarget.subcommand);
483
+ if (json) {
484
+ const helpData = { help: helpText };
485
+ if (helpTarget.command) helpData.command = helpTarget.command;
486
+ if (helpTarget.subcommand) helpData.subcommand = helpTarget.subcommand;
487
+ stdout.write(`${JSON.stringify(createSuccessEnvelope(helpData, context.toMeta()))}\n`);
488
+ } else stdout.write(`${helpText}\n`);
470
489
  return EXIT_CODES.SUCCESS;
471
490
  }
472
491
  let resolvedClient;
@@ -505,6 +524,8 @@ async function runCli(argv, deps = {}) {
505
524
  }
506
525
  async function dispatch(parsed, deps) {
507
526
  switch (parsed.command) {
527
+ case "check": return dispatchCheck(parsed, deps);
528
+ case "whoami": return dispatchWhoami(parsed, deps);
508
529
  case "search": return dispatchSearch(parsed, deps);
509
530
  case "get": return dispatchGet(parsed, deps);
510
531
  case "download": return dispatchDownload(parsed, deps);
@@ -682,29 +703,82 @@ async function dispatchAuth(parsed, deps) {
682
703
  default: throw createArgumentError("E_ARG_UNSUPPORTED", "auth subcommand must be: status|import-cookie|logout", { subcommand });
683
704
  }
684
705
  }
706
+ async function dispatchCheck(parsed, deps) {
707
+ if (parsed.positional.length > 0) throw createArgumentError("E_ARG_UNSUPPORTED", "check command does not accept subcommands", { positional: parsed.positional });
708
+ const resolved = await resolveClientConfig({
709
+ cwd: process.cwd(),
710
+ env: process.env,
711
+ getFlag: (key) => parsed.flags.get(key)
712
+ });
713
+ if (!(typeof resolved.cookie === "string" && resolved.cookie.trim().length > 0)) throw new CliAppError({
714
+ code: "E_AUTH_REQUIRED",
715
+ message: "Missing BYR credentials. Set BYR_COOKIE or run `byr auth import-cookie`."
716
+ });
717
+ const client = await deps.getClient();
718
+ let authenticated = true;
719
+ if (typeof client.verifyAuth === "function") authenticated = (await client.verifyAuth()).authenticated;
720
+ if (!authenticated) throw new CliAppError({
721
+ code: "E_AUTH_INVALID",
722
+ message: "BYR credentials are present but verification failed."
723
+ });
724
+ const result = {
725
+ hasCredentials: true,
726
+ authenticated: true,
727
+ source: resolved.cookieSource ?? "none"
728
+ };
729
+ return {
730
+ data: result,
731
+ humanOutput: ["Authentication: valid", `Source: ${result.source}`].join("\n")
732
+ };
733
+ }
734
+ async function dispatchWhoami(parsed, deps) {
735
+ if (parsed.positional.length > 0) throw createArgumentError("E_ARG_UNSUPPORTED", "whoami command does not accept subcommands", { positional: parsed.positional });
736
+ const client = await deps.getClient();
737
+ if (typeof client.getUserInfo !== "function") throw createArgumentError("E_ARG_UNSUPPORTED", "Current client does not support user info", {});
738
+ const info = await client.getUserInfo();
739
+ return {
740
+ data: {
741
+ id: info.id,
742
+ name: info.name,
743
+ levelName: info.levelName,
744
+ levelId: info.levelId,
745
+ ratio: info.ratio
746
+ },
747
+ humanOutput: `${info.name} (${info.id}) | Level: ${info.levelName}${info.levelId ? ` (#${info.levelId})` : ""} | Ratio: ${info.ratio}`
748
+ };
749
+ }
685
750
  function parseArgs(argv) {
686
- const command = argv[0];
751
+ let command;
687
752
  const flags = /* @__PURE__ */ new Map();
688
753
  const positional = [];
689
- for (let index = 1; index < argv.length; index += 1) {
754
+ for (let index = 0; index < argv.length; index += 1) {
690
755
  const token = argv[index];
691
- if (!token.startsWith("--")) {
692
- positional.push(token);
756
+ const shortAlias = SHORT_FLAG_ALIASES[token];
757
+ if (shortAlias !== void 0) {
758
+ flags.set(shortAlias, true);
693
759
  continue;
694
760
  }
695
- const stripped = token.slice(2);
696
- const eqIndex = stripped.indexOf("=");
697
- if (eqIndex >= 0) {
698
- appendFlagValue(flags, stripped.slice(0, eqIndex), stripped.slice(eqIndex + 1));
761
+ if (token.startsWith("--")) {
762
+ const stripped = token.slice(2);
763
+ const eqIndex = stripped.indexOf("=");
764
+ if (eqIndex >= 0) {
765
+ appendFlagValue(flags, stripped.slice(0, eqIndex), stripped.slice(eqIndex + 1));
766
+ continue;
767
+ }
768
+ const next = argv[index + 1];
769
+ if (next !== void 0 && !next.startsWith("-")) {
770
+ appendFlagValue(flags, stripped, next);
771
+ index += 1;
772
+ continue;
773
+ }
774
+ flags.set(stripped, true);
699
775
  continue;
700
776
  }
701
- const next = argv[index + 1];
702
- if (next !== void 0 && !next.startsWith("--")) {
703
- appendFlagValue(flags, stripped, next);
704
- index += 1;
777
+ if (command === void 0) {
778
+ command = token;
705
779
  continue;
706
780
  }
707
- flags.set(stripped, true);
781
+ positional.push(token);
708
782
  }
709
783
  return {
710
784
  command,
@@ -712,6 +786,9 @@ function parseArgs(argv) {
712
786
  positional
713
787
  };
714
788
  }
789
+ function hasFlag(flags, key) {
790
+ return flags.has(key);
791
+ }
715
792
  function appendFlagValue(flags, key, value) {
716
793
  const previous = flags.get(key);
717
794
  if (previous === void 0) {
@@ -798,11 +875,107 @@ function parseSingleFacetFlag(flags, key, facet) {
798
875
  if (parsed.values.length !== 1) throw createArgumentError("E_ARG_INVALID", `--${key} expects exactly one value`, { values });
799
876
  return parsed.values[0];
800
877
  }
801
- function renderHelp() {
878
+ function resolveHelpTarget(parsed) {
879
+ if (parsed.command === "help") return {
880
+ command: parsed.positional[0],
881
+ subcommand: parsed.positional[1]
882
+ };
883
+ if (hasFlag(parsed.flags, "help")) return {
884
+ command: parsed.command,
885
+ subcommand: parsed.positional[0]
886
+ };
887
+ return {};
888
+ }
889
+ function renderHelp(command, subcommand) {
890
+ if (command === "search") return [
891
+ "byr search",
892
+ "",
893
+ "Usage:",
894
+ " byr search --query <text> [--limit <n>] [--category <alias|id>] [--incldead <alias|id>] [--spstate <alias|id>] [--bookmarked <alias|id>] [--page <n>] [--json]",
895
+ " byr search --imdb <tt-id> [--limit <n>] [--json]"
896
+ ].join("\n");
897
+ if (command === "get") return [
898
+ "byr get",
899
+ "",
900
+ "Usage:",
901
+ " byr get --id <torrent-id> [--json]"
902
+ ].join("\n");
903
+ if (command === "download") return [
904
+ "byr download",
905
+ "",
906
+ "Usage:",
907
+ " byr download --id <torrent-id> --output <path> [--dry-run] [--json]"
908
+ ].join("\n");
909
+ if (command === "user") return [
910
+ "byr user",
911
+ "",
912
+ "Usage:",
913
+ " byr user info [--json]"
914
+ ].join("\n");
915
+ if (command === "meta") return [
916
+ "byr meta",
917
+ "",
918
+ "Usage:",
919
+ " byr meta categories [--json]",
920
+ " byr meta levels [--json]"
921
+ ].join("\n");
922
+ if (command === "auth") {
923
+ if (subcommand === "status") return [
924
+ "byr auth status",
925
+ "",
926
+ "Usage:",
927
+ " byr auth status [--verify] [--json]"
928
+ ].join("\n");
929
+ if (subcommand === "import-cookie") return [
930
+ "byr auth import-cookie",
931
+ "",
932
+ "Usage:",
933
+ " byr auth import-cookie --cookie \"uid=...; pass=...\" [--json]",
934
+ " byr auth import-cookie --from-browser <chrome|safari> [--profile <name>] [--json]"
935
+ ].join("\n");
936
+ if (subcommand === "logout") return [
937
+ "byr auth logout",
938
+ "",
939
+ "Usage:",
940
+ " byr auth logout [--json]"
941
+ ].join("\n");
942
+ return [
943
+ "byr auth",
944
+ "",
945
+ "Usage:",
946
+ " byr auth status [--verify] [--json]",
947
+ " byr auth import-cookie --cookie \"uid=...; pass=...\" [--json]",
948
+ " byr auth import-cookie --from-browser <chrome|safari> [--profile <name>] [--json]",
949
+ " byr auth logout [--json]"
950
+ ].join("\n");
951
+ }
952
+ if (command === "check") return [
953
+ "byr check",
954
+ "",
955
+ "Usage:",
956
+ " byr check [--json]"
957
+ ].join("\n");
958
+ if (command === "whoami") return [
959
+ "byr whoami",
960
+ "",
961
+ "Usage:",
962
+ " byr whoami [--json]"
963
+ ].join("\n");
964
+ if (command === "version") return [
965
+ "byr version",
966
+ "",
967
+ "Usage:",
968
+ " byr version [--json]"
969
+ ].join("\n");
802
970
  return [
803
971
  "byr CLI",
804
972
  "",
805
973
  "Usage:",
974
+ " byr [--help|-h] [--version|-V]",
975
+ " byr help [command]",
976
+ " byr version [--json]",
977
+ " byr check [--json]",
978
+ " byr whoami [--json]",
806
979
  " byr search --query <text> [--limit <n>] [--category <alias|id>] [--incldead <alias|id>] [--spstate <alias|id>] [--bookmarked <alias|id>] [--page <n>] [--json]",
807
980
  " byr search --imdb <tt-id> [--limit <n>] [--json]",
808
981
  " byr get --id <torrent-id> [--json]",
@@ -819,11 +992,27 @@ function renderHelp() {
819
992
  " CLI flags > ENV > ./.byrrc.json > ~/.config/byr-cli/config.json > ~/.config/byr-cli/auth.json",
820
993
  "",
821
994
  "Flags:",
995
+ " -h, --help Show help",
996
+ " -V, --version Show CLI version",
822
997
  " --json Output CliEnvelope JSON",
823
998
  " --dry-run Validate and show write plan without writing files",
824
- " --verbose Include verbose mode in metadata"
999
+ " -v, --verbose Include verbose mode in metadata"
825
1000
  ].join("\n");
826
1001
  }
1002
+ function loadVersionInfo() {
1003
+ try {
1004
+ const pkg = createRequire(import.meta.url)("../package.json");
1005
+ return {
1006
+ name: typeof pkg.name === "string" ? pkg.name : "byr-pt-cli",
1007
+ version: typeof pkg.version === "string" ? pkg.version : "0.0.0"
1008
+ };
1009
+ } catch {
1010
+ return {
1011
+ name: "byr-pt-cli",
1012
+ version: "0.0.0"
1013
+ };
1014
+ }
1015
+ }
827
1016
  function createArgumentError(code, message, details) {
828
1017
  return new CliAppError({
829
1018
  code,
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import "./client-DT9oDCaE.mjs";
2
- import { t as runCli } from "./cli-B6Pr98en.mjs";
1
+ import "./client-CXGKExl2.mjs";
2
+ import { t as runCli } from "./cli-orER4PKy.mjs";
3
3
 
4
4
  export { runCli };
@@ -1,4 +1,4 @@
1
- import { CliAppError } from "@onemoreproduct/cli-core";
1
+ import { CliAppError } from "clawkit-cli-core";
2
2
 
3
3
  //#region src/domain/byr-metadata.ts
4
4
  function aliases(value, ...extra) {
@@ -1,4 +1,4 @@
1
- import { CliAppError } from "@onemoreproduct/cli-core";
1
+ import { CliAppError } from "clawkit-cli-core";
2
2
 
3
3
  //#region src/commands/download.ts
4
4
  async function runDownloadCommand(client, input) {
@@ -1,4 +1,4 @@
1
- import { CliAppError } from "@onemoreproduct/cli-core";
1
+ import { CliAppError } from "clawkit-cli-core";
2
2
 
3
3
  //#region src/commands/get.ts
4
4
  async function runGetCommand(client, input) {
@@ -1,4 +1,4 @@
1
- import { CliAppError } from "@onemoreproduct/cli-core";
1
+ import { CliAppError } from "clawkit-cli-core";
2
2
 
3
3
  //#region src/commands/search.ts
4
4
  async function runSearchCommand(client, input) {
@@ -1,3 +1,3 @@
1
- import { n as createByrClientFromEnv, r as createMockByrClient, t as createByrClient } from "../client-DT9oDCaE.mjs";
1
+ import { n as createByrClientFromEnv, r as createMockByrClient, t as createByrClient } from "../client-CXGKExl2.mjs";
2
2
 
3
3
  export { createByrClient, createByrClientFromEnv, createMockByrClient };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import "./client-DT9oDCaE.mjs";
3
- import { t as runCli } from "./cli-B6Pr98en.mjs";
2
+ import "./client-CXGKExl2.mjs";
3
+ import { t as runCli } from "./cli-orER4PKy.mjs";
4
4
 
5
5
  //#region src/index.ts
6
6
  const exitCode = await runCli(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "byr-pt-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "description": "BYR CLI with OpenClaw-friendly JSON contract",
6
6
  "license": "MIT",