xserver-cli 1.2.1 → 1.2.2

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/dist/index.js CHANGED
@@ -567,7 +567,7 @@ function enc(s) {
567
567
  }
568
568
 
569
569
  // ../core/dist/commands/auth/login.js
570
- import { password } from "@inquirer/prompts";
570
+ import { password, select } from "@inquirer/prompts";
571
571
 
572
572
  // ../core/dist/lib/config.js
573
573
  import fs from "fs";
@@ -772,10 +772,76 @@ function pickDefined(obj) {
772
772
  return result;
773
773
  }
774
774
 
775
+ // ../core/dist/lib/resolve-servername-from-me.js
776
+ function resolveServernameFromMe(meData) {
777
+ const services = meData.services;
778
+ const server = services?.server;
779
+ if (!server) {
780
+ return { status: "manual", reason: "no_server" };
781
+ }
782
+ const targetMode = server.target_mode;
783
+ const targets = normalizeTargets(server.targets);
784
+ if (targetMode === "all") {
785
+ return { status: "manual", reason: "all" };
786
+ }
787
+ if (targetMode === "selected") {
788
+ if (targets.length === 1) {
789
+ return { status: "auto", servername: targets[0] };
790
+ }
791
+ if (targets.length >= 2) {
792
+ return { status: "choose", targets };
793
+ }
794
+ return { status: "manual", reason: "empty_targets" };
795
+ }
796
+ return { status: "manual", reason: "empty_targets" };
797
+ }
798
+ function manualServernameMessage(reason) {
799
+ switch (reason) {
800
+ case "no_server":
801
+ return "\u3053\u306EAPI\u30AD\u30FC\u3067\u306F\u30B5\u30FC\u30D0\u30FCAPI\u3092\u5229\u7528\u3067\u304D\u307E\u305B\u3093\uFF08\u30B5\u30FC\u30D0\u30FC\u533A\u5206\u304C\u542B\u307E\u308C\u3066\u3044\u307E\u305B\u3093\uFF09\u3002";
802
+ case "all":
803
+ return "\u3053\u306EAPI\u30AD\u30FC\u306F\u5BFE\u8C61\u30B5\u30FC\u30D0\u30FC\u304C\u56FA\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\uFF08\u300C\u3059\u3079\u3066\u306E\u30B5\u30FC\u30D0\u30FC\u300D\u7B49\uFF09\u3002";
804
+ case "empty_targets":
805
+ return "\u3053\u306EAPI\u30AD\u30FC\u306E\u30B5\u30FC\u30D0\u30FC\u5BFE\u8C61\u3092\u7279\u5B9A\u3067\u304D\u307E\u305B\u3093\u3002";
806
+ }
807
+ }
808
+ function normalizeTargets(targets) {
809
+ if (!Array.isArray(targets)) {
810
+ return [];
811
+ }
812
+ return targets.filter((t) => typeof t === "string" && t !== "");
813
+ }
814
+
775
815
  // ../core/dist/commands/auth/login.js
776
816
  function maskApiKey(apiKey) {
777
817
  return `${apiKey.substring(0, 8)}...`;
778
818
  }
819
+ async function resolveLoginServername(meData, brand) {
820
+ const outcome = resolveServernameFromMe(meData);
821
+ if (outcome.status === "auto") {
822
+ console.error(` \u30B5\u30FC\u30D0\u30FC\u540D\u3092\u81EA\u52D5\u691C\u51FA\u3057\u307E\u3057\u305F: ${outcome.servername}`);
823
+ return outcome.servername;
824
+ }
825
+ if (outcome.status === "choose") {
826
+ if (process.stdin.isTTY) {
827
+ const chosen = await select({
828
+ message: "\u5BFE\u8C61\u30B5\u30FC\u30D0\u30FC\u3092\u9078\u629E:",
829
+ choices: outcome.targets.map((target) => ({ value: target, name: target }))
830
+ });
831
+ console.error(` \u30B5\u30FC\u30D0\u30FC\u540D: ${chosen}`);
832
+ return chosen;
833
+ }
834
+ console.error(" \u5BFE\u8C61\u30B5\u30FC\u30D0\u30FC\u304C\u8907\u6570\u3042\u308B\u305F\u3081\u81EA\u52D5\u691C\u51FA\u3067\u304D\u307E\u305B\u3093\u3002--servername \u3067\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
835
+ console.error(` \u5019\u88DC: ${outcome.targets.join(", ")}`);
836
+ console.error(" \u30B5\u30FC\u30D0\u30FC\u7CFB\u30B3\u30DE\u30F3\u30C9\u3067\u306F --servername \u3067\u5BFE\u8C61\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
837
+ console.error(` \u4F8B: ${brand.commandName} server --servername <\u30B5\u30FC\u30D0\u30FCID> info`);
838
+ return void 0;
839
+ }
840
+ console.error(` ${manualServernameMessage(outcome.reason)}`);
841
+ console.error(" \u30B5\u30FC\u30D0\u30FC\u7CFB\u30B3\u30DE\u30F3\u30C9\u3067\u306F --servername \u3067\u5BFE\u8C61\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
842
+ console.error(` \u4F8B: ${brand.commandName} server --servername <\u30B5\u30FC\u30D0\u30FCID> info`);
843
+ return void 0;
844
+ }
779
845
  function registerAuthCommands(program, brand) {
780
846
  const auth = program.command("auth").description("\u8A8D\u8A3C\u8A2D\u5B9A");
781
847
  auth.command("login").description("API\u30AD\u30FC\u3092\u8A2D\u5B9A\uFF08\u5BFE\u8C61\u30B5\u30FC\u30D0\u30FC\u304C1\u53F0\u306E\u30AD\u30FC\u306F\u30B5\u30FC\u30D0\u30FC\u540D\u3092\u81EA\u52D5\u691C\u51FA\uFF09").option("--api-key <key>", "API\u30AD\u30FC").option("--servername <name>", "\u30B5\u30FC\u30D0\u30FC\u540D\uFF08\u81EA\u52D5\u691C\u51FA\u3092\u4E0A\u66F8\u304D\uFF09").action(async (opts, cmd) => {
@@ -802,13 +868,8 @@ function registerAuthCommands(program, brand) {
802
868
  throw err;
803
869
  }
804
870
  console.error("\u2713 \u8A8D\u8A3C\u306B\u6210\u529F\u3057\u307E\u3057\u305F");
805
- if (!servername && meData.servername) {
806
- servername = meData.servername;
807
- console.error(` \u30B5\u30FC\u30D0\u30FC\u540D\u3092\u81EA\u52D5\u691C\u51FA\u3057\u307E\u3057\u305F: ${servername}`);
808
- } else if (!servername) {
809
- console.error(" \u3053\u306EAPI\u30AD\u30FC\u306F\u5BFE\u8C61\u30B5\u30FC\u30D0\u30FC\u304C\u56FA\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\uFF08\u300C\u3059\u3079\u3066\u306E\u30B5\u30FC\u30D0\u30FC\u300D\u7B49\uFF09\u3002");
810
- console.error(" \u30B5\u30FC\u30D0\u30FC\u7CFB\u30B3\u30DE\u30F3\u30C9\u3067\u306F --servername \u3067\u5BFE\u8C61\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
811
- console.error(` \u4F8B: ${brand.commandName} server --servername <\u30B5\u30FC\u30D0\u30FCID> info`);
871
+ if (!servername) {
872
+ servername = await resolveLoginServername(meData, brand);
812
873
  }
813
874
  const config = loadConfig(brand);
814
875
  config.profiles[profileName] = {
@@ -2188,7 +2249,7 @@ function run(brand, version = "0.0.0") {
2188
2249
  // package.json
2189
2250
  var package_default = {
2190
2251
  name: "xserver-cli",
2191
- version: "1.2.1",
2252
+ version: "1.2.2",
2192
2253
  description: "Official CLI for XServer API \u2014 manage your XServer hosting from the terminal",
2193
2254
  type: "module",
2194
2255
  bin: {