@gunshi/plugin-completion 0.27.6 → 0.28.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.
Files changed (2) hide show
  1. package/lib/index.js +20 -3
  2. package/package.json +5 -5
package/lib/index.js CHANGED
@@ -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
  }
@@ -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, 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
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.6",
4
+ "version": "0.28.2",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -53,10 +53,10 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@bomb.sh/tab": "^0.0.11",
56
- "@gunshi/plugin": "0.27.6"
56
+ "@gunshi/plugin": "0.28.2"
57
57
  },
58
58
  "peerDependencies": {
59
- "@gunshi/plugin-i18n": "0.27.6"
59
+ "@gunshi/plugin-i18n": "0.28.2"
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.6",
72
- "@gunshi/shared": "0.27.6"
71
+ "@gunshi/plugin-i18n": "0.28.2",
72
+ "@gunshi/shared": "0.28.2"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "tsdown",