@gunshi/plugin-completion 0.27.5 → 0.28.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 (2) hide show
  1. package/lib/index.js +25 -8
  2. package/package.json +6 -6
package/lib/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  import { RootCommand } from "@bomb.sh/tab";
7
7
  import { createCommandContext, plugin } from "@gunshi/plugin";
8
8
 
9
- //#region ../../node_modules/.pnpm/args-tokens@0.23.0/node_modules/args-tokens/lib/utils-1LQrGCWG.js
9
+ //#region ../../node_modules/.pnpm/args-tokens@0.23.1/node_modules/args-tokens/lib/utils-CxvkckUD.js
10
10
  /**
11
11
  * Entry point of utils.
12
12
  *
@@ -56,7 +56,8 @@ async function resolveLazyCommand(cmd, name, needRunResolving = false) {
56
56
  args: cmd.args,
57
57
  examples: cmd.examples,
58
58
  internal: cmd.internal,
59
- entry: cmd.entry
59
+ entry: cmd.entry,
60
+ subCommands: cmd.subCommands
60
61
  };
61
62
  if ("resource" in cmd && cmd.resource) baseCommand.resource = cmd.resource;
62
63
  command = Object.assign(create(), baseCommand);
@@ -72,6 +73,7 @@ async function resolveLazyCommand(cmd, name, needRunResolving = false) {
72
73
  command.examples = loaded.examples;
73
74
  command.internal = loaded.internal;
74
75
  command.entry = loaded.entry;
76
+ command.subCommands = loaded.subCommands || cmd.subCommands;
75
77
  if ("resource" in loaded && loaded.resource) command.resource = loaded.resource;
76
78
  } else throw new TypeError(`Cannot resolve command: ${cmd.name || name}`);
77
79
  }
@@ -420,11 +422,11 @@ function completion(options = {}) {
420
422
  }
421
423
  });
422
424
  }
423
- async function registerCompletion({ name, cmd, config, i18nPluginId: i18nPluginId$1, i18n, t, isBombshellRoot = false }) {
425
+ async function registerCompletion({ name, cmd, config, i18nPluginId, i18n, t, isBombshellRoot = false }) {
424
426
  const resolvedCmd = await resolveLazyCommand(cmd);
425
427
  const extensions = Object.create(null);
426
- if (i18n) extensions[i18nPluginId$1] = {
427
- key: Symbol(i18nPluginId$1),
428
+ if (i18n) extensions[i18nPluginId] = {
429
+ key: Symbol(i18nPluginId),
428
430
  factory: () => i18n
429
431
  };
430
432
  const ctx = await createCommandContext({
@@ -448,17 +450,32 @@ function resolveCompletionHandler(name, optionOrArgKey, config, i18n) {
448
450
  for (const item of handler({ locale: i18n?.locale })) complete(item.value, item.description || "");
449
451
  };
450
452
  }
451
- async function handleSubCommands(t, subCommands, i18nPluginId$1, config = {}, i18n) {
453
+ async function handleSubCommands(t, subCommands, i18nPluginId, config = {}, i18n, parentPath = "") {
452
454
  for (const [name, cmd] of subCommands) {
453
455
  if (cmd.internal || cmd.entry || name === "complete") continue;
456
+ const fullName = parentPath ? `${parentPath} ${name}` : name;
454
457
  await registerCompletion({
455
- name,
458
+ name: fullName,
456
459
  cmd,
457
460
  config,
458
- i18nPluginId: i18nPluginId$1,
461
+ i18nPluginId,
459
462
  i18n,
460
463
  t
461
464
  });
465
+ const nestedSubCommands = getNestedSubCommands(cmd);
466
+ if (nestedSubCommands && nestedSubCommands.size > 0) await handleSubCommands(t, nestedSubCommands, i18nPluginId, config, i18n, fullName);
467
+ }
468
+ }
469
+ function getNestedSubCommands(cmd) {
470
+ const subCommands = typeof cmd === "function" ? cmd.subCommands : cmd.subCommands;
471
+ if (!subCommands) return;
472
+ if (subCommands instanceof Map) return subCommands.size > 0 ? subCommands : void 0;
473
+ if (typeof subCommands === "object") {
474
+ const entries = Object.entries(subCommands);
475
+ if (entries.length === 0) return;
476
+ const map = /* @__PURE__ */ new Map();
477
+ for (const [name, c] of entries) map.set(name, c);
478
+ return map;
462
479
  }
463
480
  }
464
481
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/plugin-completion",
3
3
  "description": "completion plugin for gunshi",
4
- "version": "0.27.5",
4
+ "version": "0.28.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -52,11 +52,11 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
- "@bomb.sh/tab": "^0.0.10",
56
- "@gunshi/plugin": "0.27.5"
55
+ "@bomb.sh/tab": "^0.0.11",
56
+ "@gunshi/plugin": "0.28.0"
57
57
  },
58
58
  "peerDependencies": {
59
- "@gunshi/plugin-i18n": "0.27.5"
59
+ "@gunshi/plugin-i18n": "0.28.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/node": "^25.0.3",
@@ -68,8 +68,8 @@
68
68
  "tsdown": "0.15.12",
69
69
  "typedoc": "^0.28.15",
70
70
  "typedoc-plugin-markdown": "^4.9.0",
71
- "@gunshi/plugin-i18n": "0.27.5",
72
- "@gunshi/shared": "0.27.5"
71
+ "@gunshi/plugin-i18n": "0.28.0",
72
+ "@gunshi/shared": "0.28.0"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "tsdown",