politty 0.4.13 → 0.4.14

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 (65) hide show
  1. package/dist/{arg-registry-6E4C5MTC.d.ts → arg-registry-CkPDokIu.d.ts} +53 -14
  2. package/dist/arg-registry-CkPDokIu.d.ts.map +1 -0
  3. package/dist/{arg-registry-CeIRoLaB.d.cts → arg-registry-r5wYN6qd.d.cts} +53 -14
  4. package/dist/arg-registry-r5wYN6qd.d.cts.map +1 -0
  5. package/dist/augment.d.cts +3 -2
  6. package/dist/augment.d.cts.map +1 -1
  7. package/dist/augment.d.ts +3 -2
  8. package/dist/augment.d.ts.map +1 -1
  9. package/dist/completion/index.cjs +1 -1
  10. package/dist/completion/index.d.cts +1 -1
  11. package/dist/completion/index.d.ts +1 -1
  12. package/dist/completion/index.js +1 -1
  13. package/dist/{completion-D3LUac1o.cjs → completion-CAekGYS4.cjs} +24 -14
  14. package/dist/completion-CAekGYS4.cjs.map +1 -0
  15. package/dist/{completion-DzaT2YCN.js → completion-yHz8Pdr7.js} +23 -13
  16. package/dist/completion-yHz8Pdr7.js.map +1 -0
  17. package/dist/docs/index.cjs +21 -8
  18. package/dist/docs/index.cjs.map +1 -1
  19. package/dist/docs/index.d.cts +1 -1
  20. package/dist/docs/index.d.cts.map +1 -1
  21. package/dist/docs/index.d.ts +1 -1
  22. package/dist/docs/index.d.ts.map +1 -1
  23. package/dist/docs/index.js +21 -8
  24. package/dist/docs/index.js.map +1 -1
  25. package/dist/{index-BW02tH1-.d.cts → index-BLySW_2k.d.ts} +7 -4
  26. package/dist/index-BLySW_2k.d.ts.map +1 -0
  27. package/dist/{index-C3UtsvgY.d.ts → index-DPswv0Vt.d.cts} +7 -4
  28. package/dist/index-DPswv0Vt.d.cts.map +1 -0
  29. package/dist/index.cjs +3 -3
  30. package/dist/index.d.cts +2 -2
  31. package/dist/index.d.cts.map +1 -1
  32. package/dist/index.d.ts +2 -2
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +3 -3
  35. package/dist/{lazy-qPy4cMnv.cjs → lazy-AGV9Pkt5.cjs} +34 -3
  36. package/dist/lazy-AGV9Pkt5.cjs.map +1 -0
  37. package/dist/{lazy-xrzxwnru.js → lazy-DiMJSDMB.js} +28 -3
  38. package/dist/lazy-DiMJSDMB.js.map +1 -0
  39. package/dist/prompt/clack/index.cjs +1 -1
  40. package/dist/prompt/clack/index.d.cts +1 -1
  41. package/dist/prompt/clack/index.d.ts +1 -1
  42. package/dist/prompt/index.d.cts +1 -1
  43. package/dist/prompt/index.d.ts +1 -1
  44. package/dist/prompt/inquirer/index.cjs +1 -1
  45. package/dist/prompt/inquirer/index.d.cts +1 -1
  46. package/dist/prompt/inquirer/index.d.ts +1 -1
  47. package/dist/{runner-DA48D-3K.cjs → runner-CY5fOsSh.cjs} +76 -36
  48. package/dist/runner-CY5fOsSh.cjs.map +1 -0
  49. package/dist/{runner-CnG-Ncz0.js → runner-DSZw1AsW.js} +76 -36
  50. package/dist/runner-DSZw1AsW.js.map +1 -0
  51. package/dist/{subcommand-router-BhYVuS83.js → subcommand-router--EUt6ftA.js} +2 -2
  52. package/dist/{subcommand-router-BhYVuS83.js.map → subcommand-router--EUt6ftA.js.map} +1 -1
  53. package/dist/{subcommand-router-BnHpqyRk.cjs → subcommand-router-C9ONv6Nq.cjs} +2 -2
  54. package/dist/{subcommand-router-BnHpqyRk.cjs.map → subcommand-router-C9ONv6Nq.cjs.map} +1 -1
  55. package/package.json +12 -12
  56. package/dist/arg-registry-6E4C5MTC.d.ts.map +0 -1
  57. package/dist/arg-registry-CeIRoLaB.d.cts.map +0 -1
  58. package/dist/completion-D3LUac1o.cjs.map +0 -1
  59. package/dist/completion-DzaT2YCN.js.map +0 -1
  60. package/dist/index-BW02tH1-.d.cts.map +0 -1
  61. package/dist/index-C3UtsvgY.d.ts.map +0 -1
  62. package/dist/lazy-qPy4cMnv.cjs.map +0 -1
  63. package/dist/lazy-xrzxwnru.js.map +0 -1
  64. package/dist/runner-CnG-Ncz0.js.map +0 -1
  65. package/dist/runner-DA48D-3K.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
- const require_subcommand_router = require('./subcommand-router-BnHpqyRk.cjs');
2
- const require_lazy = require('./lazy-qPy4cMnv.cjs');
1
+ const require_subcommand_router = require('./subcommand-router-C9ONv6Nq.cjs');
2
+ const require_lazy = require('./lazy-AGV9Pkt5.cjs');
3
3
  let node_util = require("node:util");
4
4
  let string_width = require("string-width");
5
5
  string_width = require_subcommand_router.__toESM(string_width);
@@ -614,8 +614,8 @@ function renderOptions(command, descriptions = {}, context) {
614
614
  version: descriptions.version ?? defaultBuiltinDescriptions.version
615
615
  };
616
616
  const extracted = require_lazy.getExtractedFields(command);
617
- const hasUserDefinedh = extracted?.fields.some((f) => f.alias === "h" && f.overrideBuiltinAlias === true) ?? false;
618
- const hasUserDefinedH = extracted?.fields.some((f) => f.alias === "H" && f.overrideBuiltinAlias === true) ?? false;
617
+ const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && require_lazy.getAllAliases(f).includes("h")) ?? false;
618
+ const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && require_lazy.getAllAliases(f).includes("H")) ?? false;
619
619
  if (hasUserDefinedh) lines.push(formatOption(styles.option("--help"), desc.help));
620
620
  else lines.push(formatOption(`${styles.option("-h")}, ${styles.option("--help")}`, desc.help));
621
621
  if (hasUserDefinedH) lines.push(formatOption(styles.option("--help-all"), desc.helpAll));
@@ -738,13 +738,25 @@ function renderUnionOptions(extracted, _command, lines) {
738
738
  */
739
739
  function formatFlags(opt) {
740
740
  const parts = [];
741
- if (opt.alias) parts.push(styles.option(`-${opt.alias}`));
741
+ if (opt.alias) {
742
+ for (const alias of opt.alias) if (alias.length === 1) parts.push(styles.option(`-${alias}`));
743
+ }
742
744
  let longFlag = styles.option(`--${opt.cliName}`);
743
745
  if (opt.type !== "boolean") {
744
746
  const placeholder = opt.placeholder ?? opt.cliName.toUpperCase();
745
747
  longFlag += ` ${styles.placeholder(`<${placeholder}>`)}`;
746
748
  }
747
749
  parts.push(longFlag);
750
+ if (opt.alias) {
751
+ for (const alias of opt.alias) if (alias.length > 1) {
752
+ let longAlias = styles.option(`--${alias}`);
753
+ if (opt.type !== "boolean") {
754
+ const placeholder = opt.placeholder ?? opt.cliName.toUpperCase();
755
+ longAlias += ` ${styles.placeholder(`<${placeholder}>`)}`;
756
+ }
757
+ parts.push(longAlias);
758
+ }
759
+ }
748
760
  return parts.join(", ");
749
761
  }
750
762
  /**
@@ -1000,22 +1012,36 @@ function checkDuplicateAliases(extracted, commandPath) {
1000
1012
  const errors = [];
1001
1013
  const seenAliases = /* @__PURE__ */ new Map();
1002
1014
  const fieldNames = new Set(extracted.fields.map((f) => f.name));
1003
- for (const field of extracted.fields) {
1004
- if (!field.alias) continue;
1005
- if (fieldNames.has(field.alias)) errors.push({
1006
- commandPath,
1007
- type: "duplicate_alias",
1008
- message: `Alias "${field.alias}" for field "${field.name}" conflicts with existing field name "${field.alias}".`,
1009
- field: field.name
1010
- });
1011
- const existingField = seenAliases.get(field.alias);
1012
- if (existingField) errors.push({
1015
+ const cliNames = new Set(extracted.fields.map((f) => f.cliName));
1016
+ const registerAlias = (alias, fieldName, isDerived) => {
1017
+ if (fieldNames.has(alias) || cliNames.has(alias)) errors.push({
1013
1018
  commandPath,
1014
1019
  type: "duplicate_alias",
1015
- message: `Duplicate alias "${field.alias}" detected. Both "${existingField}" and "${field.name}" use the same alias.`,
1016
- field: field.name
1020
+ message: `Alias "${alias}" for field "${fieldName}" conflicts with existing field name or CLI name "${alias}".`,
1021
+ field: fieldName
1017
1022
  });
1018
- seenAliases.set(field.alias, field.name);
1023
+ const existingField = seenAliases.get(alias);
1024
+ if (existingField && existingField !== fieldName) {
1025
+ const qualifier = isDerived ? " (derived camelCase variant)" : "";
1026
+ errors.push({
1027
+ commandPath,
1028
+ type: "duplicate_alias",
1029
+ message: `Duplicate alias "${alias}"${qualifier} detected. Both "${existingField}" and "${fieldName}" use the same alias.`,
1030
+ field: fieldName
1031
+ });
1032
+ }
1033
+ seenAliases.set(alias, fieldName);
1034
+ };
1035
+ for (const field of extracted.fields) {
1036
+ const allAliases = require_lazy.getAllAliases(field);
1037
+ if (allAliases.length === 0) continue;
1038
+ for (const alias of allAliases) {
1039
+ registerAlias(alias, field.name, false);
1040
+ if (alias.length > 1 && alias.includes("-")) {
1041
+ const camelVariant = require_lazy.toCamelCase(alias);
1042
+ if (camelVariant !== alias && !fieldNames.has(camelVariant)) registerAlias(camelVariant, field.name, true);
1043
+ }
1044
+ }
1019
1045
  }
1020
1046
  return errors;
1021
1047
  }
@@ -1056,12 +1082,15 @@ function checkPositionalConfig(extracted, commandPath) {
1056
1082
  */
1057
1083
  function checkReservedAliases(extracted, commandPath) {
1058
1084
  const errors = [];
1059
- for (const field of extracted.fields) if ((field.alias === "h" || field.alias === "H") && field.overrideBuiltinAlias !== true) errors.push({
1060
- commandPath,
1061
- type: "reserved_alias",
1062
- message: `Alias "${field.alias}" is reserved for --${field.alias === "h" ? "help" : "help-all"}.`,
1063
- field: field.name
1064
- });
1085
+ for (const field of extracted.fields) {
1086
+ if (field.overrideBuiltinAlias === true) continue;
1087
+ for (const alias of require_lazy.getAllAliases(field)) if (alias === "h" || alias === "H") errors.push({
1088
+ commandPath,
1089
+ type: "reserved_alias",
1090
+ message: `Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}.`,
1091
+ field: field.name
1092
+ });
1093
+ }
1065
1094
  return errors;
1066
1095
  }
1067
1096
  /**
@@ -1125,8 +1154,9 @@ function validateReservedAliases(extracted, _hasSubCommands) {
1125
1154
  const errors = checkReservedAliases(extracted, []);
1126
1155
  if (errors.length > 0) {
1127
1156
  const field = errors[0].field ?? "unknown";
1128
- const alias = extracted.fields.find((f) => f.name === field)?.alias ?? "h";
1129
- throw new ReservedAliasError(`Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}. To override this, set { alias: "${alias}", overrideBuiltinAlias: true } for "${field}".`);
1157
+ const found = extracted.fields.find((f) => f.name === field);
1158
+ const alias = (found ? require_lazy.getAllAliases(found) : []).find((a) => a === "h" || a === "H") ?? "h";
1159
+ throw new ReservedAliasError(`Alias "${alias}" is reserved for --${alias === "h" ? "help" : "help-all"}. To override this, set { overrideBuiltinAlias: true } for "${field}" and keep the alias where it is currently defined (in alias or hiddenAlias).`);
1130
1160
  }
1131
1161
  }
1132
1162
  /**
@@ -1371,7 +1401,13 @@ function buildParserOptions(extracted) {
1371
1401
  for (const field of extracted.fields) definedNames.add(field.name);
1372
1402
  for (const field of extracted.fields) {
1373
1403
  if (field.cliName !== field.name) aliasMap.set(field.cliName, field.name);
1374
- if (field.alias) aliasMap.set(field.alias, field.name);
1404
+ for (const alias of require_lazy.getAllAliases(field)) {
1405
+ aliasMap.set(alias, field.name);
1406
+ if (alias.length > 1 && alias.includes("-")) {
1407
+ const camelAlias = require_lazy.toCamelCase(alias);
1408
+ if (camelAlias !== alias && !definedNames.has(camelAlias) && !aliasMap.has(camelAlias)) aliasMap.set(camelAlias, field.name);
1409
+ }
1410
+ }
1375
1411
  const camelVariant = require_lazy.toCamelCase(field.name);
1376
1412
  if (camelVariant !== field.name && !definedNames.has(camelVariant) && !aliasMap.has(camelVariant)) aliasMap.set(camelVariant, field.name);
1377
1413
  if (field.type === "boolean") booleanFlags.add(field.name);
@@ -1413,12 +1449,14 @@ function mergeWithPositionals(parsed, extracted) {
1413
1449
  */
1414
1450
  function buildGlobalFlagLookup(globalExtracted) {
1415
1451
  const { aliasMap = /* @__PURE__ */ new Map(), booleanFlags = /* @__PURE__ */ new Set() } = buildParserOptions(globalExtracted);
1452
+ const shortAliases = /* @__PURE__ */ new Set();
1453
+ for (const field of globalExtracted.fields) for (const alias of require_lazy.getAllAliases(field)) if (alias.length === 1) shortAliases.add(alias);
1416
1454
  return {
1417
1455
  aliasMap,
1418
1456
  booleanFlags,
1419
1457
  flagNames: new Set(globalExtracted.fields.map((f) => f.name)),
1420
1458
  cliNames: new Set(globalExtracted.fields.map((f) => f.cliName)),
1421
- aliases: new Set(globalExtracted.fields.filter((f) => f.alias).map((f) => f.alias))
1459
+ aliases: shortAliases
1422
1460
  };
1423
1461
  }
1424
1462
  /**
@@ -1604,8 +1642,8 @@ function parseArgs(argv, command, options = {}) {
1604
1642
  if (options.globalExtracted) validateCrossSchemaCollisions(options.globalExtracted, extracted);
1605
1643
  }
1606
1644
  }
1607
- const hasUserDefinedH = extracted?.fields.some((f) => f.alias === "H" && f.overrideBuiltinAlias === true) ?? false;
1608
- const hasUserDefinedh = extracted?.fields.some((f) => f.alias === "h" && f.overrideBuiltinAlias === true) ?? false;
1645
+ const hasUserDefinedH = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && require_lazy.getAllAliases(f).includes("H")) ?? false;
1646
+ const hasUserDefinedh = extracted?.fields.some((f) => f.overrideBuiltinAlias === true && require_lazy.getAllAliases(f).includes("h")) ?? false;
1609
1647
  const helpAllRequested = argv.includes("--help-all") || !hasUserDefinedH && argv.includes("-H");
1610
1648
  const helpRequested = !helpAllRequested && (argv.includes("--help") || !hasUserDefinedh && argv.includes("-h"));
1611
1649
  const versionRequested = argv.includes("--version");
@@ -1652,11 +1690,12 @@ function parseArgs(argv, command, options = {}) {
1652
1690
  }
1653
1691
  const knownFlags = new Set(extracted.fields.map((f) => f.name));
1654
1692
  const knownCliNames = new Set(extracted.fields.map((f) => f.cliName));
1655
- const knownAliases = new Set(extracted.fields.filter((f) => f.alias).map((f) => f.alias));
1693
+ const knownAliases = /* @__PURE__ */ new Set();
1694
+ for (const f of extracted.fields) for (const alias of require_lazy.getAllAliases(f)) knownAliases.add(alias);
1656
1695
  if (options.globalExtracted) for (const f of options.globalExtracted.fields) {
1657
1696
  knownFlags.add(f.name);
1658
1697
  knownCliNames.add(f.cliName);
1659
- if (f.alias) knownAliases.add(f.alias);
1698
+ for (const alias of require_lazy.getAllAliases(f)) knownAliases.add(alias);
1660
1699
  }
1661
1700
  const unknownFlags = [];
1662
1701
  for (const key of Object.keys(parsed.options)) if (!knownFlags.has(key) && !knownCliNames.has(key) && !knownAliases.has(key)) unknownFlags.push(key);
@@ -1694,8 +1733,9 @@ function parseGlobalArgs(tokens, globalExtracted) {
1694
1733
  */
1695
1734
  function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1696
1735
  const lookup = buildGlobalFlagLookup(globalExtracted);
1736
+ const localFieldNames = new Set(localExtracted?.fields.map((f) => f.name) ?? []);
1697
1737
  const localCliNames = new Set(localExtracted?.fields.map((f) => f.cliName) ?? []);
1698
- const localAliases = new Set(localExtracted?.fields.filter((f) => f.alias).map((f) => f.alias) ?? []);
1738
+ const localAliasMapKeys = localExtracted ? new Set(buildParserOptions(localExtracted).aliasMap?.keys() ?? []) : /* @__PURE__ */ new Set();
1699
1739
  const globalTokens = [];
1700
1740
  const commandTokens = [];
1701
1741
  for (let i = 0; i < argv.length; i++) {
@@ -1707,7 +1747,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1707
1747
  if (arg.startsWith("--")) {
1708
1748
  const { resolvedName, withoutDashes, isNegated, isGlobal } = resolveGlobalLongOption(arg, lookup);
1709
1749
  const flagName = isNegated ? withoutDashes.slice(3) : withoutDashes;
1710
- const isLocalCollision = localCliNames.has(withoutDashes) || localCliNames.has(flagName);
1750
+ const isLocalCollision = localFieldNames.has(withoutDashes) || localFieldNames.has(flagName) || localCliNames.has(withoutDashes) || localCliNames.has(flagName) || localAliasMapKeys.has(withoutDashes) || localAliasMapKeys.has(flagName);
1711
1751
  if (isGlobal && !isLocalCollision) {
1712
1752
  i += collectGlobalFlag(argv, i, resolvedName, isNegated, lookup.booleanFlags, globalTokens) - 1;
1713
1753
  continue;
@@ -1716,7 +1756,7 @@ function separateGlobalArgs(argv, globalExtracted, localExtracted) {
1716
1756
  const withoutDash = arg.includes("=") ? arg.slice(1, arg.indexOf("=")) : arg.slice(1);
1717
1757
  if (withoutDash.length === 1) {
1718
1758
  const resolvedName = lookup.aliasMap.get(withoutDash) ?? withoutDash;
1719
- if ((lookup.aliases.has(withoutDash) || lookup.flagNames.has(resolvedName)) && !localAliases.has(withoutDash)) {
1759
+ if ((lookup.aliases.has(withoutDash) || lookup.flagNames.has(resolvedName)) && !localAliasMapKeys.has(withoutDash)) {
1720
1760
  i += collectGlobalFlag(argv, i, resolvedName, false, lookup.booleanFlags, globalTokens) - 1;
1721
1761
  continue;
1722
1762
  }
@@ -2380,4 +2420,4 @@ Object.defineProperty(exports, 'validateReservedAliases', {
2380
2420
  return validateReservedAliases;
2381
2421
  }
2382
2422
  });
2383
- //# sourceMappingURL=runner-DA48D-3K.cjs.map
2423
+ //# sourceMappingURL=runner-CY5fOsSh.cjs.map