politty 0.4.13 → 0.4.15

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 (68) hide show
  1. package/README.md +7 -1
  2. package/dist/{arg-registry-CeIRoLaB.d.cts → arg-registry-CB5gGtzp.d.cts} +55 -14
  3. package/dist/arg-registry-CB5gGtzp.d.cts.map +1 -0
  4. package/dist/{arg-registry-6E4C5MTC.d.ts → arg-registry-Dw0f11Zc.d.ts} +55 -14
  5. package/dist/arg-registry-Dw0f11Zc.d.ts.map +1 -0
  6. package/dist/augment.d.cts +3 -2
  7. package/dist/augment.d.cts.map +1 -1
  8. package/dist/augment.d.ts +3 -2
  9. package/dist/augment.d.ts.map +1 -1
  10. package/dist/completion/index.cjs +1 -1
  11. package/dist/completion/index.d.cts +1 -1
  12. package/dist/completion/index.d.ts +1 -1
  13. package/dist/completion/index.js +1 -1
  14. package/dist/{completion-D3LUac1o.cjs → completion-B5fgnUGm.cjs} +103 -38
  15. package/dist/completion-B5fgnUGm.cjs.map +1 -0
  16. package/dist/{completion-DzaT2YCN.js → completion-Ca5ESJlG.js} +91 -26
  17. package/dist/completion-Ca5ESJlG.js.map +1 -0
  18. package/dist/docs/index.cjs +59 -50
  19. package/dist/docs/index.cjs.map +1 -1
  20. package/dist/docs/index.d.cts +5 -1
  21. package/dist/docs/index.d.cts.map +1 -1
  22. package/dist/docs/index.d.ts +5 -1
  23. package/dist/docs/index.d.ts.map +1 -1
  24. package/dist/docs/index.js +52 -43
  25. package/dist/docs/index.js.map +1 -1
  26. package/dist/{index-C3UtsvgY.d.ts → index-C1gGgUeB.d.cts} +9 -4
  27. package/dist/index-C1gGgUeB.d.cts.map +1 -0
  28. package/dist/{index-BW02tH1-.d.cts → index-Dg9Fpz0R.d.ts} +9 -4
  29. package/dist/index-Dg9Fpz0R.d.ts.map +1 -0
  30. package/dist/index.cjs +10 -10
  31. package/dist/index.d.cts +6 -3
  32. package/dist/index.d.cts.map +1 -1
  33. package/dist/index.d.ts +6 -3
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +3 -3
  36. package/dist/{subcommand-router-BnHpqyRk.cjs → log-collector-Cd2_mv87.cjs} +1 -59
  37. package/dist/log-collector-Cd2_mv87.cjs.map +1 -0
  38. package/dist/{subcommand-router-BhYVuS83.js → log-collector-Cu6MCtAx.js} +2 -43
  39. package/dist/log-collector-Cu6MCtAx.js.map +1 -0
  40. package/dist/prompt/clack/index.cjs +1 -1
  41. package/dist/prompt/clack/index.d.cts +1 -1
  42. package/dist/prompt/clack/index.d.ts +1 -1
  43. package/dist/prompt/index.d.cts +1 -1
  44. package/dist/prompt/index.d.ts +1 -1
  45. package/dist/prompt/inquirer/index.cjs +1 -1
  46. package/dist/prompt/inquirer/index.d.cts +1 -1
  47. package/dist/prompt/inquirer/index.d.ts +1 -1
  48. package/dist/{runner-DA48D-3K.cjs → runner-CriXJlm4.cjs} +176 -74
  49. package/dist/runner-CriXJlm4.cjs.map +1 -0
  50. package/dist/{runner-CnG-Ncz0.js → runner-DKAQBNNh.js} +149 -47
  51. package/dist/runner-DKAQBNNh.js.map +1 -0
  52. package/dist/{lazy-qPy4cMnv.cjs → subcommand-router-CqZX3orq.cjs} +140 -3
  53. package/dist/subcommand-router-CqZX3orq.cjs.map +1 -0
  54. package/dist/{lazy-xrzxwnru.js → subcommand-router-ENeCymvX.js} +104 -3
  55. package/dist/subcommand-router-ENeCymvX.js.map +1 -0
  56. package/package.json +12 -12
  57. package/dist/arg-registry-6E4C5MTC.d.ts.map +0 -1
  58. package/dist/arg-registry-CeIRoLaB.d.cts.map +0 -1
  59. package/dist/completion-D3LUac1o.cjs.map +0 -1
  60. package/dist/completion-DzaT2YCN.js.map +0 -1
  61. package/dist/index-BW02tH1-.d.cts.map +0 -1
  62. package/dist/index-C3UtsvgY.d.ts.map +0 -1
  63. package/dist/lazy-qPy4cMnv.cjs.map +0 -1
  64. package/dist/lazy-xrzxwnru.js.map +0 -1
  65. package/dist/runner-CnG-Ncz0.js.map +0 -1
  66. package/dist/runner-DA48D-3K.cjs.map +0 -1
  67. package/dist/subcommand-router-BhYVuS83.js.map +0 -1
  68. package/dist/subcommand-router-BnHpqyRk.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { i as extractFields, l as arg, r as resolveSubCommandMeta } from "./lazy-xrzxwnru.js";
1
+ import { c as resolveSubCommandMeta, h as arg, i as resolveSubCommandAlias, l as extractFields, p as toCamelCase } from "./subcommand-router-ENeCymvX.js";
2
2
  import { z } from "zod";
3
3
  import { execSync } from "node:child_process";
4
4
 
@@ -7,6 +7,7 @@ function defineCommand(config) {
7
7
  return {
8
8
  name: config.name,
9
9
  description: config.description,
10
+ aliases: config.aliases,
10
11
  args: config.args,
11
12
  subCommands: config.subCommands,
12
13
  setup: config.setup,
@@ -111,6 +112,25 @@ function getVisibleSubs(subs) {
111
112
  return subs.filter((s) => !s.name.startsWith("__"));
112
113
  }
113
114
  /**
115
+ * Get all completable subcommand names including aliases.
116
+ * Returns an array of { name, description } for all visible subcommands
117
+ * and their aliases.
118
+ */
119
+ function getSubNamesWithAliases(subs) {
120
+ const result = [];
121
+ for (const sub of getVisibleSubs(subs)) {
122
+ result.push({
123
+ name: sub.name,
124
+ description: sub.description
125
+ });
126
+ if (sub.aliases) for (const alias of sub.aliases) result.push({
127
+ name: alias,
128
+ description: sub.description
129
+ });
130
+ }
131
+ return result;
132
+ }
133
+ /**
114
134
  * Convert a resolved field to a completable option
115
135
  */
116
136
  function fieldToOption(field) {
@@ -173,6 +193,7 @@ function extractSubcommand(name, command) {
173
193
  return {
174
194
  name,
175
195
  description: command.description,
196
+ aliases: command.aliases,
176
197
  subcommands,
177
198
  options: extractOptions$1(command),
178
199
  positionals: extractCompletablePositionals(command)
@@ -191,16 +212,20 @@ function optTakesValueEntries(sub, parentPath) {
191
212
  const lines = [];
192
213
  for (const opt of sub.options) if (opt.takesValue) {
193
214
  const patterns = [`${parentPath}:--${opt.cliName}`];
194
- if (opt.alias) patterns.push(`${parentPath}:-${opt.alias}`);
215
+ if (opt.alias) for (const a of opt.alias) patterns.push(`${parentPath}:${a.length === 1 ? `-${a}` : `--${a}`}`);
195
216
  lines.push(` ${patterns.join("|")}) return 0 ;;`);
196
217
  }
197
- for (const child of getVisibleSubs(sub.subcommands)) lines.push(...optTakesValueEntries(child, joinPrefix(parentPath, child.name, ":")));
218
+ for (const child of getVisibleSubs(sub.subcommands)) {
219
+ lines.push(...optTakesValueEntries(child, joinPrefix(parentPath, child.name, ":")));
220
+ if (child.aliases) for (const alias of child.aliases) lines.push(...optTakesValueEntries(child, joinPrefix(parentPath, alias, ":")));
221
+ }
198
222
  return lines;
199
223
  }
200
224
  /**
201
225
  * Recursively collect all subcommand route entries.
202
226
  * Returns entries used by all shell generators for both dispatch routing
203
227
  * and subcommand lookup (is_subcmd) tables.
228
+ * Aliases are mapped to the same handler as the canonical name.
204
229
  */
205
230
  function collectRouteEntries(sub, parentPath = "", parentFunc = "") {
206
231
  const entries = [];
@@ -213,6 +238,15 @@ function collectRouteEntries(sub, parentPath = "", parentFunc = "") {
213
238
  funcSuffix,
214
239
  lookupPattern: `${parentPath}:${child.name}`
215
240
  });
241
+ if (child.aliases) for (const alias of child.aliases) {
242
+ const aliasPathStr = joinPrefix(parentPath, alias, ":");
243
+ entries.push(...collectRouteEntries(child, aliasPathStr, funcSuffix));
244
+ entries.push({
245
+ pathStr: aliasPathStr,
246
+ funcSuffix,
247
+ lookupPattern: `${parentPath}:${alias}`
248
+ });
249
+ }
216
250
  }
217
251
  return entries;
218
252
  }
@@ -331,7 +365,7 @@ function optionValueCases$2(options, inline) {
331
365
  const valLines = bashValueLines(opt.valueCompletion, inline);
332
366
  if (valLines.length === 0) continue;
333
367
  const patterns = [`--${opt.cliName}`];
334
- if (opt.alias) patterns.push(`-${opt.alias}`);
368
+ if (opt.alias) for (const a of opt.alias) patterns.push(a.length === 1 ? `-${a}` : `--${a}`);
335
369
  const patternStr = patterns.join("|");
336
370
  lines.push(` ${patternStr})`);
337
371
  for (const vl of valLines) lines.push(` ${vl}`);
@@ -381,7 +415,7 @@ function availableOptionLines$2(options, fn) {
381
415
  for (const opt of options) if (opt.valueType === "array") lines.push(` _avail+=(--${opt.cliName})`);
382
416
  else {
383
417
  const patterns = [`"--${opt.cliName}"`];
384
- if (opt.alias) patterns.push(`"-${opt.alias}"`);
418
+ if (opt.alias) for (const a of opt.alias) patterns.push(a.length === 1 ? `"-${a}"` : `"--${a}"`);
385
419
  lines.push(` __${fn}_not_used ${patterns.join(" ")} && _avail+=(--${opt.cliName})`);
386
420
  }
387
421
  lines.push(` __${fn}_not_used "--help" && _avail+=(--help)`);
@@ -416,7 +450,7 @@ function generateSubHandler$2(sub, fn, path) {
416
450
  lines.push(` return`);
417
451
  lines.push(` fi`);
418
452
  if (visibleSubs.length > 0) {
419
- const subNames = visibleSubs.map((s) => s.name).join(" ");
453
+ const subNames = getSubNamesWithAliases(sub.subcommands).map((s) => s.name).join(" ");
420
454
  lines.push(` COMPREPLY=($(compgen -W "${subNames}" -- "$_cur"))`);
421
455
  lines.push(` compopt +o default 2>/dev/null`);
422
456
  } else if (sub.positionals.length > 0) lines.push(...positionalBlock$2(sub.positionals));
@@ -478,7 +512,7 @@ function generateBashCompletion(command, options) {
478
512
  lines.push(` compopt +o default 2>/dev/null`);
479
513
  if (visibleSubs.length > 0) {
480
514
  lines.push(` else`);
481
- const subNames = visibleSubs.map((s) => s.name).join(" ");
515
+ const subNames = getSubNamesWithAliases(root.subcommands).map((s) => s.name).join(" ");
482
516
  lines.push(` COMPREPLY=($(compgen -W "${subNames}" -- "$_cur"))`);
483
517
  lines.push(` compopt +o default 2>/dev/null`);
484
518
  } else if (root.positionals.length > 0) {
@@ -667,8 +701,16 @@ function generateSubcommandCandidates(context) {
667
701
  const candidates = [];
668
702
  let directive = CompletionDirective.FilterPrefix;
669
703
  for (const name of context.subcommands) {
704
+ let description;
670
705
  const sub = context.currentCommand.subCommands?.[name];
671
- const description = sub ? resolveSubCommandMeta(sub)?.description : void 0;
706
+ if (sub) description = resolveSubCommandMeta(sub)?.description;
707
+ else {
708
+ const canonical = resolveSubCommandAlias(context.currentCommand, name);
709
+ if (canonical) {
710
+ const resolved = context.currentCommand.subCommands?.[canonical];
711
+ if (resolved) description = resolveSubCommandMeta(resolved)?.description;
712
+ }
713
+ }
672
714
  candidates.push({
673
715
  value: name,
674
716
  description,
@@ -692,7 +734,9 @@ function generateOptionNameCandidates(context) {
692
734
  const directive = CompletionDirective.FilterPrefix;
693
735
  const availableOptions = context.options.filter((opt) => {
694
736
  if (opt.valueType === "array") return true;
695
- return !context.usedOptions.has(opt.cliName) && !context.usedOptions.has(opt.alias || "");
737
+ if (context.usedOptions.has(opt.cliName)) return false;
738
+ if (opt.alias && opt.alias.some((a) => context.usedOptions.has(a))) return false;
739
+ return true;
696
740
  });
697
741
  for (const opt of availableOptions) candidates.push({
698
742
  value: `--${opt.cliName}`,
@@ -787,20 +831,29 @@ function extractPositionalsForContext(command) {
787
831
  }));
788
832
  }
789
833
  /**
790
- * Get subcommand names from a command
834
+ * Get subcommand names from a command (including aliases)
791
835
  */
792
836
  function getSubcommandNames(command) {
793
837
  if (!command.subCommands) return [];
794
- return Object.keys(command.subCommands).filter((name) => !name.startsWith("__"));
838
+ const names = [];
839
+ for (const [name, subCmd] of Object.entries(command.subCommands)) {
840
+ if (name.startsWith("__")) continue;
841
+ names.push(name);
842
+ const meta = resolveSubCommandMeta(subCmd);
843
+ if (meta?.aliases) names.push(...meta.aliases);
844
+ }
845
+ return names;
795
846
  }
796
847
  /**
797
- * Resolve subcommand by name
848
+ * Resolve subcommand by name (including alias lookup)
798
849
  */
799
850
  function resolveSubcommand(command, name) {
800
851
  if (!command.subCommands) return null;
801
852
  const sub = command.subCommands[name];
802
- if (!sub) return null;
803
- return resolveSubCommandMeta(sub);
853
+ if (sub) return resolveSubCommandMeta(sub);
854
+ const canonical = resolveSubCommandAlias(command, name);
855
+ if (canonical) return resolveSubCommandMeta(command.subCommands[canonical]);
856
+ return null;
804
857
  }
805
858
  /**
806
859
  * Check if a word is an option (starts with - or --)
@@ -830,7 +883,15 @@ function hasInlineValue(word) {
830
883
  * Find option by name or alias
831
884
  */
832
885
  function findOption(options, nameOrAlias) {
833
- return options.find((opt) => opt.cliName === nameOrAlias || opt.alias === nameOrAlias);
886
+ return options.find((opt) => {
887
+ if (opt.cliName === nameOrAlias) return true;
888
+ if (opt.alias?.includes(nameOrAlias)) return true;
889
+ if (nameOrAlias.length > 1) {
890
+ if (opt.cliName.includes("-") && toCamelCase(opt.cliName) === nameOrAlias) return true;
891
+ if (opt.alias?.some((a) => a.includes("-") && toCamelCase(a) === nameOrAlias)) return true;
892
+ }
893
+ return false;
894
+ });
834
895
  }
835
896
  /**
836
897
  * Parse completion context from command line arguments
@@ -859,7 +920,7 @@ function parseCompletionContext(argv, rootCommand) {
859
920
  const opt = findOption(options, optName);
860
921
  if (opt) {
861
922
  usedOptions.add(opt.cliName);
862
- if (opt.alias) usedOptions.add(opt.alias);
923
+ if (opt.alias) for (const a of opt.alias) usedOptions.add(a);
863
924
  if (opt.takesValue && !hasInlineValue(word)) i++;
864
925
  }
865
926
  i++;
@@ -1149,7 +1210,7 @@ function optionValueCases$1(options) {
1149
1210
  const valLines = fishValueLines(opt.valueCompletion);
1150
1211
  if (valLines.length === 0) continue;
1151
1212
  const conditions = [`test "$_prev" = "--${opt.cliName}"`];
1152
- if (opt.alias) conditions.push(`test "$_prev" = "-${opt.alias}"`);
1213
+ if (opt.alias) for (const a of opt.alias) conditions.push(`test "$_prev" = "${a.length === 1 ? `-${a}` : `--${a}`}"`);
1153
1214
  const cond = conditions.join("; or ");
1154
1215
  lines.push(` if ${cond}`);
1155
1216
  for (const vl of valLines) lines.push(` ${vl}`);
@@ -1181,7 +1242,7 @@ function availableOptionLines$1(options, fn) {
1181
1242
  if (opt.valueType === "array") lines.push(` echo "--${opt.cliName}\t${desc}"`);
1182
1243
  else {
1183
1244
  const checks = [`"--${opt.cliName}"`];
1184
- if (opt.alias) checks.push(`"-${opt.alias}"`);
1245
+ if (opt.alias) for (const a of opt.alias) checks.push(a.length === 1 ? `"-${a}"` : `"--${a}"`);
1185
1246
  lines.push(` __${fn}_not_used ${checks.join(" ")}; and echo "--${opt.cliName}\t${desc}"`);
1186
1247
  }
1187
1248
  }
@@ -1217,7 +1278,7 @@ function generateSubHandler$1(sub, fn, path) {
1217
1278
  lines.push(...availableOptionLines$1(sub.options, fn));
1218
1279
  lines.push(` return`);
1219
1280
  lines.push(` end`);
1220
- if (visibleSubs.length > 0) for (const s of visibleSubs) {
1281
+ if (visibleSubs.length > 0) for (const s of getSubNamesWithAliases(sub.subcommands)) {
1221
1282
  const desc = escapeDesc$1(s.description ?? "");
1222
1283
  lines.push(` echo "${s.name}\t${desc}"`);
1223
1284
  }
@@ -1231,13 +1292,17 @@ function optTakesValueCases(sub, parentPath) {
1231
1292
  const lines = [];
1232
1293
  for (const opt of sub.options) if (opt.takesValue) {
1233
1294
  const patterns = [`"${parentPath}:--${opt.cliName}"`];
1234
- if (opt.alias) patterns.push(`"${parentPath}:-${opt.alias}"`);
1295
+ if (opt.alias) for (const a of opt.alias) patterns.push(`"${parentPath}:${a.length === 1 ? `-${a}` : `--${a}`}"`);
1235
1296
  lines.push(` case ${patterns.join(" ")}`);
1236
1297
  lines.push(` return 0`);
1237
1298
  }
1238
1299
  for (const child of getVisibleSubs(sub.subcommands)) {
1239
1300
  const childPath = parentPath ? `${parentPath}:${child.name}` : child.name;
1240
1301
  lines.push(...optTakesValueCases(child, childPath));
1302
+ if (child.aliases) for (const alias of child.aliases) {
1303
+ const aliasPath = parentPath ? `${parentPath}:${alias}` : alias;
1304
+ lines.push(...optTakesValueCases(child, aliasPath));
1305
+ }
1241
1306
  }
1242
1307
  return lines;
1243
1308
  }
@@ -1294,7 +1359,7 @@ function generateFishCompletion(command, options) {
1294
1359
  lines.push(...availableOptionLines$1(root.options, fn));
1295
1360
  if (visibleSubs.length > 0) {
1296
1361
  lines.push(` else`);
1297
- for (const s of visibleSubs) {
1362
+ for (const s of getSubNamesWithAliases(root.subcommands)) {
1298
1363
  const desc = escapeDesc$1(s.description ?? "");
1299
1364
  lines.push(` echo "${s.name}\t${desc}"`);
1300
1365
  }
@@ -1406,7 +1471,7 @@ function optionValueCases(options, fn) {
1406
1471
  const valLines = zshValueLines(opt.valueCompletion, fn);
1407
1472
  if (valLines.length === 0) continue;
1408
1473
  const patterns = [`--${opt.cliName}`];
1409
- if (opt.alias) patterns.push(`-${opt.alias}`);
1474
+ if (opt.alias) for (const a of opt.alias) patterns.push(a.length === 1 ? `-${a}` : `--${a}`);
1410
1475
  lines.push(` ${patterns.join("|")})`);
1411
1476
  for (const vl of valLines) lines.push(` ${vl}`);
1412
1477
  lines.push(` return 0 ;;`);
@@ -1447,7 +1512,7 @@ function availableOptionLines(options, fn) {
1447
1512
  if (opt.valueType === "array") lines.push(` _opts+=("--${opt.cliName}${desc}")`);
1448
1513
  else {
1449
1514
  const patterns = [`"--${opt.cliName}"`];
1450
- if (opt.alias) patterns.push(`"-${opt.alias}"`);
1515
+ if (opt.alias) for (const a of opt.alias) patterns.push(a.length === 1 ? `"-${a}"` : `"--${a}"`);
1451
1516
  lines.push(` __${fn}_not_used ${patterns.join(" ")} && _opts+=("--${opt.cliName}${desc}")`);
1452
1517
  }
1453
1518
  }
@@ -1482,7 +1547,7 @@ function generateSubHandler(sub, fn, path) {
1482
1547
  lines.push(` return 0`);
1483
1548
  lines.push(` fi`);
1484
1549
  if (visibleSubs.length > 0) {
1485
- const subItems = visibleSubs.map((s) => {
1550
+ const subItems = getSubNamesWithAliases(sub.subcommands).map((s) => {
1486
1551
  const desc = s.description ? `:${escapeDesc(s.description)}` : "";
1487
1552
  return `"${s.name}${desc}"`;
1488
1553
  }).join(" ");
@@ -1557,7 +1622,7 @@ function generateZshCompletion(command, options) {
1557
1622
  lines.push(` __${fn}_cdescribe 'options' _opts`);
1558
1623
  if (visibleSubs.length > 0) {
1559
1624
  lines.push(` else`);
1560
- const subItems = visibleSubs.map((s) => {
1625
+ const subItems = getSubNamesWithAliases(root.subcommands).map((s) => {
1561
1626
  const desc = s.description ? `:${escapeDesc(s.description)}` : "";
1562
1627
  return `"${s.name}${desc}"`;
1563
1628
  }).join(" ");
@@ -1776,4 +1841,4 @@ function withCompletionCommand(command, options) {
1776
1841
 
1777
1842
  //#endregion
1778
1843
  export { withCompletionCommand as a, formatForShell as c, generateCandidates as d, extractCompletionData as f, defineCommand as g, createDefineCommand as h, getSupportedShells as i, parseCompletionContext as l, resolveValueCompletion as m, detectShell as n, createDynamicCompleteCommand as o, extractPositionals as p, generateCompletion as r, hasCompleteCommand as s, createCompletionCommand as t, CompletionDirective as u };
1779
- //# sourceMappingURL=completion-DzaT2YCN.js.map
1844
+ //# sourceMappingURL=completion-Ca5ESJlG.js.map